org.jpox.enhancer.bcel
Class BCELClassEnhancer

java.lang.Object
  extended by org.jpox.enhancer.AbstractClassEnhancer
      extended by org.jpox.enhancer.bcel.BCELClassEnhancer
All Implemented Interfaces:
ClassEnhancer

public class BCELClassEnhancer
extends AbstractClassEnhancer

Class enhancer using Apache BCEL (http://jakarta.apache.org/bcel).

Version:
$Revision: 1.12.2.2 $

Field Summary
protected  java.util.List addFieldList
          append field list
protected  long addSerialVersionUID
          serialVersionUID value
 BCELClassMetaData classConfig
          class config of enhancing class (BCEL version of "cmd").
 org.apache.bcel.generic.ObjectType classType
          class type of enhancing class
 org.apache.bcel.generic.ConstantPoolGen constantPoolGen
          constant pool of enhancing class
protected  java.util.List methodBuilderList
          append method list
 org.apache.bcel.generic.ClassGen newClass
          enhancing class
 org.apache.bcel.classfile.JavaClass oldClass
          Original class
static org.apache.bcel.generic.ObjectType OT_BitSet
          Object type of java.util.BitSet
static org.apache.bcel.generic.ObjectType OT_ByteIdentity
           
static org.apache.bcel.generic.ObjectType OT_CharIdentity
           
static org.apache.bcel.generic.ObjectType OT_CLASS
          Object type of java.lang.Class
static org.apache.bcel.generic.ObjectType OT_Detachable
          Object type of javax.jdo.spi.Detachable
static org.apache.bcel.generic.Type OT_Flag
          Field type of jdoFlag
static org.apache.bcel.generic.ObjectType OT_IntIdentity
           
static org.apache.bcel.generic.ObjectType OT_JDOImplHelper
          Object type of javax.jdo.spi.JDOImplHelper
static org.apache.bcel.generic.ObjectType OT_LongIdentity
          Object type of SingleFieldIdentity classes
static org.apache.bcel.generic.Type OT_ObjectArray
          Type of Object[]
static org.apache.bcel.generic.ObjectType OT_ObjectIdentity
           
static org.apache.bcel.generic.ObjectType OT_ObjectIdFieldConsumer
          Object type of javax.jdo.spi.PersistenceCapable.ObjectIdFieldConsumer
static org.apache.bcel.generic.ObjectType OT_ObjectIdFieldSupplier
          Object type of javax.jdo.spi.PersistenceCapable.ObjectIdFieldSupplier
static org.apache.bcel.generic.ObjectType OT_PersistenceCapable
          Object type of javax.jdo.spi.PersistenceCapable
static org.apache.bcel.generic.ObjectType OT_PersistenceManager
          Object type of javax.spi.PersistenceManager
static org.apache.bcel.generic.ObjectType OT_ShortIdentity
           
static org.apache.bcel.generic.ObjectType OT_StateManager
          Object type of javax.jdo.spi.StateManager
static org.apache.bcel.generic.ObjectType OT_StringIdentity
           
 
Fields inherited from class org.jpox.enhancer.AbstractClassEnhancer
className, clr, cmd, LOCALISER, update
 
Fields inherited from interface org.jpox.enhancer.ClassEnhancer
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_JdoIsDetachedInternal, MN_jdoLoadClass, MN_JdoManagingFieldCountMethod, MN_JdoParentManagingFieldCountMethod, MN_JdoPreSerialize, MN_JdoSuperClone, MN_PersistenceCapableSuperclassInitMethod
 
Constructor Summary
BCELClassEnhancer(org.jpox.metadata.ClassMetaData cmd, org.jpox.ClassLoaderResolver clr)
          Constructor.
 
Method Summary
 java.lang.String check()
          Method to check the class for obvious errors
 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
 void enhanceClassAfter()
           
 void enhanceClassBefore()
           
 void enhanceFields()
          Method to enhance the fields
 void enhanceFieldsAfter()
           
 void enhanceFieldsBefore()
           
protected  void enhanceGetter(BCELFieldMetaData fieldConfig)
           
 void enhanceMethod()
          Method to enhance the methods of the class.
 void enhanceMethodAfter()
           
 void enhanceMethodBefore()
           
protected  void enhanceOriginalMethod(org.apache.bcel.classfile.Method m)
           
protected  void enhanceOriginalMethods()
           
protected  void enhanceSetter(BCELFieldMetaData fieldConfig)
           
 void enhanceStaticInitializer()
           
 void enhanceStaticInitializerAfter()
           
 void enhanceStaticInitializerBefore()
           
protected  void field_addField(org.apache.bcel.generic.FieldGen fieldGen)
           
 byte[] getBytes()
          Access the class in byte array format
protected  void init_addFieldsList()
          append basic fields.
protected  void init_addMethodCallbackList()
          append basic method.
 void init()
          Initialisation.
protected  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 org.jpox.enhancer.AbstractClassEnhancer
getClassLoaderResolver, isPersistenceCapable, requiresDetachable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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
constant pool of enhancing class


classConfig

public final BCELClassMetaData classConfig
class config of enhancing class (BCEL version of "cmd"). TODO Use "cmd" and cast it


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


addSerialVersionUID

protected long addSerialVersionUID
serialVersionUID value


OT_Flag

public static final org.apache.bcel.generic.Type OT_Flag
Field type of jdoFlag


OT_ObjectArray

public static final org.apache.bcel.generic.Type OT_ObjectArray
Type of Object[]


OT_LongIdentity

public static final org.apache.bcel.generic.ObjectType OT_LongIdentity
Object type of SingleFieldIdentity classes


OT_StringIdentity

public static final org.apache.bcel.generic.ObjectType OT_StringIdentity

OT_ShortIdentity

public static final org.apache.bcel.generic.ObjectType OT_ShortIdentity

OT_IntIdentity

public static final org.apache.bcel.generic.ObjectType OT_IntIdentity

OT_CharIdentity

public static final org.apache.bcel.generic.ObjectType OT_CharIdentity

OT_ByteIdentity

public static final org.apache.bcel.generic.ObjectType OT_ByteIdentity

OT_ObjectIdentity

public static final org.apache.bcel.generic.ObjectType OT_ObjectIdentity

OT_PersistenceManager

public static final org.apache.bcel.generic.ObjectType OT_PersistenceManager
Object type of javax.spi.PersistenceManager


OT_ObjectIdFieldConsumer

public static final org.apache.bcel.generic.ObjectType OT_ObjectIdFieldConsumer
Object type of javax.jdo.spi.PersistenceCapable.ObjectIdFieldConsumer


OT_ObjectIdFieldSupplier

public static final org.apache.bcel.generic.ObjectType OT_ObjectIdFieldSupplier
Object type of javax.jdo.spi.PersistenceCapable.ObjectIdFieldSupplier


OT_BitSet

public static final org.apache.bcel.generic.ObjectType OT_BitSet
Object type of java.util.BitSet


OT_StateManager

public static final org.apache.bcel.generic.ObjectType OT_StateManager
Object type of javax.jdo.spi.StateManager


OT_PersistenceCapable

public static final org.apache.bcel.generic.ObjectType OT_PersistenceCapable
Object type of javax.jdo.spi.PersistenceCapable


OT_Detachable

public static final org.apache.bcel.generic.ObjectType OT_Detachable
Object type of javax.jdo.spi.Detachable


OT_JDOImplHelper

public static final org.apache.bcel.generic.ObjectType OT_JDOImplHelper
Object type of javax.jdo.spi.JDOImplHelper


OT_CLASS

public static final org.apache.bcel.generic.ObjectType OT_CLASS
Object type of java.lang.Class

Constructor Detail

BCELClassEnhancer

public BCELClassEnhancer(org.jpox.metadata.ClassMetaData cmd,
                         org.jpox.ClassLoaderResolver clr)
Constructor.

Parameters:
cmd - MetaData for the class to be enhanced
clr - ClassLoader resolver
Method Detail

init

public void init()
Initialisation.


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

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

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

Returns:
Return true if already enhanced class.

enhance

public void enhance()
Method to enhance the classes.


enhanceClass

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


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 void enhanceClassAfter()

enhanceClassBefore

public void enhanceClassBefore()

enhanceFields

public void enhanceFields()
Method to enhance the fields


field_addField

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

enhanceFieldsAfter

public void enhanceFieldsAfter()

enhanceFieldsBefore

public void enhanceFieldsBefore()

enhanceMethod

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


enhanceMethodAfter

public void enhanceMethodAfter()

enhanceMethodBefore

public void enhanceMethodBefore()

enhanceStaticInitializer

public void enhanceStaticInitializer()

staticInitializerAppend

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

enhanceStaticInitializerAfter

public void enhanceStaticInitializerAfter()

enhanceStaticInitializerBefore

public void enhanceStaticInitializerBefore()

enhanceOriginalMethod

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

enhanceOriginalMethods

protected void enhanceOriginalMethods()

enhanceSetter

protected void enhanceSetter(BCELFieldMetaData fieldConfig)

enhanceGetter

protected void enhanceGetter(BCELFieldMetaData fieldConfig)

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 - Thrown if an error occurs while verifying


Copyright © -2008 . All Rights Reserved.