org.apache.tapestry.enhance
Interface EnhancementOperation

All Known Implementing Classes:
EnhancementOperationImpl

public interface EnhancementOperation

A process object representing enhancements to a component class. The operation is passed to EnhancementWorkerobjects that perform enhancements.

Since:
4.0
Author:
Howard M. Lewis Ship

Method Summary
 void addField(java.lang.String name, java.lang.Class type)
          Adds a field to the enhanced class; the field will be private and use the provided name and type.
 java.lang.String addInjectedField(java.lang.String fieldName, java.lang.Class fieldType, java.lang.Object value)
          Adds a field containing an initial value, which is injected into the class via its fabricated constructor.
 void addMethod(int modifier, org.apache.hivemind.service.MethodSignature sig, java.lang.String methodBody, org.apache.hivemind.Location location)
          Adds a method to the enhanced class.
 void claimProperty(java.lang.String propertyName)
          Claims a property.
 void claimReadonlyProperty(java.lang.String propertyName)
          Claims a property as read-only.
 java.lang.Class convertTypeName(java.lang.String type)
          Converts a type name (an object class name, a primtive name, or an array) into the corresponding Class object.
 void extendMethodImplementation(java.lang.Class interfaceClass, org.apache.hivemind.service.MethodSignature methodSignature, java.lang.String code)
          Allows for a kind of distributed construction of a particular method, within a particular interface.
 java.util.List findUnclaimedAbstractProperties()
          Returns a list of the names of existing properties that are not claimed and which have abstract accessor methods.
 java.lang.String getAccessorMethodName(java.lang.String propertyName)
          Returns the name of the accessor method for the given property (if it exists in the component base class), or fabricates a new name if it does not.
 java.lang.Class getBaseClass()
          Returns the base component class, as defined in the specification (or defaulted).
 java.lang.String getClassReference(java.lang.Class clazz)
          Returns a reference to a particular class.
 java.lang.Class getPropertyType(java.lang.String name)
          Returns the type of an existing property of the base component class.
 boolean implementsInterface(java.lang.Class interfaceClass)
          Returns true if the class implements the specified interface.
 void validateProperty(java.lang.String name, java.lang.Class expectedType)
          Confirms that the named property either doesn't exist (in the component base class), or that the type of the property exactly matches the indicated type.
 

Method Detail

claimProperty

public void claimProperty(java.lang.String propertyName)
Claims a property. Most enhancements are concerned with adding properties. Some enhancement workers exist to fill in defaults, and they need to know what properties have already been spoken for by eariler enhancement works.

Throws:
org.apache.hivemind.ApplicationRuntimeException - if the property was previously claimed

claimReadonlyProperty

public void claimReadonlyProperty(java.lang.String propertyName)
Claims a property as read-only. This will check to see if the property has an abstract setter method.

Throws:
org.apache.hivemind.ApplicationRuntimeException - if the property was previously claimed, or if the property includes an accessor method.

findUnclaimedAbstractProperties

public java.util.List findUnclaimedAbstractProperties()
Returns a list of the names of existing properties that are not claimed and which have abstract accessor methods.


addField

public void addField(java.lang.String name,
                     java.lang.Class type)
Adds a field to the enhanced class; the field will be private and use the provided name and type.


addInjectedField

public java.lang.String addInjectedField(java.lang.String fieldName,
                                         java.lang.Class fieldType,
                                         java.lang.Object value)
Adds a field containing an initial value, which is injected into the class via its fabricated constructor. This method may be called multiple times with the same value and will return the same variable name (an identity map is kept internally).

Parameters:
fieldName - The default name for the field, used if a new field (and contructor argument) is being created. Only used if a field for the value doesn't exist.
fieldType - The type of the field to be created.
value - the value to be referenced, which may not be null
Returns:
the name of the field containing the value. This may or may not match fieldName. The provided fieldName may be modified to prevent naming conflicts.

convertTypeName

public java.lang.Class convertTypeName(java.lang.String type)
Converts a type name (an object class name, a primtive name, or an array) into the corresponding Class object.


validateProperty

public void validateProperty(java.lang.String name,
                             java.lang.Class expectedType)
Confirms that the named property either doesn't exist (in the component base class), or that the type of the property exactly matches the indicated type.


getAccessorMethodName

public java.lang.String getAccessorMethodName(java.lang.String propertyName)
Returns the name of the accessor method for the given property (if it exists in the component base class), or fabricates a new name if it does not.


addMethod

public void addMethod(int modifier,
                      org.apache.hivemind.service.MethodSignature sig,
                      java.lang.String methodBody,
                      org.apache.hivemind.Location location)
Adds a method to the enhanced class.

Parameters:
modifier - as defined by Modifier, typically Modifier.PUBLIC
sig - the method signature (defining name, return type, etc.)
methodBody - a Javassist code snippet for the method body
location - a location used to identify "why" the method was added; the location may later be used to describe conflicts. May not be null.

getBaseClass

public java.lang.Class getBaseClass()
Returns the base component class, as defined in the specification (or defaulted). An enhaced subclass of the component class will usually be created.


getClassReference

public java.lang.String getClassReference(java.lang.Class clazz)
Returns a reference to a particular class. This will, effectively, by the name of a private field.


getPropertyType

public java.lang.Class getPropertyType(java.lang.String name)
Returns the type of an existing property of the base component class. If the property does not exist, then returns null.


extendMethodImplementation

public void extendMethodImplementation(java.lang.Class interfaceClass,
                                       org.apache.hivemind.service.MethodSignature methodSignature,
                                       java.lang.String code)
Allows for a kind of distributed construction of a particular method, within a particular interface. Code can be appended to the method's implementation throughout the course of the enhancement operation. When the enhanced class is finialized, the method is added with whatever contents are in its body. If the base class implements the method, then the method body will include an initial call to that implementation.

At this time, this works best for void methods (since there isn't an easy way to ensure code would be inserted before a final return statement).

Parameters:
interfaceClass - the interface containing the method. If the base class does not implement the interface, then the enhanced class will have the interface added.
methodSignature - the signature of the method to be added.
code - the Javassist markup to be added to the body of the method.

implementsInterface

public boolean implementsInterface(java.lang.Class interfaceClass)
Returns true if the class implements the specified interface. Checks the base class (as identified in the specification), but also accounts for any additional interfaces that may be added by extendMethodImplementation(Class, MethodSignature, String).