org.apache.tapestry.enhance
Class EnhancementOperationImpl

java.lang.Object
  extended by org.apache.tapestry.enhance.EnhancementOperationImpl
All Implemented Interfaces:
EnhancementOperation

public class EnhancementOperationImpl
extends Object
implements EnhancementOperation

Implementation of EnhancementOperationthat knows how to collect class changes from enhancements. The method getConstructor() finalizes the enhancement into a ComponentConstructor.

Since:
4.0
Author:
Howard M. Lewis Ship

Constructor Summary
EnhancementOperationImpl(org.apache.hivemind.ClassResolver classResolver, IComponentSpecification specification, Class baseClass, org.apache.hivemind.service.ClassFactory classFactory, Log log)
           
 
Method Summary
 void addField(String name, Class type)
          Adds a field to the enhanced class; the field will be private and use the provided name and type.
 String addInjectedField(String fieldName, Class fieldType, 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, String methodBody, org.apache.hivemind.Location location)
          Adds a method to the enhanced class.
 boolean canClaimAsReadOnlyProperty(String propertyName)
          Checks to see if the specified property can be claimed as read only.
 void claimProperty(String propertyName)
          Claims a property.
 void claimReadonlyProperty(String propertyName)
          Claims a property as read-only.
 Class convertTypeName(String type)
          Converts a type name (an object class name, a primtive name, or an array) into the corresponding Class object.
 void extendMethodImplementation(Class interfaceClass, org.apache.hivemind.service.MethodSignature methodSignature, String code)
          Allows for a kind of distributed construction of a particular method, within a particular interface.
 List findUnclaimedAbstractProperties()
          Returns a list of the names of existing properties that are not claimed and which have abstract accessor methods.
 String getAccessorMethodName(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.
 Class getBaseClass()
          Returns the base component class, as defined in the specification (or defaulted).
 String getClassReference(Class clazz)
          Returns a reference to a particular class.
 ComponentConstructor getConstructor()
          Returns an object that can be used to construct instances of the enhanced component subclass.
 Class getPropertyType(String name)
          Returns the type of an existing property of the base component class.
 IComponentSpecification getSpecification()
          The specification defined for the component class being enhanced.
 boolean implementsInterface(Class interfaceClass)
          Returns true if the class implements the specified interface.
 String toString()
           
 void validateProperty(String name, 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EnhancementOperationImpl

public EnhancementOperationImpl(org.apache.hivemind.ClassResolver classResolver,
                                IComponentSpecification specification,
                                Class baseClass,
                                org.apache.hivemind.service.ClassFactory classFactory,
                                Log log)
Method Detail

toString

public String toString()
Overrides:
toString in class Object

claimProperty

public void claimProperty(String propertyName)
Description copied from interface: EnhancementOperation
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.

Specified by:
claimProperty in interface EnhancementOperation

canClaimAsReadOnlyProperty

public boolean canClaimAsReadOnlyProperty(String propertyName)
Checks to see if the specified property can be claimed as read only.

Specified by:
canClaimAsReadOnlyProperty in interface EnhancementOperation
Parameters:
propertyName - The property to check.
Returns:
True, if no setter method has been created for the specified property and the property hasn't been claimed by someone else.

claimReadonlyProperty

public void claimReadonlyProperty(String propertyName)
Description copied from interface: EnhancementOperation
Claims a property as read-only. This will check to see if the property has an abstract setter method.

Specified by:
claimReadonlyProperty in interface EnhancementOperation

addField

public void addField(String name,
                     Class type)
Description copied from interface: EnhancementOperation
Adds a field to the enhanced class; the field will be private and use the provided name and type.

Specified by:
addField in interface EnhancementOperation

addInjectedField

public String addInjectedField(String fieldName,
                               Class fieldType,
                               Object value)
Description copied from interface: EnhancementOperation
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).

Specified by:
addInjectedField in interface EnhancementOperation
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 Class convertTypeName(String type)
Description copied from interface: EnhancementOperation
Converts a type name (an object class name, a primtive name, or an array) into the corresponding Class object.

Specified by:
convertTypeName in interface EnhancementOperation

getPropertyType

public Class getPropertyType(String name)
Description copied from interface: EnhancementOperation
Returns the type of an existing property of the base component class. If the property does not exist, then returns null.

Specified by:
getPropertyType in interface EnhancementOperation
Parameters:
name - The property name.
Returns:
The property type, or null if it doesn't exist.

validateProperty

public void validateProperty(String name,
                             Class expectedType)
Description copied from interface: EnhancementOperation
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.

Specified by:
validateProperty in interface EnhancementOperation

getAccessorMethodName

public String getAccessorMethodName(String propertyName)
Description copied from interface: EnhancementOperation
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.

Specified by:
getAccessorMethodName in interface EnhancementOperation
Parameters:
propertyName - The property to get an accessor method name of.
Returns:
The existing/future name of an appropriate accessor method for the property.

addMethod

public void addMethod(int modifier,
                      org.apache.hivemind.service.MethodSignature sig,
                      String methodBody,
                      org.apache.hivemind.Location location)
Description copied from interface: EnhancementOperation
Adds a method to the enhanced class.

Specified by:
addMethod in interface EnhancementOperation
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 Class getBaseClass()
Description copied from interface: EnhancementOperation
Returns the base component class, as defined in the specification (or defaulted). An enhaced subclass of the component class will usually be created.

Specified by:
getBaseClass in interface EnhancementOperation
Returns:
The class this enhancement operation is operating on.

getClassReference

public String getClassReference(Class clazz)
Description copied from interface: EnhancementOperation
Returns a reference to a particular class. This will, effectively, by the name of a private field.

Specified by:
getClassReference in interface EnhancementOperation
Parameters:
clazz - The class to get a string equivalent reference of.
Returns:
The enhancement (javassist) compatiable string version of the specified class.

getConstructor

public ComponentConstructor getConstructor()
Returns an object that can be used to construct instances of the enhanced component subclass. This should only be called once.


extendMethodImplementation

public void extendMethodImplementation(Class interfaceClass,
                                       org.apache.hivemind.service.MethodSignature methodSignature,
                                       String code)
Description copied from interface: EnhancementOperation
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).

Specified by:
extendMethodImplementation in interface EnhancementOperation
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(Class interfaceClass)
Description copied from interface: EnhancementOperation
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 EnhancementOperation.extendMethodImplementation(Class, MethodSignature, String).

Specified by:
implementsInterface in interface EnhancementOperation
Parameters:
interfaceClass - The class to check if the base class implements.
Returns:
Whether or not the specified interface is implemented by the base class being enhanced.

findUnclaimedAbstractProperties

public List findUnclaimedAbstractProperties()
Description copied from interface: EnhancementOperation
Returns a list of the names of existing properties that are not claimed and which have abstract accessor methods.

Specified by:
findUnclaimedAbstractProperties in interface EnhancementOperation

getSpecification

public IComponentSpecification getSpecification()
Description copied from interface: EnhancementOperation
The specification defined for the component class being enhanced.

Specified by:
getSpecification in interface EnhancementOperation
Returns:
The specification for the component being enhanced.


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.