org.jpox.enhancer
Class GeneratorBase

java.lang.Object
  extended byorg.jpox.enhancer.GeneratorBase
All Implemented Interfaces:
Generator
Direct Known Subclasses:
JPOXEnhancer

public abstract class GeneratorBase
extends java.lang.Object
implements Generator

Enhancer base class.

Version:
$Revision: 1.87 $

Field Summary
protected  java.util.List addFieldList
          append field list
protected  long addSerialVersionUID
          serialVersionUID value
 EnhancerClassMetaData classConfig
          class config of enhancing class
 java.lang.String className
          class name of enhancing class
 org.apache.bcel.generic.ObjectType classType
          class type of enhancing class
protected  org.jpox.ClassLoaderResolver clr
           
 org.apache.bcel.generic.ConstantPoolGen constantPoolGen
          constatnt pool of enhancing class
 org.jpox.metadata.FileMetaData jdoConfig
          config of enhancing class
protected static org.jpox.util.Localiser LOCALISER
          Message resource
protected  java.util.List methodBuilderList
          append method list
 org.apache.bcel.generic.ClassGen newClass
          enhancing class
 org.apache.bcel.classfile.JavaClass oldClass
          Original class
 org.jpox.metadata.PackageMetaData packageConfig
          package config of enhancing class
protected  boolean update
          flag for enhanceing ok
 
Fields inherited from interface org.jpox.enhancer.Generator
CN_BitSet, CN_ByteIdentity, CN_CharIdentity, CN_Class, CN_ClassCastException, CN_Detachable, CN_Flag, CN_IllegalArgumentException, CN_IllegalStateException, CN_IntIdentity, CN_JDODetachedFieldAccessException, CN_JDOFatalInternalException, CN_JDOHelper, CN_JDOImplHelper, CN_LongIdentity, CN_ObjectIdentity, CN_ObjectIdFieldConsumer, CN_ObjectIdFieldSupplier, CN_PersistenceCapable, CN_PersistenceManager, CN_ShortIdentity, CN_StateManager, CN_StringIdentity, FN_FieldFlags, FN_FieldNames, FN_FieldTypes, FN_Flag, FN_JdoDetachedState, FN_JdoLoadedFields, FN_JdoModifiedFields, FN_JdoObjectId, FN_JdoParentFieldCount, FN_JdoVersion, FN_PersistenceCapableSuperclass, FN_serialVersionUID, FN_StateManager, MN_FieldFlagsInitMethod, MN_FieldNamesInitMethod, MN_FieldTypesInitMethod, MN_JdoGetPersistenceManager, MN_JdoIsDetached, MN_jdoLoadClass, MN_JdoManagingFieldCountMethod, MN_JdoParentManagingFieldCountMethod, MN_JdoPreSerialize, MN_JdoSuperClone, MN_PersistenceCapableSuperclassInitMethod, OT_BitSet, OT_ByteIdentity, OT_CharIdentity, OT_CLASS, OT_Detachable, OT_Flag, OT_IntIdentity, OT_JDOImplHelper, OT_LongIdentity, OT_ObjectArray, OT_ObjectIdentity, OT_ObjectIdFieldConsumer, OT_ObjectIdFieldSupplier, OT_PersistenceCapable, OT_PersistenceManager, OT_ShortIdentity, OT_StateManager, OT_StringIdentity
 
Constructor Summary
GeneratorBase(EnhancerClassMetaData classConfig)
          Constructor.
 
Method Summary
 java.lang.String check()
          Method to check the class for obvious errors
protected  boolean checkEnhanced()
          Check original class is already enhanced.
protected  java.lang.String checkHasDefaultConstructor()
          Check original class has default(no arg) constructor.
protected  void class_addInterface(java.lang.String interfaceName)
          Method to add the "implements {interface}" to the class description.
protected  void dumpClass(java.io.OutputStream out)
           
 void enhance()
          Method to enhance the classes.
 void enhanceClass()
          Method to enhance the class as a whole, providing the required interfaces and adding any setters/getters for its fields
abstract  void enhanceClassAfter()
          call after check enhanceClass() method.
abstract  void enhanceClassBefore()
          call after check method.
 void enhanceFields()
          Method to enhance the fields
abstract  void enhanceFieldsAfter()
          call after check enhanceFields() method.
abstract  void enhanceFieldsBefore()
          call after check enhanceClassAfter() method.
