org.apache.hivemind.service
Interface ClassFab

All Known Implementing Classes:
ClassFabImpl

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. The BodyBuilder class is very useful for assembling this method bodies. 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:

Author:
Howard Lewis Ship

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 addInterface(java.lang.Class interfaceClass)
          Adds the specified interface as an interface implemented by this class.
 MethodFab addMethod(int modifiers, MethodSignature signature, java.lang.String body)
          Adds a method.
 java.lang.Class createClass()
          Invoked last to create the class.
 MethodFab getMethodFab(MethodSignature signature)
          Returns a previous defined method so that it can be further enhanced (perhaps by adding additional catches, etc.).
 

Method Detail

addInterface

public void addInterface(java.lang.Class interfaceClass)
Adds the specified interface as an interface implemented by this class.


addField

public void addField(java.lang.String name,
                     java.lang.Class type)
Adds a new field with the given name and type. The field is added as a private field.


addMethod

public MethodFab addMethod(int modifiers,
                           MethodSignature signature,
                           java.lang.String body)
Adds a method. The method is a public instance method.

Parameters:
modifiers - Modifiers for the method (see Modifier).
signature - defines the name, return type, parameters and exceptions thrown
body - The body of the method.
Returns:
a method fabricator, used to add catch handlers.
Throws:
ApplicationRuntimeException - if a method with that signature has already been added, or if there is a Javassist compilation error

getMethodFab

public MethodFab getMethodFab(MethodSignature signature)
Returns a previous defined method so that it can be further enhanced (perhaps by adding additional catches, etc.).

Parameters:
signature - the signature of the method previously added
Returns:
the MethodFab for that method, or null if the method has not been added yet

addConstructor

public void addConstructor(java.lang.Class[] parameterTypes,
                           java.lang.Class[] exceptions,
                           java.lang.String body)
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.
exceptions - the type of each exception, or null if the constructor throws no exceptions.
body - The body of the constructor.

createClass

public java.lang.Class createClass()
Invoked last to create the class. This will enforce that all abstract methods have been implemented in the (concrete) class.