org.datanucleus.enhancer
Class AbstractClassEnhancer

java.lang.Object
  extended by org.datanucleus.enhancer.AbstractClassEnhancer
All Implemented Interfaces:
ClassEnhancer
Direct Known Subclasses:
ASMClassEnhancer

public abstract class AbstractClassEnhancer
extends java.lang.Object
implements ClassEnhancer

Abstract representation of a class enhancer. To be extended by implementing enhancers.


Field Summary
 java.lang.String className
          Class name of the class being enhanced
protected  org.datanucleus.ClassLoaderResolver clr
          Class Loader Resolver to use for any loading issues.
protected  org.datanucleus.metadata.ClassMetaData cmd
          MetaData for the class being enhanced.
protected  java.util.List<ClassField> fieldsToAdd
          List of fields to be added to the class.
protected  boolean initialised
          Flag for whether we are initialised.
protected static org.datanucleus.util.Localiser LOCALISER
          Message resource
protected  org.datanucleus.metadata.MetaDataManager metaDataMgr
          MetaData Manager to use.
protected  java.util.List<ClassMethod> methodsToAdd
          List of methods to be added to the class.
protected  java.util.Collection<java.lang.String> options
          Options for enhancement.
protected  boolean update
          Flag specifying if the class needs updating.
 
Fields inherited from interface org.datanucleus.enhancer.ClassEnhancer
CN_BitSet, CN_ByteIdentity, CN_CharIdentity, CN_Class, CN_ClassCastException, CN_Detachable, 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_JdoInheritedFieldCount, FN_PersistenceCapableSuperclass, FN_serialVersionUID, FN_StateManager, MN_FieldFlagsInitMethod, MN_FieldNamesInitMethod, MN_FieldTypesInitMethod, MN_JdoCopyField, MN_JdoCopyFields, MN_JdoCopyKeyFieldsFromObjectId, MN_JdoCopyKeyFieldsToObjectId, MN_JdoGetInheritedFieldCount, MN_JdoGetManagedFieldCount, MN_JdoGetObjectId, MN_JdoGetPersistenceManager, MN_JdoGetTransactionalObjectId, MN_JdoGetVersion, MN_JdoIsDeleted, MN_JdoIsDetached, MN_JdoIsDetachedInternal, MN_JdoIsDirty, MN_JdoIsNew, MN_JdoIsPersistent, MN_JdoIsTransactional, MN_jdoLoadClass, MN_JdoMakeDirty, MN_JdoMakeDirtyDetached, MN_JdoNewInstance, MN_JdoNewObjectIdInstance, MN_JdoPersistenceCapableSuperclassInit, MN_JdoPreSerialize, MN_JdoProvideField, MN_JdoProvideFields, MN_JdoReplaceDetachedState, MN_JdoReplaceField, MN_JdoReplaceFields, MN_JdoReplaceFlags, MN_JdoReplaceStateManager, MN_JdoSuperClone, OPTION_GENERATE_DEFAULT_CONSTRUCTOR, OPTION_GENERATE_PK
 
Constructor Summary
AbstractClassEnhancer(org.datanucleus.metadata.ClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr, org.datanucleus.metadata.MetaDataManager mmgr)
          Constructor.
 
Method Summary
 org.datanucleus.ClassLoaderResolver getClassLoaderResolver()
          Accessor for the ClassLoaderResolver
 org.datanucleus.metadata.ClassMetaData getClassMetaData()
          Accessor for the ClassMetaData for the class.
 java.util.List<ClassField> getFieldsList()
          Accessor for the fields required.
 org.datanucleus.metadata.MetaDataManager getMetaDataManager()
          Accessor for the MetaData manager in use.
 java.util.List<ClassMethod> getMethodsList()
          Accessor for the methods required.
 boolean hasOption(java.lang.String name)
          Accessor for whether a particular option is enabled.
protected  void initialise()
          Initialisation of the information for enhancing this class.
protected abstract  void initialiseFieldsList()
          Method to initialise the list of fields to add.
protected abstract  void initialiseMethodsList()
          Method to initialise the list of methods to add.
 boolean isPersistenceCapable(java.lang.String className)
          Check if the class is PersistenceCapable or is going to be enhanced based on the metadata
