org.apache.tapestry5.ioc.internal.services
Class ClassFabImpl

java.lang.Object
  extended by org.apache.tapestry5.ioc.internal.services.AbstractFab
      extended by org.apache.tapestry5.ioc.internal.services.ClassFabImpl
All Implemented Interfaces:
ClassFab

public class ClassFabImpl
extends AbstractFab
implements ClassFab

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


Field Summary
 
Fields inherited from class org.apache.tapestry5.ioc.internal.services.AbstractFab
lock
 
Constructor Summary
ClassFabImpl(CtClassSource source, javassist.CtClass ctClass, org.slf4j.Logger logger)
           
 
Method Summary
 void addConstructor(Class[] parameterTypes, Class[] exceptions, String body)
          Adds a constructor to the class.
 void addField(String name, Class type)
          Adds a new field with the given name and type.
 void addField(String name, int modifiers, Class type)
          Adds a new field with the provided modifiers.
 void addMethod(int modifiers, MethodSignature ms, String body)
          Adds a method.
 void addNoOpMethod(MethodSignature signature)
          Adds a public no-op method.
 void addToString(String toString)
          Adds an implementation of toString, as a method that returns a fixed string.
 void copyClassAnnotationsFromDelegate(Class delegateClass)
          Copies annotations from delegate class to the fabricated class.
 void copyMethodAnnotationsFromDelegate(Class serviceInterface, Class delegateClass)
          Copies method annotations from delegate class to the methods of the fabricated class.
 void proxyMethodsToDelegate(Class serviceInterface, String delegateExpression, String toString)
          Makes the fabricated class implement the provided service interface.
 String toString()
          Returns a representation of the fabricated class, including inheritance, fields, constructors, methods and method bodies.
 
Methods inherited from class org.apache.tapestry5.ioc.internal.services.AbstractFab
addInterface, createClass, getCtClass, getLogger, getSource, toCtClass, toCtClasses
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.tapestry5.ioc.services.ClassFab
addInterface, createClass
 

Constructor Detail

ClassFabImpl

public ClassFabImpl(CtClassSource source,
                    javassist.CtClass ctClass,
                    org.slf4j.Logger logger)
Method Detail

toString

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

Overrides:
toString in class Object

addField

public void addField(String name,
                     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

addField

public void addField(String name,
                     int modifiers,
                     Class type)
Description copied from interface: ClassFab
Adds a new field with the provided modifiers.

Specified by:
addField in interface ClassFab

proxyMethodsToDelegate

public void proxyMethodsToDelegate(Class serviceInterface,
                                   String delegateExpression,
                                   String toString)
Description copied from interface: ClassFab
Makes the fabricated class implement the provided service interface. The interface will be added, and all methods in the interface will be delegate wrappers. If toString() is not part of the delegate interface, then an implementation will be supplied that returns the provided string. This method is used when creating objects that proxy their behavior to some other object.

Specified by:
proxyMethodsToDelegate in interface ClassFab
Parameters:
serviceInterface - the interface to implement
delegateExpression - 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 object

addToString

public void addToString(String toString)
Description copied from interface: ClassFab
Adds an implementation of toString, as a method that returns a fixed string.

Specified by:
addToString in interface ClassFab

addMethod

public void addMethod(int modifiers,
                      MethodSignature ms,
                      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.

addNoOpMethod

public void addNoOpMethod(MethodSignature signature)
Description copied from interface: ClassFab
Adds a public no-op method. The method will return null, false, or zero as per the return type (if not void).

Specified by:
addNoOpMethod in interface ClassFab

addConstructor

public void addConstructor(Class[] parameterTypes,
                           Class[] exceptions,
                           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.

copyClassAnnotationsFromDelegate

public void copyClassAnnotationsFromDelegate(Class delegateClass)
Description copied from interface: ClassFab
Copies annotations from delegate class to the fabricated class.

Specified by:
copyClassAnnotationsFromDelegate in interface ClassFab
Parameters:
delegateClass - class of the delegate

copyMethodAnnotationsFromDelegate

public void copyMethodAnnotationsFromDelegate(Class serviceInterface,
                                              Class delegateClass)
Description copied from interface: ClassFab
Copies method annotations from delegate class to the methods of the fabricated class.

Specified by:
copyMethodAnnotationsFromDelegate in interface ClassFab
Parameters:
serviceInterface - service interface
delegateClass - class of the delegate


Copyright © 2003-2012 The Apache Software Foundation.