Top Description Fields Constructors Methods
org.eclipse.persistence.dynamic

public Class DynamicClassWriter

extends Object
implements EclipseLinkClassWriter
Class Inheritance
All Implemented Interfaces
org.eclipse.persistence.dynamic.EclipseLinkClassWriter
Static Imports
org.eclipse.persistence.internal.dynamic.DynamicPropertiesManager.PROPERTIES_MANAGER_FIELD

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() and DynamicClassLoader#defaultWriter for 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

Modifier and TypeField and Description
protected static final String
protected static final String
public static int[]
protected static final String
private List<String>
protected Class<?>
protected String
parentClassName

Name of parent class.

Constructor Summary

AccessConstructor and Description
public
public
DynamicClassWriter(Class<?> parentClass)

public
DynamicClassWriter(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

Modifier and TypeMethod and Description
protected void
addFields(ClassWriter cw, String parentClassType)

Allow subclasses to add additional state to the dynamic entity.

protected void
addInterface(String
additional interface
intf
)

Allow subclasses to add additional interfaces to the dynamic entity.

protected void
addMethods(ClassWriter cw, String parentClassType)

Allow subclasses to add additional methods to the dynamic entity.

protected DynamicClassWriter
createCopy(Class<?> parentClass)

Create a copy of this DynamicClassWriter but with a different parent class.

protected byte[]
protected String[]

Returns:

Interfaces implemented by Dynamic class. May be null
getInterfaces
()

Interfaces the dynamic entity class implements.

public Class<?>
private Class<?>
getParentClass(ClassLoader loader)

Return the parentClass converting the parentClassName using the provided loader if required.

public String
public boolean
isCompatible(EclipseLinkClassWriter writer)

Implements org.eclipse.persistence.dynamic.EclipseLinkClassWriter.isCompatible.

Verify that the provided writer is compatible with the current writer.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
protected boolean
verify(Class<?> dynamicClass, ClassLoader loader)

Verify that the provided class meets the requirements of the writer.

public byte[]
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

CLINITback to summary
protected static final String CLINIT
DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHESback to summary
protected static final String DYNAMIC_PROPERTIES_MANAGER_CLASSNAME_SLASHES
ICONSTback to summary
public static int[] ICONST
INITback to summary
protected static final String INIT
interfacesback to summary
private List<String> interfaces
parentClassback to summary
protected Class<?> parentClass
parentClassNameback to summary
protected 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.

Constructor Detail

DynamicClassWriterback to summary
public DynamicClassWriter()
DynamicClassWriterback to summary
public DynamicClassWriter(Class<?> parentClass)
DynamicClassWriterback to summary
public DynamicClassWriter(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.

See Also
getParentClass(), DynamicException#illegalDynamicClassWriter(DynamicClassLoader, String)

Method Detail

addFieldsback to summary
protected void addFields(ClassWriter cw, String parentClassType)

Allow subclasses to add additional state to the dynamic entity.

addInterfaceback to summary
protected void addInterface(String intf)

Allow subclasses to add additional interfaces to the dynamic entity.

Parameters
intf:String

additional interface

addMethodsback to summary
protected void addMethods(ClassWriter cw, String parentClassType)

Allow subclasses to add additional methods to the dynamic entity.

createCopyback to summary
protected DynamicClassWriter createCopy(Class<?> parentClass)

Create a copy of this DynamicClassWriter but with a different parent class.

See Also
DynamicClassLoader#addClass(String, Class)
createEnumback to summary
protected byte[] createEnum(DynamicClassLoader.EnumInfo enumInfo)
getInterfacesback to summary
protected 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:String[]

Interfaces implemented by Dynamic class. May be null

getParentClassback to summary
public Class<?> getParentClass()

Implements org.eclipse.persistence.dynamic.EclipseLinkClassWriter.getParentClass.

Annotations
@Override
getParentClassback to summary
private Class<?> getParentClass(ClassLoader loader) throws ClassNotFoundException

Return the parentClass converting the parentClassName using the provided loader if required.

Exceptions
ClassNotFoundException:
if the parentClass is not available.
getParentClassNameback to summary
public String getParentClassName()

Implements org.eclipse.persistence.dynamic.EclipseLinkClassWriter.getParentClassName.

Annotations
@Override
isCompatibleback to summary
public boolean isCompatible(EclipseLinkClassWriter writer)

Implements org.eclipse.persistence.dynamic.EclipseLinkClassWriter.isCompatible.

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.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
verifyback to summary
protected boolean verify(Class<?> dynamicClass, ClassLoader loader) throws ClassNotFoundException

Verify that the provided class meets the requirements of the writer. In the case of DynamicClassWriter this will ensure that the class is a subclass of the parentClass

writeClassback to summary
public byte[] writeClass(DynamicClassLoader loader, String className) throws ClassNotFoundException

Implements org.eclipse.persistence.dynamic.EclipseLinkClassWriter.writeClass.

Annotations
@Override