public class ClassEnhancerImpl extends Object implements ClassEnhancer
Modifier and Type | Class and Description |
---|---|
static class |
ClassEnhancerImpl.MyClassVisitor
Convenience class to look up the class name for a file.
|
Modifier and Type | Field and Description |
---|---|
protected String |
asmClassName
ASM Class name for this class (replace .
|
protected byte[] |
classBytes
Bytes of the class (after enhancing).
|
protected String |
classDescriptor
Class descriptor for this class.
|
String |
className
Class name of the class being enhanced
|
protected ClassLoaderResolver |
clr
Class Loader Resolver to use for any loading issues.
|
protected Class |
cls
Class that is being enhanced.
|
protected ClassMetaData |
cmd
MetaData for the class being enhanced.
|
protected List<ClassField> |
fieldsToAdd
List of fields to be added to the class.
|
protected boolean |
initialised
Flag for whether we are initialised.
|
protected byte[] |
inputBytes
Bytes of the input class (only when enhancing generated classes with no class file).
|
protected String |
inputResourceName
Resource name of the input class (only when the class exists in a class file).
|
protected MetaDataManager |
metaDataMgr
MetaData Manager to use.
|
protected List<ClassMethod> |
methodsToAdd
List of methods to be added to the class.
|
protected EnhancementNamer |
namer |
protected Collection<String> |
options
Options for enhancement.
|
protected byte[] |
pkClassBytes
Bytes for any auto-generated PK class (if generated during enhancement).
|
protected boolean |
update
Flag specifying if the class needs updating.
|
ASM_API_VERSION, OPTION_GENERATE_DEFAULT_CONSTRUCTOR, OPTION_GENERATE_DETACH_LISTENER, OPTION_GENERATE_PK
Constructor and Description |
---|
ClassEnhancerImpl(ClassMetaData cmd,
ClassLoaderResolver clr,
MetaDataManager mmgr,
EnhancementNamer namer)
Constructor for an enhancer for the class.
|
ClassEnhancerImpl(ClassMetaData cmd,
ClassLoaderResolver clr,
MetaDataManager mmgr,
EnhancementNamer namer,
byte[] classBytes)
Constructor for an enhancer to enhance a class defined by the provided bytes.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkClassIsEnhanced(boolean logErrors)
Convenience method to return if a class is enhanced.
|
boolean |
enhance()
Method to enhance a classes definition.
|
String |
getASMClassName()
Accessor for the ASM class name
|
Class |
getClassBeingEnhanced()
Accessor for the class being enhanced.
|
byte[] |
getClassBytes()
Accessor for the class bytes.
|
String |
getClassDescriptor()
Accessor for the class descriptor for the class being enhanced
|
ClassLoaderResolver |
getClassLoaderResolver()
Accessor for the ClassLoaderResolver
|
ClassMetaData |
getClassMetaData()
Accessor for the ClassMetaData for the class.
|
String |
getClassName()
Accessor for the name of the class being enhanced.
|
static String |
getClassNameForFileName(String filename)
Convenience accessor for the class name that is stored in a particular class.
|
List<ClassField> |
getFieldsList()
Accessor for the fields required.
|
MetaDataManager |
getMetaDataManager()
Accessor for the MetaData manager in use.
|
List<ClassMethod> |
getMethodsList()
Accessor for the methods required.
|
EnhancementNamer |
getNamer() |
byte[] |
getPrimaryKeyClassBytes()
Accessor for the primary-key class bytes (if generating a PK).
|
boolean |
hasOption(String name)
Accessor for whether a particular option is enabled.
|
protected void |
initialise()
Initialisation of the information for enhancing this class.
|
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 |
isPersistable(String className)
Check if the class is Persistable 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(String directoryName)
Method to save the class definition bytecode into a class file.
|
void |
setNamer(EnhancementNamer namer) |
void |
setOptions(Collection<String> options)
Method to set the options controlling the enhancement.
|
boolean |
validate()
Validate whether the class is enhanced.
|
protected final ClassLoaderResolver clr
protected final MetaDataManager metaDataMgr
protected final ClassMetaData cmd
public final String className
protected boolean update
protected List<ClassField> fieldsToAdd
protected List<ClassMethod> methodsToAdd
protected boolean initialised
protected Collection<String> options
protected String inputResourceName
protected byte[] inputBytes
protected final Class cls
protected byte[] classBytes
protected byte[] pkClassBytes
protected String asmClassName
protected String classDescriptor
protected EnhancementNamer namer
public ClassEnhancerImpl(ClassMetaData cmd, ClassLoaderResolver clr, MetaDataManager mmgr, EnhancementNamer namer)
cmd
- MetaData for the class to be enhancedclr
- ClassLoader resolvermmgr
- MetaData managernamer
- The namerpublic ClassEnhancerImpl(ClassMetaData cmd, ClassLoaderResolver clr, MetaDataManager mmgr, EnhancementNamer namer, byte[] classBytes)
cmd
- MetaData for the class to be enhancedclr
- ClassLoader resolvermmgr
- MetaData managernamer
- The namerclassBytes
- Bytes of the class to enhanceprotected void initialise()
public String getClassName()
ClassEnhancer
getClassName
in interface ClassEnhancer
public List<ClassMethod> getMethodsList()
getMethodsList
in interface ClassEnhancer
public List<ClassField> getFieldsList()
getFieldsList
in interface ClassEnhancer
public ClassLoaderResolver getClassLoaderResolver()
getClassLoaderResolver
in interface ClassEnhancer
public MetaDataManager getMetaDataManager()
ClassEnhancer
getMetaDataManager
in interface ClassEnhancer
public ClassMetaData getClassMetaData()
ClassEnhancer
getClassMetaData
in interface ClassEnhancer
protected boolean requiresDetachable()
public boolean isPersistable(String className)
isPersistable
in interface ClassEnhancer
className
- the class namepublic void setOptions(Collection<String> options)
ClassEnhancer
setOptions
in interface ClassEnhancer
options
- The optionspublic boolean hasOption(String name)
ClassEnhancer
hasOption
in interface ClassEnhancer
name
- Name of the optionpublic void save(String directoryName) throws IOException
save
in interface ClassEnhancer
directoryName
- Name of a directory (or null to overwrite the class)IOException
- If an I/O error occurs in the write.public void setNamer(EnhancementNamer namer)
setNamer
in interface ClassEnhancer
public static String getClassNameForFileName(String filename)
filename
- Name of the filepublic Class getClassBeingEnhanced()
getClassBeingEnhanced
in interface ClassEnhancer
public String getASMClassName()
getASMClassName
in interface ClassEnhancer
public String getClassDescriptor()
getClassDescriptor
in interface ClassEnhancer
protected void initialiseMethodsList()
protected void initialiseFieldsList()
public boolean enhance()
enhance
in interface ClassEnhancer
public byte[] getClassBytes()
getClassBytes
in interface ClassEnhancer
public byte[] getPrimaryKeyClassBytes()
getPrimaryKeyClassBytes
in interface ClassEnhancer
public boolean validate()
ClassEnhancer
validate
in interface ClassEnhancer
protected boolean checkClassIsEnhanced(boolean logErrors)
logErrors
- Whether to log any errors (missing methods etc) as errors (otherwise info/debug)public EnhancementNamer getNamer()
getNamer
in interface ClassEnhancer
Copyright © 2019. All rights reserved.