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

public Class DynamicClassLoader

extends ClassLoader
Class Inheritance
Imports
java.util.ArrayList, .HashMap, .List, .Map, org.eclipse.persistence.config.SystemProperties, org.eclipse.persistence.exceptions.DynamicException, org.eclipse.persistence.internal.helper.ConversionManager, .Helper, org.eclipse.persistence.internal.security.PrivilegedAccessHelper, org.eclipse.persistence.sessions.Session

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
protected Map<String, EclipseLinkClassWriter>
classWriters

Map of DynamicClassWriter used to dynamically create a class in the findClass(String) call.

public DynamicClassWriter
defaultWriter

Default writer to use if one is not specified.

protected Map<String, DynamicClassLoader.EnumInfo>

Constructor Summary

AccessConstructor and Description
public
DynamicClassLoader(ClassLoader delegate)

Create a DynamicClassLoader providing the delegate loader and leaving the defaultWriter as DynamicClassWriter

public
DynamicClassLoader(ClassLoader delegate, DynamicClassWriter writer)

Create a DynamicClassLoader providing the delegate loader and a default DynamicClassWriter.

Method Summary

Modifier and TypeMethod and Description
public void
addClass(String className)

Register a class to be dynamically created using the default DynamicClassWriter.

public void
addClass(String className, Class<?> parentClass)

Register a class to be dynamically created using a copy of default DynamicClassWriter but specifying a different parent class.

public void
addClass(String className, EclipseLinkClassWriter writer)

Register a class to be dynamically created using the provided DynamicClassWriter.

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

protected Class<?>
public void
createDynamicAdapter(String className)

Create an adapter for given className

public Class<?>
createDynamicClass(String className, DynamicClassWriter writer)

Create a dynamic class registering a writer and then forcing the provided class name to be loaded.

public Class<?>
createDynamicClass(String className)

Create a new dynamic entity type for the specified name assuming the use of the default writer and its default parent class.

public Class<?>
createDynamicClass(String className, Class<?> parentClass)

Create a new dynamic entity type for the specified name with the specified parent class.

public void
createDynamicCollectionAdapter(String className)

Create a collection adapter for given className

public void
createDynamicReferenceAdapter(String className)

Create a reference for given className

protected Class<?>
defineDynamicClass(String name, byte[] b)

Converts an array of bytes into an instance of class Class.

protected Class<?>
findClass(String
The binary name of the class
className
)

Overrides java.lang.ClassLoader.findClass.

Create a new dynamic class if a ClassWriter is registered for the provided className.
public EclipseLinkClassWriter
protected Map<String, EclipseLinkClassWriter>
public DynamicClassWriter
public static DynamicClassLoader
lookup(Session session)

Lookup the DynamicConversionManager for the given session.

Inherited from java.lang.ClassLoader:
clearAssertionStatusdefineClassdefineClassdefineClassdefineClassdefinePackagefindClassfindLibraryfindLoadedClassfindResourcefindResourcefindResourcesfindSystemClassgetClassLoadingLockgetDefinedPackagegetDefinedPackagesgetNamegetPackagegetPackagesgetParentgetPlatformClassLoadergetResourcegetResourceAsStreamgetResourcesgetSystemClassLoadergetSystemResourcegetSystemResourceAsStreamgetSystemResourcesgetUnnamedModuleisRegisteredAsParallelCapableloadClassloadClassregisterAsParallelCapableresolveClassresourcessetClassAssertionStatussetDefaultAssertionStatussetPackageAssertionStatussetSigners

Field Detail

classWritersback to summary
protected Map<String, EclipseLinkClassWriter> 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.

defaultWriterback to summary
public DynamicClassWriter defaultWriter

Default writer to use if one is not specified.

enumInfoRegistryback to summary
protected Map<String, DynamicClassLoader.EnumInfo> enumInfoRegistry

Constructor Detail

DynamicClassLoaderback to summary
public DynamicClassLoader(ClassLoader delegate)

Create a DynamicClassLoader providing the delegate loader and leaving the defaultWriter as DynamicClassWriter

DynamicClassLoaderback to summary
public DynamicClassLoader(ClassLoader delegate, DynamicClassWriter writer)

Create a DynamicClassLoader providing the delegate loader and a default DynamicClassWriter.

Method Detail

addClassback to summary
public void addClass(String className)

Register a class to be dynamically created using the default DynamicClassWriter.

See Also
addClass(String, EclipseLinkClassWriter)
addClassback to summary
public void addClass(String className, 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, EclipseLinkClassWriter)
addClassback to summary
public void addClass(String className, EclipseLinkClassWriter 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 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.

See Also
findClass(String)
addEnumback to summary
public void addEnum(String className, Object... literalLabels)
checkAssignableback to summary
protected Class<?> checkAssignable(Class<?> clz)
createDynamicAdapterback to summary
public void createDynamicAdapter(String className)

Create an adapter for given className

createDynamicClassback to summary
public Class<?> createDynamicClass(String className, DynamicClassWriter writer)

Create a dynamic class registering a writer and then forcing the provided class name to be loaded.

createDynamicClassback to summary
public Class<?> createDynamicClass(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
createDynamicClass(String, DynamicClassWriter)
createDynamicClassback to summary
public Class<?> createDynamicClass(String className, Class<?> parentClass)

Create a new dynamic entity type for the specified name with the specified parent class.

See Also
createDynamicClass(String, DynamicClassWriter)
createDynamicCollectionAdapterback to summary
public void createDynamicCollectionAdapter(String className)

Create a collection adapter for given className

createDynamicReferenceAdapterback to summary
public void createDynamicReferenceAdapter(String className)

Create a reference for given className

defineDynamicClassback to summary
protected Class<?> defineDynamicClass(String name, byte[] b)

Converts an array of bytes into an instance of class Class. Before the Class can be used it must be resolved.

findClassback to summary
protected Class<?> findClass(String className) throws ClassNotFoundException

Overrides java.lang.ClassLoader.findClass.

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.

Parameters
className:String

Doc from java.lang.ClassLoader.findClass.

The binary name of the class

Returns:Class<?>

Doc from java.lang.ClassLoader.findClass.

The resulting Class object

Annotations
@Override
Exceptions
ClassNotFoundException:

Doc from java.lang.ClassLoader.findClass.

If the class could not be found

getClassWriterback to summary
public EclipseLinkClassWriter getClassWriter(String className)
getClassWritersback to summary
protected Map<String, EclipseLinkClassWriter> getClassWriters()
getDefaultWriterback to summary
public DynamicClassWriter getDefaultWriter()
lookupback to summary
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.

org.eclipse.persistence.dynamic back to summary

public Class DynamicClassLoader.EnumInfo

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv String
pack-priv List<String>

Constructor Summary

AccessConstructor and Description
public
EnumInfo(String className)

Method Summary

Modifier and TypeMethod and Description
public void
addLiteralLabel(String literalLabel)

public String
public String[]
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classNameback to summary
pack-priv String className
literalLabelsback to summary
pack-priv List<String> literalLabels

Constructor Detail

EnumInfoback to summary
public EnumInfo(String className)

Method Detail

addLiteralLabelback to summary
public void addLiteralLabel(String literalLabel)
getClassNameback to summary
public String getClassName()
getLiteralLabelsback to summary
public String[] getLiteralLabels()