org.apache.tapestry5.internal.transform
Class BridgeClassTransformation

java.lang.Object
  extended by org.apache.tapestry5.internal.transform.BridgeClassTransformation
All Implemented Interfaces:
AnnotationProvider, ClassTransformation

public class BridgeClassTransformation
extends Object
implements ClassTransformation

A re-implementation of ClassTransformation around an instance of PlasticClass, acting as a bridge for code written against the 5.2 and earlier APIs to work with the 5.3 API.

Since:
5.3

Constructor Summary
BridgeClassTransformation(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model)
           
 
Method Summary
 void addComponentEventHandler(String eventType, int minContextValues, String methodDescription, ComponentEventHandler handler)
          Adds advice to the Component.dispatchComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) method.
 void addImplementedInterface(Class interfaceClass)
          Transforms the class to implement the indicated interface.
<T> TransformField
addIndirectInjectedField(Class<T> type, String suggestedName, ComponentValueProvider<T> provider)
          Like ClassTransformation.addInjectedField(Class, String, Object), but instead of specifying the value, a provider for the value is specified.
 String addInjectedField(Class type, String suggestedName, Object value)
          Defines a new protected instance variable whose initial value is provided statically, via a constructor parameter.
 TransformField createField(int modifiers, String type, String suggestedName)
          Defines a new declared field for the class.
<T extends Annotation>
T
getAnnotation(Class<T> annotationClass)
          Searches for the specified annotation, returning the matching annotation instance.
 String getClassName()
          Returns the fully qualified class name of the class being transformed.
 TransformField getField(String fieldName)
          Locates a declared field by its field name.
 org.slf4j.Logger getLogger()
          Returns a logger, based on the class name being transformed, to which warnings or errors concerning the class being transformed may be logged.
 TransformMethod getOrCreateMethod(TransformMethodSignature signature)
          Locates and returns the method if declared in this class; If not, the method is added to the class.
 boolean isDeclaredMethod(TransformMethodSignature signature)
          Determines if the class being transformed includes a declared (not inherited) method with the provided signature.
 boolean isField(String fieldName)
          Returns true if the indicated name is a private instance field.
 boolean isRootTransformation()
          Returns true if this transformation represents a root class (one that extends directly from Object), or false if this transformation is an sub-class of another transformed class.
 List<TransformField> matchFields(Predicate<TransformField> predicate)
          Finds all unclaimed fields matched by the provided predicate.
 List<TransformField> matchFieldsWithAnnotation(Class<? extends Annotation> annotationClass)
          Returns a sorted list of declared instance fields with the indicated annotation.
 List<TransformMethod> matchMethods(Predicate<TransformMethod> predicate)
          Finds all methods matched by the provided predicate.
 List<TransformMethod> matchMethodsWithAnnotation(Class<? extends Annotation> annotationType)
          Finds all methods matched by the provided predicate.
 List<TransformField> matchUnclaimedFields()
          Matches all fields that are not claimed.
 String newMemberName(String suggested)
          Returns the name of a new member (field or method).
 String newMemberName(String prefix, String baseName)
          As with ClassTransformation.newMemberName(String), but the suggested name is constructed from the prefix and base name.
 Class toClass(String type)
          Converts a type name into a corresponding class (possibly, a transformed class).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BridgeClassTransformation

public BridgeClassTransformation(PlasticClass plasticClass,
                                 TransformationSupport support,
                                 MutableComponentModel model)
Method Detail

getAnnotation

public <T extends Annotation> T getAnnotation(Class<T> annotationClass)
Description copied from interface: AnnotationProvider
Searches for the specified annotation, returning the matching annotation instance.

Specified by:
getAnnotation in interface AnnotationProvider
Parameters:
annotationClass - used to select the annotation to return
Returns:
the annotation, or null if not found

getClassName

public String getClassName()
Description copied from interface: ClassTransformation
Returns the fully qualified class name of the class being transformed.

Specified by:
getClassName in interface ClassTransformation