protected  boolean requiresDetachable()
          Convenience method for whether this class needs to implement Detachable
 void save(java.lang.String directoryName)
          Method to save the class definition bytecode into a class file.
 void setOptions(java.util.Collection<java.lang.String> options)
          Method to set the options controlling the enhancement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.datanucleus.enhancer.ClassEnhancer
enhance, getClassBytes, getPrimaryKeyClassBytes, validate
 

Field Detail

LOCALISER

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


clr

protected final org.datanucleus.ClassLoaderResolver clr
Class Loader Resolver to use for any loading issues.


metaDataMgr

protected final org.datanucleus.metadata.MetaDataManager metaDataMgr
MetaData Manager to use.


cmd

protected final org.datanucleus.metadata.ClassMetaData cmd
MetaData for the class being enhanced.


className

public final java.lang.String className
Class name of the class being enhanced


update

protected boolean update
Flag specifying if the class needs updating.


fieldsToAdd

protected java.util.List<ClassField> fieldsToAdd
List of fields to be added to the class.


methodsToAdd

protected java.util.List<ClassMethod> methodsToAdd
List of methods to be added to the class.


initialised

protected boolean initialised
Flag for whether we are initialised.


options

protected java.util.Collection<java.lang.String> options
Options for enhancement.

Constructor Detail

AbstractClassEnhancer

public AbstractClassEnhancer(org.datanucleus.metadata.ClassMetaData cmd,
                             org.datanucleus.ClassLoaderResolver clr,
                             org.datanucleus.metadata.MetaDataManager mmgr)
Constructor.

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

initialise

protected void initialise()
Initialisation of the information for enhancing this class.


initialiseMethodsList

protected abstract void initialiseMethodsList()
Method to initialise the list of methods to add.


initialiseFieldsList

protected abstract void initialiseFieldsList()
Method to initialise the list of fields to add.


getMethodsList

public java.util.List<ClassMethod> getMethodsList()
Accessor for the methods required.

Returns:
List of methods required for enhancement

getFieldsList

public java.util.List<ClassField> getFieldsList()
Accessor for the fields required.

Returns:
List of fields required for enhancement

getClassLoaderResolver

public org.datanucleus.ClassLoaderResolver getClassLoaderResolver()
Accessor for the ClassLoaderResolver

Specified by:
getClassLoaderResolver in interface ClassEnhancer
Returns:
ClassLoader resolver

getMetaDataManager

public org.datanucleus.metadata.MetaDataManager getMetaDataManager()
Description copied from interface: ClassEnhancer
Accessor for the MetaData manager in use.

Specified by:
getMetaDataManager in interface ClassEnhancer
Returns:
MetaData manager

getClassMetaData

public org.datanucleus.metadata.ClassMetaData getClassMetaData()
Description copied from interface: ClassEnhancer
Accessor for the ClassMetaData for the class.

Specified by:
getClassMetaData in interface ClassEnhancer
Returns:
MetaData for the class

requiresDetachable

protected boolean requiresDetachable()
Convenience method for whether this class needs to implement Detachable

Returns:
Whether we need to implement the Detachable interface

isPersistenceCapable

public boolean isPersistenceCapable(java.lang.String className)
Check if the class is PersistenceCapable or is going to be enhanced based on the metadata

Parameters:
className - the class name
Returns:
true if PersistenceCapable

setOptions

public void setOptions(java.util.Collection<java.lang.String> options)
Description copied from interface: ClassEnhancer
Method to set the options controlling the enhancement.

Specified by:
setOptions in interface ClassEnhancer
Parameters:
options - The options

hasOption

public boolean hasOption(java.lang.String name)
Description copied from interface: ClassEnhancer
Accessor for whether a particular option is enabled.

Specified by:
hasOption in interface ClassEnhancer
Parameters:
name - Name of the option
Returns:
Whether it has this option

save

public void save(java.lang.String directoryName)
          throws java.io.IOException
Method to save the class definition bytecode into a class file. If directoryName is specified it will be written to $directoryName/className.class else will overwrite the existing class.

Specified by:
save in interface ClassEnhancer
Parameters:
directoryName - Name of a directory (or null to overwrite the class)
Throws:
java.io.IOException - If an I/O error occurs in the write.


Copyright © 2011. All Rights Reserved.