org.apache.hivemind.service.impl
Class ClassFabImpl

java.lang.Object
  extended by org.apache.hivemind.service.impl.AbstractFab
      extended by org.apache.hivemind.service.impl.ClassFabImpl
All Implemented Interfaces:
ClassFab

public class ClassFabImpl
extends AbstractFab
implements ClassFab

Implementation of ClassFab. Hides, as much as possible, the underlying library (Javassist).

Author:
Howard Lewis Ship

Constructor Summary
ClassFabImpl(CtClassSource source, javassist.CtClass ctClass)
           
 
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.
 MethodFab addMethod(int modifiers, MethodSignature ms, java.lang.String body)
          Adds a method.
 boolean containsMethod(MethodSignature ms)
          Convenience method for checking whether the fabricated class already contains a method.
 MethodFab getMethodFab(MethodSignature ms)
          Returns a previous defined method so that it can be further enhanced (perhaps by adding additional catches, etc.).
 java.lang.String toString()
          Returns a representation of the fabricated class, including inheritance, fields, constructors, methods and method bodies.
 
Methods inherited from class org.apache.hivemind.service.impl.AbstractFab
addInterface, canConvert, convertClass, convertClasses, createClass, getCtClass, getSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.hivemind.service.ClassFab
addInterface, canConvert, createClass
 

Constructor Detail

ClassFabImpl

public ClassFabImpl(CtClassSource source,
                    javassist.CtClass ctClass)
Method Detail

toString

public java.lang.String toString()
Returns a representation of the fabricated class, including inheritance, fields, constructors, methods and method bodies.

Overrides:
toString in class java.lang.Object
Since:
1.1

addField

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

Specified by:
addField in interface ClassFab

containsMethod

public boolean containsMethod(MethodSignature ms)
Description copied from interface: ClassFab
Convenience method for checking whether the fabricated class already contains a method.

Specified by:
containsMethod in interface ClassFab
Parameters:
ms - the signature
Returns:
whether or not the fabricated class already contains the method

addMethod

public MethodFab addMethod(int modifiers,
                           MethodSignature ms,
                           java.lang.String body)
Description copied from interface: ClassFab
Adds a method. The method is a public instance method.

Specified by:
addMethod in interface ClassFab
Parameters:
modifiers - Modifiers for the method (see Modifier).
ms - defines the name, return type, parameters and exceptions thrown
body - The body of the method.
Returns:
a method fabricator, used to add catch handlers.

getMethodFab

public MethodFab getMethodFab(MethodSignature ms)
Description copied from interface: ClassFab
Returns a previous defined method so that it can be further enhanced (perhaps by adding additional catches, etc.).

Specified by:
getMethodFab in interface ClassFab
Parameters:
ms - 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)
Description copied from interface: ClassFab
Adds a constructor to the class. The constructor will be public.

Specified by:
addConstructor in interface ClassFab
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.


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