protected  void enhanceGetter(EnhancerFieldMetaData fieldConfig)
           
 void enhanceMethod()
          Method to enhance the methods of the class.
abstract  void enhanceMethodAfter()
          call after check enhanceMethod() method.
abstract  void enhanceMethodBefore()
          call after check enhanceFieldsAfter() method.
protected  void enhanceOriginalMethod(org.apache.bcel.classfile.Method m)
           
protected  void enhanceOriginalMethods()
           
protected  void enhanceSetter(EnhancerFieldMetaData fieldConfig)
           
 void enhanceStaticInitializer()
          call after check enhanceStaticInitializerBefore() method.
abstract  void enhanceStaticInitializerAfter()
          call after check enhanceStaticInitializer() method.
abstract  void enhanceStaticInitializerBefore()
          call after check enhanceMethodAfter() method.
protected  void field_addField(org.apache.bcel.generic.FieldGen fieldGen)
           
 byte[] getBytes()
          Access the class in byte array format
 org.jpox.ClassLoaderResolver getClassLoaderResolver()
           
static java.lang.String[] getFullClassNames(org.jpox.metadata.FileMetaData config)
           
protected abstract  GeneratorBase getGenerator()
           
protected  void init_addFieldsList()
          append basic fields.
protected  void init_addMethodCallbackList()
          append basic method.
 void init()
          Initialisation.
static org.jpox.metadata.FileMetaData[] readJDOConfig(org.jpox.PMFContext context, java.lang.String[] fileList)
          Method to read in and initialise the supplied JDO MetaData files.
protected abstract  void staticInitializerAppend(org.apache.bcel.generic.InstructionFactory factory, org.apache.bcel.generic.InstructionList il)
           
 void store(java.lang.String dir)
          Enhance the class writing to the specified location.
 void update()
          Enhance the class, overwriting the existing class location.
 void verify()
          Method to verify the enhancement state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static org.jpox.util.Localiser LOCALISER
Message resource


oldClass

public final org.apache.bcel.classfile.JavaClass oldClass
Original class


newClass

public final org.apache.bcel.generic.ClassGen newClass
enhancing class


constantPoolGen

public final org.apache.bcel.generic.ConstantPoolGen constantPoolGen
constatnt pool of enhancing class


jdoConfig

public final org.jpox.metadata.FileMetaData jdoConfig
config of enhancing class


packageConfig

public final org.jpox.metadata.PackageMetaData packageConfig
package config of enhancing class


classConfig

public final EnhancerClassMetaData classConfig
class config of enhancing class


className

public final java.lang.String className
class name of enhancing class


classType

public final org.apache.bcel.generic.ObjectType classType
class type of enhancing class


addFieldList

protected java.util.List addFieldList
append field list


methodBuilderList

protected java.util.List methodBuilderList
append method list


update

protected boolean update
flag for enhanceing ok


addSerialVersionUID

protected long addSerialVersionUID
serialVersionUID value


clr

protected final org.jpox.ClassLoaderResolver clr
Constructor Detail

GeneratorBase

public GeneratorBase(EnhancerClassMetaData classConfig)
Constructor.

Parameters:
classConfig - base config file.
Method Detail

getGenerator

protected abstract GeneratorBase getGenerator()

init

public void init()
Initialisation.

Specified by:
init in interface Generator

init_addMethodCallbackList

protected void init_addMethodCallbackList()
append basic method.


init_addFieldsList

protected void init_addFieldsList()
append basic fields.


check

public java.lang.String check()
Method to check the class for obvious errors

Specified by:
check in interface Generator
Returns:
An error message (null if no errors found)

checkHasDefaultConstructor

protected java.lang.String checkHasDefaultConstructor()
Check original class has default(no arg) constructor.
Original class must has default(no arg) constructor.

Returns:
Return null if this class has default constructor.

checkEnhanced

protected boolean checkEnhanced()
Check original class is already enhanced.

Returns:
Return true if already enhanced class.

enhance

public void enhance()
Method to enhance the classes.

Specified by:
enhance in interface Generator

enhanceClass

public void enhanceClass()
Method to enhance the class as a whole, providing the required interfaces and adding any setters/getters for its fields

Specified by:
enhanceClass in interface Generator

class_addInterface

protected void class_addInterface(java.lang.String interfaceName)
Method to add the "implements {interface}" to the class description.