newMemberName

public String newMemberName(String suggested)
Description copied from interface: ClassTransformation
Returns the name of a new member (field or method). Ensures that the resulting name does not conflict with any existing member (declared by the underlying class, or inherited from a base class).

Specified by:
newMemberName in interface ClassTransformation
Parameters:
suggested - the suggested value for the member
Returns:
a unique name for the member

newMemberName

public String newMemberName(String prefix,
                            String baseName)
Description copied from interface: ClassTransformation
As with ClassTransformation.newMemberName(String), but the suggested name is constructed from the prefix and base name. An underscore will separate the prefix from the base name.

Specified by:
newMemberName in interface ClassTransformation
Parameters:
prefix - for the generated name
baseName - a name, often of an existing field or method
Returns:
a unique name

matchFieldsWithAnnotation

public List<TransformField> matchFieldsWithAnnotation(Class<? extends Annotation> annotationClass)
Description copied from interface: ClassTransformation
Returns a sorted list of declared instance fields with the indicated annotation. Non-private and static fields are ignored.

Specified by:
matchFieldsWithAnnotation in interface ClassTransformation

matchMethods

public List<TransformMethod> matchMethods(Predicate<TransformMethod> predicate)
Description copied from interface: ClassTransformation
Finds all methods matched by the provided predicate.

Specified by:
matchMethods in interface ClassTransformation
Parameters:
predicate - Used to filter the list
Returns:
a list of matching methods (which may be empty) in ascending order (by method name), but descending order (by parameter count) within overrides of a single method name.

matchMethodsWithAnnotation

public List<TransformMethod> matchMethodsWithAnnotation(Class<? extends Annotation> annotationType)
Description copied from interface: ClassTransformation
Finds all methods matched by the provided predicate.

Specified by:
matchMethodsWithAnnotation in interface ClassTransformation
Parameters:
annotationType - Used to filter the list
Returns:
a list of matching methods (which may be empty) in ascending order (by method name), but descending order (by parameter count) within overrides of a single method name.

matchFields

public List<TransformField> matchFields(Predicate<TransformField> predicate)
Description copied from interface: ClassTransformation
Finds all unclaimed fields matched by the provided predicate. Only considers instance fields. Added, removed and claimed fields are excluded.

Specified by:
matchFields in interface ClassTransformation
Parameters:
predicate - used for matching
Returns:
sorted list of matching fields

getField

public TransformField getField(String fieldName)
Description copied from interface: ClassTransformation
Locates a declared field by its field name. The field must exist.

Specified by:
getField in interface ClassTransformation
Parameters:
fieldName - of declared field
Returns:
field information

matchUnclaimedFields

public List<TransformField> matchUnclaimedFields()
Description copied from interface: ClassTransformation
Matches all fields that are not claimed. This may include static fields and final fields, but will not include fields that have been added as part of the transformation.

Specified by:
matchUnclaimedFields in interface ClassTransformation
Returns:
sorted list of unclaimed fields

isField

public boolean isField(String fieldName)
Description copied from interface: ClassTransformation
Returns true if the indicated name is a private instance field.

Specified by:
isField in interface ClassTransformation
Returns:
true if field exists

createField

public TransformField createField(int modifiers,
                                  String type,
                                  String suggestedName)
Description copied from interface: ClassTransformation
Defines a new declared field for the class. Suggested name may be modified to ensure uniqueness.

Specified by:
createField in interface ClassTransformation
Parameters:
modifiers - modifiers for the field (typically, Modifier.PRIVATE)
type - the type for the field, as a string
suggestedName - the desired name for the field, which may be modified (for uniqueness) when returned
Returns:
new field instance

addInjectedField

public String addInjectedField(Class type,
                               String suggestedName,
                               Object value)
Description copied from interface: ClassTransformation
Defines a new protected instance variable whose initial value is provided statically, via a constructor parameter. The transformation caches the result, so calling this method repeatedly with the same type and value will return the same field name. Caching extends to the parent transformation, so that a value injected into a parent class will be available (via the protected instance variable) to subclasses. This is primarily used to inject service dependencies into components, though it has a number of other uses as well.

