org.apache.tapestry.enhance
Class ClassFabricator

java.lang.Object
  |
  +--org.apache.tapestry.enhance.ClassFabricator

public class ClassFabricator
extends Object

Class used to simplify the generation of new classes as a wrapper around BCEL.

Since:
3.0
Version:
$Id: ClassFabricator.java,v 1.5 2003/04/21 13:15:34 glongman Exp $
Author:
Howard Lewis Ship

Constructor Summary
ClassFabricator(String className, String parentClassName)
          Creates a public final class.
ClassFabricator(String className, String parentClassName, int accessFlags)
          General constructor, creates a new instance using the supplied parameters.
 
Method Summary
 void addDefaultConstructor()
          Adds a public, no-arguments constructor.
 void addField(int accessFlags, org.apache.bcel.generic.Type type, String name)
          Adds a field with the given access type, type and name.
 void addField(org.apache.bcel.generic.Type type, String name)
          Adds a private instance variable of the given type and name.
 void addInterface(Class interfaceClass)
           
 void addInterface(String interfaceName)
          Adds an interface to the list of interfaces implemented by the class.
 org.apache.bcel.classfile.JavaClass commit()
          Invoked very much last, to create the new JavaClass instance.
 MethodFabricator createMethod(int accessFlags, org.apache.bcel.generic.Type returnType, String methodName)
          Creates a new MethodFabricator.
 MethodFabricator createMethod(String methodName)
          Creates a default public method that returns void.
 String getClassName()
          Returns the name of the class being fabricated.
 org.apache.bcel.generic.ConstantPoolGen getConstantPool()
          Returns the mutable constant pool.
 org.apache.bcel.generic.InstructionFactory getInstructionFactory()
           
 MethodFabricator getStaticInitializerMethod()
          Returns the static initializer method for the class, creating it if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassFabricator

public ClassFabricator(String className,
                       String parentClassName)
Creates a public final class.


ClassFabricator

public ClassFabricator(String className,
                       String parentClassName,
                       int accessFlags)
General constructor, creates a new instance using the supplied parameters. ACC_SUPER is automatically added to the access flags.

Method Detail

createMethod

public MethodFabricator createMethod(int accessFlags,
                                     org.apache.bcel.generic.Type returnType,
                                     String methodName)
Creates a new MethodFabricator. Invoke MethodFabricator.getInstructionList() to obtain the (initially empty) instruction list for the method.


createMethod

public MethodFabricator createMethod(String methodName)
Creates a default public method that returns void.


addField

public void addField(org.apache.bcel.generic.Type type,
                     String name)
Adds a private instance variable of the given type and name.


addField

public void addField(int accessFlags,
                     org.apache.bcel.generic.Type type,
                     String name)
Adds a field with the given access type, type and name.


addDefaultConstructor

public void addDefaultConstructor()
Adds a public, no-arguments constructor.


addInterface

public void addInterface(String interfaceName)
Adds an interface to the list of interfaces implemented by the class.


addInterface

public void addInterface(Class interfaceClass)

getInstructionFactory

public org.apache.bcel.generic.InstructionFactory getInstructionFactory()

commit

public org.apache.bcel.classfile.JavaClass commit()
Invoked very much last, to create the new JavaClass instance. If there is a static initializer method, then a RETURN opcode is appended, and the method is committed.


getStaticInitializerMethod

public MethodFabricator getStaticInitializerMethod()
Returns the static initializer method for the class, creating it if necessary.

Do not add RETURN opcodes to the initializer; it may be accessed by several enhancers, each of which will need to add some code; putting a RETURN in the middle will keep some of the initializations from being executed!

commit() will append a RETURN and commit the method.


getConstantPool

public org.apache.bcel.generic.ConstantPoolGen getConstantPool()
Returns the mutable constant pool.


getClassName

public String getClassName()
Returns the name of the class being fabricated.