EclipseLink 2.1.2, build 'v20101206-r8635' API Reference

org.eclipse.persistence.dynamic
Class DynamicClassWriter

java.lang.Object
  extended by org.eclipse.persistence.dynamic.DynamicClassWriter

public class DynamicClassWriter
extends java.lang.Object

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
protected static java.lang.String INIT
           
protected  java.lang.Class<?> parentClass
           
protected  java.lang.String parentClassName
          Name of parent class.
 
Constructor Summary
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
protected  void addConstructor(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw, java.lang.reflect.Constructor<?> constructor)
          Add a new constructor based invoking the provided constructor from the parent class.
protected  void addConstructors(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw)
          Adds all constructors calling those available in the parent class.
protected  void addFields(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw)
          Provided to allow subclasses to add their own fields.
protected  void addMethods(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw)
          Provided to allow subclasses to add their own methods.
protected  void addWriteReplace(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw)
          Add a writeReplace method if one is found in the parentClass.
protected  DynamicClassWriter createCopy(java.lang.Class<?> parentClass)
          Create a copy of this DynamicClassWriter but 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.String getParentClassName()
           
protected  boolean isCompatible(DynamicClassWriter writer)
          Verify that the provided writer is compatible with the current writer.
 java.lang.String toString()
           
 byte[] writeClass(DynamicClassLoader loader, java.lang.String className)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

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.


INIT

protected static final java.lang.String INIT
See Also:
Constant Field Values
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.

See Also:
getParentClass(), DynamicException.illegalDynamicClassWriter(DynamicClassLoader, String)
Method Detail

getParentClass

public java.lang.Class<?> getParentClass()

getParentClassName

public java.lang.String getParentClassName()

writeClass

public byte[] writeClass(DynamicClassLoader loader,
                         java.lang.String className)
                  throws java.lang.ClassNotFoundException
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

addConstructors

protected void addConstructors(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw)
Adds all constructors calling those available in the parent class.

See Also:
addConstructor(ClassWriter, Constructor)

addConstructor

protected void addConstructor(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw,
                              java.lang.reflect.Constructor<?> constructor)
Add a new constructor based invoking the provided constructor from the parent class. This method is called by #addConstructors(ClassWriter, Class) for each constructor available in the parent class.


addWriteReplace

protected void addWriteReplace(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw)
Add a writeReplace method if one is found in the parentClass. The created writeReplace method will call the parent class version. This is provided to support Serializable which requires that the writeReplace method exist as a method on the Serializable class and not provided through inheritance.


createEnum

protected byte[] createEnum(DynamicClassLoader.EnumInfo enumInfo)

addFields

protected void addFields(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw)
Provided to allow subclasses to add their own fields.


addMethods

protected void addMethods(org.eclipse.persistence.internal.libraries.asm.ClassWriter cw)
Provided to allow subclasses to add their own methods. This must add additional methods needed to implement any interfaces returned from getInterfaces()

Parameters:
loader -

createCopy

protected DynamicClassWriter createCopy(java.lang.Class<?> parentClass)
Create a copy of this DynamicClassWriter but with a different parent class.

See Also:
DynamicClassLoader.addClass(String, Class)

isCompatible

protected boolean isCompatible(DynamicClassWriter 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, DynamicClassWriter) to verify if a duplicate request of the same className can proceed and return the same class that may already exist.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

EclipseLink 2.1.2, build 'v20101206-r8635' API Reference