Class DynamicClassWriter
- java.lang.Object
-
- org.eclipse.persistence.dynamic.DynamicClassWriter
-
- All Implemented Interfaces:
EclipseLinkClassWriter
public class DynamicClassWriter extends java.lang.Object implements EclipseLinkClassWriter
Write the byte codes of a dynamic entity class. The class writer will create the byte codes for a dynamic class that subclasses any provided class replicating its constructors and writeReplace method (if one exists).The intent is to provide a common writer for dynamic JPA entities but also allow for subclasses of this to be used in more complex writing situations such as SDO and DBWS.
Instances of this class and any subclasses are maintained within the
DynamicClassLoader.getClassWriters()andDynamicClassLoader.defaultWriterfor the life of the class loader so it is important that no unnecessary state be maintained that may effect memory usage.- Author:
- dclarke, mnorman
- Since:
- EclipseLink 1.2
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringCLINITprotected static java.lang.StringDYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHESstatic int[]ICONSTprotected static java.lang.StringINITprotected java.lang.Class<?>parentClassprotected java.lang.StringparentClassNameName of parent class.
-
Constructor Summary
Constructors Constructor Description DynamicClassWriter()DynamicClassWriter(java.lang.Class<?> parentClass)DynamicClassWriter(java.lang.String parentClassName)Create using a loader and class name so that the parent class can be lazily loaded when the writer is used to generate a dynamic class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddFields(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw, java.lang.String parentClassType)Allow subclasses to add additional state to the dynamic entity.protected voidaddMethods(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw, java.lang.String parentClassType)Allow subclasses to add additional methods to the dynamic entity.protected DynamicClassWritercreateCopy(java.lang.Class<?> parentClass)Create a copy of thisDynamicClassWriterbut with a different parent class.protected byte[]createEnum(DynamicClassLoader.EnumInfo enumInfo)protected java.lang.String[]getInterfaces()Interfaces the dynamic entity class implements.java.lang.Class<?>getParentClass()java.lang.StringgetParentClassName()booleanisCompatible(EclipseLinkClassWriter writer)Verify that the provided writer is compatible with the current writer.java.lang.StringtoString()protected booleanverify(java.lang.Class<?> dynamicClass, java.lang.ClassLoader loader)Verify that the provided class meets the requirements of the writer.byte[]writeClass(DynamicClassLoader loader, java.lang.String className)
-
-
-
Field Detail
-
DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES
protected static final java.lang.String DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES
-
INIT
protected static final java.lang.String INIT
- See Also:
- Constant Field Values
-
CLINIT
protected static final java.lang.String CLINIT
- See Also:
- Constant Field Values
-
parentClass
protected java.lang.Class<?> parentClass
-
parentClassName
protected java.lang.String parentClassName
Name of parent class. This is used only when the parent class is not known at the time the dynamic class writer is registered. This is generally only required when loading from an XML mapping file where the order of class access is not known.
-
ICONST
public static int[] ICONST
-
-
Constructor Detail
-
DynamicClassWriter
public DynamicClassWriter()
-
DynamicClassWriter
public DynamicClassWriter(java.lang.Class<?> parentClass)
-
DynamicClassWriter
public DynamicClassWriter(java.lang.String parentClassName)
Create using a loader and class name so that the parent class can be lazily loaded when the writer is used to generate a dynamic class.The loader must not be null and the parentClassName must not be null and not an empty String. The parentClassName will be converted to a class using the provided loader lazily.
-
-
Method Detail
-
getParentClass
public java.lang.Class<?> getParentClass()
- Specified by:
getParentClassin interfaceEclipseLinkClassWriter
-
getParentClassName
public java.lang.String getParentClassName()
- Specified by:
getParentClassNamein interfaceEclipseLinkClassWriter
-
writeClass
public byte[] writeClass(DynamicClassLoader loader, java.lang.String className) throws java.lang.ClassNotFoundException
- Specified by:
writeClassin interfaceEclipseLinkClassWriter- Throws:
java.lang.ClassNotFoundException
-
addFields
protected void addFields(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw, java.lang.String parentClassType)Allow subclasses to add additional state to the dynamic entity.- Parameters:
cw-parentClassType-
-
addMethods
protected void addMethods(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw, java.lang.String parentClassType)Allow subclasses to add additional methods to the dynamic entity.- Parameters:
cw-parentClassType-
-
createEnum
protected byte[] createEnum(DynamicClassLoader.EnumInfo enumInfo)
-
verify
protected boolean verify(java.lang.Class<?> dynamicClass, java.lang.ClassLoader loader) throws java.lang.ClassNotFoundExceptionVerify that the provided class meets the requirements of the writer. In the case ofDynamicClassWriterthis will ensure that the class is a subclass of theparentClass- Parameters:
dynamicClass-- Throws:
java.lang.ClassNotFoundException
-
getInterfaces
protected java.lang.String[] getInterfaces()
Interfaces the dynamic entity class implements. By default this is none but in the case of SDO a concrete interface must be implemented. Subclasses should override this as required.- Returns:
- Interfaces implemented by Dynamic class. May be null
-
createCopy
protected DynamicClassWriter createCopy(java.lang.Class<?> parentClass)
Create a copy of thisDynamicClassWriterbut with a different parent class.
-
isCompatible
public boolean isCompatible(EclipseLinkClassWriter writer)
Verify that the provided writer is compatible with the current writer. Returning true means that the bytes that would be created using this writer are identical with what would come from the provided writer.Used in
DynamicClassLoader.addClass(String, EclipseLinkClassWriter)to verify if a duplicate request of the same className can proceed and return the same class that may already exist.- Specified by:
isCompatiblein interfaceEclipseLinkClassWriter
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-