Specified by:
addInjectedField in interface ClassTransformation
Parameters:
type - the type of object to inject
suggestedName - the suggested name for the new field
value - to be injected. This value is retained.
Returns:
the actual name of the injected field

addIndirectInjectedField

public <T> TransformField addIndirectInjectedField(Class<T> type,
                                                   String suggestedName,
                                                   ComponentValueProvider<T> provider)
Description copied from interface: ClassTransformation
Like ClassTransformation.addInjectedField(Class, String, Object), but instead of specifying the value, a provider for the value is specified. In the generated class' constructor, the provider will be passed the ComponentResources and will return the final value; thus each component instance will receive a matching unique instance via the provider.

Specified by:
addIndirectInjectedField in interface ClassTransformation
Parameters:
type - type of value to inject
suggestedName - suggested name for the new field
provider - injected into the component to provide the value
Returns:
the actual name of the injected field

addImplementedInterface

public void addImplementedInterface(Class interfaceClass)
Description copied from interface: ClassTransformation
Transforms the class to implement the indicated interface. If the class (or its super class) does not already implement the interface, then the interface is added, and default implementations of any methods of the interface are added.

TODO: Checking that the names of methods in the interface do not conflict with the names of methods present in the (unmodified) class.

Specified by:
addImplementedInterface in interface ClassTransformation
Parameters:
interfaceClass - the interface to be implemented by the class

toClass

public Class toClass(String type)
Description copied from interface: ClassTransformation
Converts a type name into a corresponding class (possibly, a transformed class). Primitive type names are returned as wrapper types.

Specified by:
toClass in interface ClassTransformation

getLogger

public org.slf4j.Logger getLogger()
Description copied from interface: ClassTransformation
Returns a logger, based on the class name being transformed, to which warnings or errors concerning the class being transformed may be logged.

Specified by:
getLogger in interface ClassTransformation

isRootTransformation

public boolean isRootTransformation()
Description copied from interface: ClassTransformation
Returns true if this transformation represents a root class (one that extends directly from Object), or false if this transformation is an sub-class of another transformed class.

Specified by:
isRootTransformation in interface ClassTransformation
Returns:
true if root class, false if sub-class

getOrCreateMethod

public TransformMethod getOrCreateMethod(TransformMethodSignature signature)
Description copied from interface: ClassTransformation
Locates and returns the method if declared in this class; If not, the method is added to the class. If the method is an override of a base class method, then the method will delegate to the base class method (invoke it, return its value). If the method is entirely new, it will ignore its parameters and return a default value (null, 0 or false).

Specified by:
getOrCreateMethod in interface ClassTransformation
Parameters:
signature - identifies the method to locate, override or create

isDeclaredMethod

public boolean isDeclaredMethod(TransformMethodSignature signature)
Description copied from interface: ClassTransformation
Determines if the class being transformed includes a declared (not inherited) method with the provided signature.

Specified by:
isDeclaredMethod in interface ClassTransformation
Parameters:
signature - identifies method to search for
Returns:
true if a such a method exists

addComponentEventHandler

public void addComponentEventHandler(String eventType,
                                     int minContextValues,
                                     String methodDescription,
                                     ComponentEventHandler handler)
Description copied from interface: ClassTransformation
Adds advice to the Component.dispatchComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) method. If the handler is invoked, the return value of the method will be overriden to true. Updates the model to indicate that there is a handler for the named event. Existing handlers, or super-class handlers, are invoked first.

Specified by:
addComponentEventHandler in interface ClassTransformation
Parameters:
eventType - name of event to be handled
minContextValues - minimum number of event context values required to invoke the method
methodDescription - Text description of what the handler does (used with Event.setMethodDescription(String))
handler - the handler to invoke


Copyright © 2003-2012 The Apache Software Foundation.