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.
 boolean canConvert(java.lang.Class inputClass)
           
 boolean containsMethod(MethodSignature signature)
          Convenience method for checking whether the fabricated class already contains 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

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


addField

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.


canConvert

boolean canConvert(java.lang.Class inputClass)

containsMethod

boolean containsMethod(MethodSignature signature)
Convenience method for checking whether the fabricated class already contains a method.

Parameters:
signature - the signature
Returns:
whether or not the fabricated class already contains the method

addMethod

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

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

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

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



Copyright © 2003-2007 Apache Software Foundation. All Rights Reserved.