Parameters:
interfaceName - Name of the interface to add.

enhanceClassAfter

public abstract void enhanceClassAfter()
Description copied from interface: Generator
call after check enhanceClass() method.

Specified by:
enhanceClassAfter in interface Generator

enhanceClassBefore

public abstract void enhanceClassBefore()
Description copied from interface: Generator
call after check method.

Specified by:
enhanceClassBefore in interface Generator

enhanceFields

public void enhanceFields()
Method to enhance the fields

Specified by:
enhanceFields in interface Generator

field_addField

protected void field_addField(org.apache.bcel.generic.FieldGen fieldGen)

enhanceFieldsAfter

public abstract void enhanceFieldsAfter()
Description copied from interface: Generator
call after check enhanceFields() method.

Specified by:
enhanceFieldsAfter in interface Generator

enhanceFieldsBefore

public abstract void enhanceFieldsBefore()
Description copied from interface: Generator
call after check enhanceClassAfter() method.

Specified by:
enhanceFieldsBefore in interface Generator

enhanceMethod

public void enhanceMethod()
Method to enhance the methods of the class.

Specified by:
enhanceMethod in interface Generator

enhanceMethodAfter

public abstract void enhanceMethodAfter()
Description copied from interface: Generator
call after check enhanceMethod() method.

Specified by:
enhanceMethodAfter in interface Generator

enhanceMethodBefore

public abstract void enhanceMethodBefore()
Description copied from interface: Generator
call after check enhanceFieldsAfter() method.

Specified by:
enhanceMethodBefore in interface Generator

enhanceStaticInitializer

public void enhanceStaticInitializer()
Description copied from interface: Generator
call after check enhanceStaticInitializerBefore() method.

Specified by:
enhanceStaticInitializer in interface Generator

staticInitializerAppend

protected abstract void staticInitializerAppend(org.apache.bcel.generic.InstructionFactory factory,
                                                org.apache.bcel.generic.InstructionList il)

enhanceStaticInitializerAfter

public abstract void enhanceStaticInitializerAfter()
Description copied from interface: Generator
call after check enhanceStaticInitializer() method.

Specified by:
enhanceStaticInitializerAfter in interface Generator

enhanceStaticInitializerBefore

public abstract void enhanceStaticInitializerBefore()
Description copied from interface: Generator
call after check enhanceMethodAfter() method.

Specified by:
enhanceStaticInitializerBefore in interface Generator

enhanceOriginalMethod

protected void enhanceOriginalMethod(org.apache.bcel.classfile.Method m)

enhanceOriginalMethods

protected void enhanceOriginalMethods()

enhanceSetter

protected void enhanceSetter(EnhancerFieldMetaData fieldConfig)

enhanceGetter

protected void enhanceGetter(EnhancerFieldMetaData fieldConfig)

getFullClassNames

public static java.lang.String[] getFullClassNames(org.jpox.metadata.FileMetaData config)

readJDOConfig

public static org.jpox.metadata.FileMetaData[] readJDOConfig(org.jpox.PMFContext context,
                                                             java.lang.String[] fileList)
                                                      throws java.lang.Exception
Method to read in and initialise the supplied JDO MetaData files. If any files cannot be read, they are discarded. If any errors exist in the MetaData, messages are output and the process proceeds.

Parameters:
context - the PMF context
fileList - List of files.
Returns:
Array of JDOConfig representing the MetaData for these files.
Throws:
java.lang.Exception

update

public void update()
            throws java.io.IOException
Enhance the class, overwriting the existing class location.

Throws:
java.io.IOException - If an I/O error has occurs in the write.

store

public void store(java.lang.String dir)
           throws java.io.IOException
Enhance the class writing to the specified location.

Parameters:
dir - base dir
Throws:
java.io.IOException - If an I/O error has occurred.

dumpClass

protected void dumpClass(java.io.OutputStream out)
                  throws java.io.IOException
Throws:
java.io.IOException

getBytes

public byte[] getBytes()
Access the class in byte array format

Returns:
the class in byte array format

verify

public void verify()
            throws java.lang.Exception
Method to verify the enhancement state.

Throws:
java.lang.Exception

getClassLoaderResolver

public org.jpox.ClassLoaderResolver getClassLoaderResolver()


Copyright © -2007 . All Rights Reserved.