EclipseLink 2.1.2, build 'v20101206-r8635' API Reference

org.eclipse.persistence.dynamic
Class DynamicClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by org.eclipse.persistence.dynamic.DynamicClassLoader

public class DynamicClassLoader
extends java.lang.ClassLoader

This custom ClassLoader provides support for dynamically generating classes within an EclipseLink application using byte codes created using a DynamicClassWriter. A DynamicClassLoader requires a parent or delegate class-loader which is provided to the constructor. This delegate class loader handles the lookup and storage of all created classes.

Author:
dclarke, mnorman
Since:
EclipseLink 1.2

Nested Class Summary
static class DynamicClassLoader.EnumInfo
           
 
Field Summary
protected  java.util.Map<java.lang.String,DynamicClassWriter> classWriters
          Map of DynamicClassWriter used to dynamically create a class in the findClass(String) call.
 DynamicClassWriter defaultWriter
          Default writer to use if one is not specified.
protected  java.util.Map<java.lang.String,DynamicClassLoader.EnumInfo> enumInfoRegistry
           
 
Constructor Summary
DynamicClassLoader(java.lang.ClassLoader delegate)
          Create a DynamicClassLoader providing the delegate loader and leaving the defaultWriter as DynamicClassWriter
DynamicClassLoader(java.lang.ClassLoader delegate, DynamicClassWriter writer)
          Create a DynamicClassLoader providing the delegate loader and a default DynamicClassWriter.
 
Method Summary
 void addClass(java.lang.String className)
          Register a class to be dynamically created using the default DynamicClassWriter.
 void addClass(java.lang.String className, java.lang.Class<?> parentClass)
          Register a class to be dynamically created using a copy of default DynamicClassWriter but specifying a different parent class.
 void addClass(java.lang.String className, DynamicClassWriter writer)
          Register a class to be dynamically created using the provided DynamicClassWriter.
 void addEnum(java.lang.String className, java.lang.Object... literalLabels)
           
protected  java.lang.Class<?> checkAssignable(java.lang.Class<?> clz)
           
 java.lang.Class<?> createDynamicClass(java.lang.String className)
          Create a new dynamic entity type for the specified name assuming the use of the default writer and its default parent class.
 java.lang.Class<?> createDynamicClass(java.lang.String className, java.lang.Class<?> parentClass)
          Create a new dynamic entity type for the specified name with the specified parent class.
 java.lang.Class<?> createDynamicClass(java.lang.String className, DynamicClassWriter writer)
          Create a dynamic class registering a writer and then forcing the provided class name to be loaded.
protected  java.lang.Class<?> findClass(java.lang.String className)
          Create a new dynamic class if a ClassWriter is registered for the provided className.
 DynamicClassWriter getClassWriter(java.lang.String className)
           
protected  java.util.Map<java.lang.String,DynamicClassWriter> getClassWriters()
           
 DynamicClassWriter getDefaultWriter()
           
static DynamicClassLoader lookup(Session session)
          Lookup the DynamicConversionManager for the given session.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classWriters

protected java.util.Map<java.lang.String,DynamicClassWriter> classWriters
Map of DynamicClassWriter used to dynamically create a class in the findClass(String) call. The application must register classes using addClass or createDynameClass prior to the findClass(String) being invoked.

The map of writers is maintained for the life of this DynamicClassLoader instance to ensure additional requests to create dynamic classes of the same name are properly verified. Duplicate requests for dynamic classes of the same name, same writer type, and the same parent class are permitted but different parent classes or different writer types are not.


enumInfoRegistry

protected java.util.Map<java.lang.String,DynamicClassLoader.EnumInfo> enumInfoRegistry

defaultWriter

public DynamicClassWriter defaultWriter
Default writer to use if one is not specified.

Constructor Detail

DynamicClassLoader

public DynamicClassLoader(java.lang.ClassLoader delegate)
Create a DynamicClassLoader providing the delegate loader and leaving the defaultWriter as DynamicClassWriter


DynamicClassLoader

public DynamicClassLoader(java.lang.ClassLoader delegate,
                          DynamicClassWriter writer)
Create a DynamicClassLoader providing the delegate loader and a default DynamicClassWriter.

Method Detail

getDefaultWriter

public DynamicClassWriter getDefaultWriter()

getClassWriters

protected java.util.Map<java.lang.String,DynamicClassWriter> getClassWriters()

getClassWriter

public DynamicClassWriter getClassWriter(java.lang.String className)

addEnum

public void addEnum(java.lang.String className,
                    java.lang.Object... literalLabels)

addClass

public void addClass(java.lang.String className)
Register a class to be dynamically created using the default DynamicClassWriter.

See Also:
addClass(String, DynamicClassWriter)

addClass

public void addClass(java.lang.String className,
                     java.lang.Class<?> parentClass)
Register a class to be dynamically created using a copy of default DynamicClassWriter but specifying a different parent class.

See Also:
addClass(String, DynamicClassWriter)

addClass

public void addClass(java.lang.String className,
                     DynamicClassWriter writer)
              throws DynamicException
Register a class to be dynamically created using the provided DynamicClassWriter. The registered writer is used when the findClass(String) method is called back on this loader from the ClassLoader.loadClass(String) call.

If a duplicate request is made for the same className and the writers are not compatible a DynamicException will be thrown. If the duplicate request contains a compatible writer then the second request is ignored as the class may already have been generated.

Throws:
DynamicException
See Also:
findClass(String)

createDynamicClass

public java.lang.Class<?> createDynamicClass(java.lang.String className,
                                             DynamicClassWriter writer)
Create a dynamic class registering a writer and then forcing the provided class name to be loaded.


checkAssignable

protected java.lang.Class<?> checkAssignable(java.lang.Class<?> clz)

createDynamicClass

public java.lang.Class<?> createDynamicClass(java.lang.String className)
Create a new dynamic entity type for the specified name assuming the use of the default writer and its default parent class.

See Also:
#creatDynamicClass(String, DynamicClassWriter)

createDynamicClass

public java.lang.Class<?> createDynamicClass(java.lang.String className,
                                             java.lang.Class<?> parentClass)
Create a new dynamic entity type for the specified name with the specified parent class.

See Also:
#creatDynamicClass(String, DynamicClassWriter)

findClass

protected java.lang.Class<?> findClass(java.lang.String className)
                                throws java.lang.ClassNotFoundException
Create a new dynamic class if a ClassWriter is registered for the provided className. This code is single threaded to ensure only one class is created for a given name and that the ClassWriter is removed afterwards.

Overrides:
findClass in class java.lang.ClassLoader
Throws:
java.lang.ClassNotFoundException

lookup

public static DynamicClassLoader lookup(Session session)
Lookup the DynamicConversionManager for the given session. If the existing ConversionManager is not an instance of DynamicConversionManager then create a new one and replace the existing one.

Parameters:
session -
Returns:

EclipseLink 2.1.2, build 'v20101206-r8635' API Reference