|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface ClassFab
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
ClassFactory.
| Method Summary | |
|---|---|
void |
addConstructor(java.lang.Class[] parameterTypes,
java.lang.Class[] exceptions,
java.lang.String body)
Adds a constructor to the class. |
void |
addField(java.lang.String name,
java.lang.Class type)
Adds a new field with the given name and type. |
void |
addField(java.lang.String name,
int modifiers,
java.lang.Class Type)
Adds a new field with the provided modifiers. |
void |
addInterface(java.lang.Class interfaceClass)
Adds the specified interface as an interface implemented by this class. |
void |
addMethod(int modifiers,
MethodSignature signature,
java.lang.String body)
Adds a method. |
void |
addNoOpMethod(MethodSignature signature)
Adds a public no-op method. |
void |
addToString(java.lang.String toString)
Adds an implementation of toString, as a method that returns a fixed string. |
void |
copyClassAnnotationsFromDelegate(java.lang.Class delegateClass)
Copies annotations from delegate class to the fabricated class. |
void |
copyMethodAnnotationsFromDelegate(java.lang.Class serviceInterface,
java.lang.Class delegateClass)
Copies method annotations from delegate class to the methods of the fabricated class. |
java.lang.Class |
createClass()
Invoked last to create the class. |
void |
proxyMethodsToDelegate(java.lang.Class serviceInterface,
java.lang.String delegateExpression,
java.lang.String toString)
Makes the fabricated class implement the provided service interface. |
| Method Detail |
|---|
void addInterface(java.lang.Class interfaceClass)
void addField(java.lang.String name,
java.lang.Class type)
void addField(java.lang.String name,
int modifiers,
java.lang.Class Type)
void addMethod(int modifiers,
MethodSignature signature,
java.lang.String body)
modifiers - Modifiers for the method (see Modifier).signature - defines the name, return type, parameters and exceptions thrownbody - The body of the method.
java.lang.RuntimeException - if a method with that signature has already been added, or if there is a Javassist
compilation error
void addConstructor(java.lang.Class[] parameterTypes,
java.lang.Class[] exceptions,
java.lang.String body)
parameterTypes - the type of each parameter, or null if the constructor takes no parameters.exceptions - the type of each exception, or null if the constructor throws no exceptions.body - The body of the constructor.void addToString(java.lang.String toString)
void proxyMethodsToDelegate(java.lang.Class serviceInterface,
java.lang.String delegateExpression,
java.lang.String toString)
serviceInterface - the interface to implementdelegateExpression - 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()".toString - fixed value to be returned as the description of the resultant objectvoid copyClassAnnotationsFromDelegate(java.lang.Class delegateClass)
delegateClass - class of the delegate
void copyMethodAnnotationsFromDelegate(java.lang.Class serviceInterface,
java.lang.Class delegateClass)
serviceInterface - service interfacedelegateClass - class of the delegatejava.lang.Class createClass()
void addNoOpMethod(MethodSignature signature)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||