org.datanucleus.enhancer.asm
Class ASMClassEnhancer

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

public class ASMClassEnhancer
extends AbstractClassEnhancer

Class enhancer using ASM (http://asm.objectweb.org). Assumes that the version of ASM is 3.0 or above. ASM operates using a SAXParser-like "visitor-pattern". We utilise this as follows :-


Nested Class Summary
static class ASMClassEnhancer.MyClassVisitor
          Convenience class to look up the class name for a file.
 
Field Summary
protected  java.lang.String asmClassName
          ASM Class name for this class (replace .
protected  byte[] classBytes
          Bytes of the class (after enhancing).
protected  java.lang.String classDescriptor
          Class descriptor for this class.
protected  java.lang.Class cls
          Class that is being enhanced.
protected  byte[] inputBytes
          Bytes of the input class (only when enhancing generated classes with no class file).
protected  java.lang.String inputResourceName
          Resource name of the input class (only when the class exists in a class file).
protected static org.datanucleus.util.Localiser LOCALISER_CORE
           
protected  byte[] pkClassBytes
          Bytes for any auto-generated PK class (if generated during enhancement).
 
Fields inherited from class org.datanucleus.enhancer.AbstractClassEnhancer
className, clr, cmd, fieldsToAdd, initialised, LOCALISER, metaDataMgr, methodsToAdd, options, update
 
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
ASMClassEnhancer(org.datanucleus.metadata.ClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr, org.datanucleus.metadata.MetaDataManager mmgr)
          Constructor for an enhancer for the class.
ASMClassEnhancer(org.datanucleus.metadata.ClassMetaData cmd, org.datanucleus.ClassLoaderResolver clr, org.datanucleus.metadata.MetaDataManager mmgr, byte[] classBytes)
          Constructor for an enhancer to enhance a class defined by the provided bytes.
 
Method Summary
protected  boolean checkClassIsEnhanced(boolean logErrors)
          Convenience method to return if a class is enhanced.
 boolean enhance()
          Method to enhance a classes definition.
 java.lang.String getASMClassName()
          Accessor for the ASM class name
 byte[] getClassBytes()
          Accessor for the class bytes.
 java.lang.String getClassDescriptor()
          Accessor for the class descriptor for the class being enhanced
 java.lang.Class getClassEnhanced()
          Accessor for the class being enhanced.
static java.lang.String getClassNameForFileName(java.lang.String filename)
          Convenience accessor for the class name that is stored in a particular class.
 byte[] getPrimaryKeyClassBytes()
          Accessor for the primary-key class bytes (if generating a PK).
protected  void initialiseFieldsList()
          Method to initialise the list of fields to add.
protected  void initialiseMethodsList()
          Method to initialise the list of methods to add.
 boolean validate()
          Validate whether the class is enhanced.
 
Methods inherited from class org.datanucleus.enhancer.AbstractClassEnhancer
getClassLoaderResolver, getClassMetaData, getFieldsList, getMetaDataManager, getMethodsList, hasOption, initialise, isPersistenceCapable, requiresDetachable, save, setOptions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER_CORE

protected static org.datanucleus.util.Localiser LOCALISER_CORE

inputResourceName

protected java.lang.String inputResourceName
Resource name of the input class (only when the class exists in a class file).


inputBytes

protected byte[] inputBytes
Bytes of the input class (only when enhancing generated classes with no class file).


cls

protected final java.lang.Class cls
Class that is being enhanced.


classBytes

protected byte[] classBytes
Bytes of the class (after enhancing).


pkClassBytes

protected byte[] pkClassBytes
Bytes for any auto-generated PK class (if generated during enhancement).


asmClassName

protected java.lang.String asmClassName
ASM Class name for this class (replace . with /).


classDescriptor

protected java.lang.String classDescriptor
Class descriptor for this class.

Constructor Detail

ASMClassEnhancer

public ASMClassEnhancer(org.datanucleus.metadata.ClassMetaData cmd,
                        org.datanucleus.ClassLoaderResolver clr,
                        org.datanucleus.metadata.MetaDataManager mmgr)
Constructor for an enhancer for the class. The class is assumed to be in the CLASSPATH.

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

ASMClassEnhancer

public ASMClassEnhancer(org.datanucleus.metadata.ClassMetaData cmd,
                        org.datanucleus.ClassLoaderResolver clr,
                        org.datanucleus.metadata.MetaDataManager mmgr,
                        byte[] classBytes)
Constructor for an enhancer to enhance a class defined by the provided bytes.

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

getClassNameForFileName

public static java.lang.String getClassNameForFileName(java.lang.String filename)
Convenience accessor for the class name that is stored in a particular class.

Parameters:
filename - Name of the file
Returns:
The class name

getClassEnhanced

public java.lang.Class getClassEnhanced()
Accessor for the class being enhanced.

Returns:
Class being enhanced

getASMClassName

public java.lang.String getASMClassName()
Accessor for the ASM class name

Returns:
ASM class name

getClassDescriptor

public java.lang.String getClassDescriptor()
Accessor for the class descriptor for the class being enhanced

Returns:
class descriptor

initialiseMethodsList

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

Specified by:
initialiseMethodsList in class AbstractClassEnhancer

initialiseFieldsList

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

Specified by:
initialiseFieldsList in class AbstractClassEnhancer

enhance

public boolean enhance()
Method to enhance a classes definition.

Returns:
Whether it was enhanced with no errors

getClassBytes

public byte[] getClassBytes()
Accessor for the class bytes. Only has relevance to be called after enhance().

Returns:
The class bytes

getPrimaryKeyClassBytes

public byte[] getPrimaryKeyClassBytes()
Accessor for the primary-key class bytes (if generating a PK). Only has relevance to be called after enhance().

Returns:
The primary-key class bytes

validate

public boolean validate()
Description copied from interface: ClassEnhancer
Validate whether the class is enhanced.

Returns:
Return true if already enhanced class.

checkClassIsEnhanced

protected boolean checkClassIsEnhanced(boolean logErrors)
Convenience method to return if a class is enhanced.

Parameters:
logErrors - Whether to log any errors (missing methods etc) as errors (otherwise info/debug)
Returns:
Whether the class is enhanced


Copyright © 2011. All Rights Reserved.