| org.apache.tapestry.ioc.services.ClassFab
All known Subclasses: org.apache.tapestry.ioc.internal.services.ClassFabImpl,
ClassFab | public interface ClassFab (Code) | | Used when fabricating a new class. Represents a wrapper around the Javassist library.
The core concept of Javassist is how method bodies (as well as constructor bodies, etc.) are
specified ... as a very Java-like scripting language. Details are available at the Javassist home page.
Method bodies look largely like Java. References to java classes must be fully qualified. Several
special variables are used:
$0 first parameter, equivalent to this in Java code (and can't
be used when creating a static method)
$1, $2, ... actual parameters to the method
$args all the parameters as an Object[]
$r the return type of the method, typically used as
return ($r) ... . $r is valid with method that return
void . This also handles conversions between wrapper types and primitive types.
$w conversion from primitive type to wrapper type, used as
($w) foo() where foo() returns a primitive type and a wrapper type
is needed
-
ClassFab instances are not thread safe.
ClassFab instances are created by a
org.apache.tapestry.ioc.services.ClassFactory .
|
Method Summary | |
void | addConstructor(Class[] parameterTypes, Class[] exceptions, String body) Adds a constructor to the class. | void | addField(String name, Class type) Adds a new field with the given name and type. | void | addField(String name, int modifiers, Class Type) Adds a new field with the provided modifiers. | void | addInterface(Class interfaceClass) Adds the specified interface as an interface implemented by this class. | void | addMethod(int modifiers, MethodSignature signature, String body) Adds a method. | void | addNoOpMethod(MethodSignature signature) Adds a public no-op method. | void | addToString(String toString) Adds an implementation of toString, as a method that returns a fixed string. | Class | createClass() Invoked last to create the class. | void | proxyMethodsToDelegate(Class serviceInterface, String delegateExpression, String toString) Makes the fabricated class implement the provided service interface. |
addConstructor | void addConstructor(Class[] parameterTypes, Class[] exceptions, String body)(Code) | | Adds a constructor to the class. The constructor will be public.
Parameters: parameterTypes - the type of each parameter, or null if the constructor takes no parameters. Parameters: exceptions - the type of each exception, or null if the constructor throws no exceptions. Parameters: body - The body of the constructor. |
addField | void addField(String name, Class type)(Code) | | Adds a new field with the given name and type. The field is added as a private field.
|
addField | void addField(String name, int modifiers, Class Type)(Code) | | Adds a new field with the provided modifiers.
|
addInterface | void addInterface(Class interfaceClass)(Code) | | Adds the specified interface as an interface implemented by this class. It is not an error to
invoke this method multiple times with the same interface class (and the interface is only
added once).
|
addMethod | void addMethod(int modifiers, MethodSignature signature, String body)(Code) | | Adds a method. The method is a public instance method.
a method fabricator, used to add catch handlers. Parameters: modifiers - Modifiers for the method (see java.lang.reflect.Modifier). Parameters: signature - defines the name, return type, parameters and exceptions thrown Parameters: body - The body of the method. throws: RuntimeException - if a method with that signature has already been added, or if there is aJavassist compilation error |
addNoOpMethod | void addNoOpMethod(MethodSignature signature)(Code) | | Adds a public no-op method. The method will return null, false, or zero as per the return
type (if not void).
|
addToString | void addToString(String toString)(Code) | | Adds an implementation of toString, as a method that returns a fixed string.
|
createClass | Class createClass()(Code) | | Invoked last to create the class. This will enforce that all abstract methods have been
implemented in the (concrete) class.
|
proxyMethodsToDelegate | void proxyMethodsToDelegate(Class serviceInterface, String delegateExpression, String toString)(Code) | | Makes the fabricated class implement the provided service interface. The interface will be
added, and all methods in the interface will be delegate wrappers. If toString() is not part
of the delegate interface, then an implementation will be supplied that returns the provided
string. This method is used when creating objects that proxy their behavior to some other
object.
Parameters: serviceInterface - the interface to implement Parameters: delegateExpression - the expression used to find the delegate on which methods should be invoked.Typically a field name, such as "_delegate", or a method to invoke, such as"_service()". Parameters: toString - fixed value to be returned as the description of the resultant object |
|
|