public abstract class InjectionClassLoader
extends java.lang.ClassLoader
An injection class loader allows for the injection of a class after the class loader was created. Injection is only possible if this class loader is not sealed.
Important: Not sealing a class loader allows to break package encapsulation for anybody getting hold of a reference to this class loader.
Modifier and Type | Class and Description |
---|---|
static class |
InjectionClassLoader.Strategy
A class loading strategy for adding a type to an injection class loader.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
sealed
Indicates if this class loader is sealed, i.e.
|
Modifier | Constructor and Description |
---|---|
protected |
InjectionClassLoader(java.lang.ClassLoader parent,
boolean sealed)
Creates a new injection class loader.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Class<?> |
defineClass(java.lang.String name,
byte[] binaryRepresentation)
Defines a new type to be loaded by this class loader.
|
java.util.Map<java.lang.String,java.lang.Class<?>> |
defineClasses(java.util.Map<java.lang.String,byte[]> typeDefinitions)
Defines a group of types to be loaded by this class loader.
|
protected abstract java.util.Map<java.lang.String,java.lang.Class<?>> |
doDefineClasses(java.util.Map<java.lang.String,byte[]> typeDefinitions)
Defines a group of types to be loaded by this class loader.
|
boolean |
isSealed()
Returns
true if this class loader is sealed. |
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
private final boolean sealed
protected InjectionClassLoader(java.lang.ClassLoader parent, boolean sealed)
parent
- The class loader's parent.sealed
- Indicates if this class loader is sealed, i.e. forbids runtime injection.public boolean isSealed()
true
if this class loader is sealed.true
if this class loader is sealed.public java.lang.Class<?> defineClass(java.lang.String name, byte[] binaryRepresentation) throws java.lang.ClassNotFoundException
name
- The name of the type.binaryRepresentation
- The type's binary representation.java.lang.ClassNotFoundException
- If the class could not be loaded.public java.util.Map<java.lang.String,java.lang.Class<?>> defineClasses(java.util.Map<java.lang.String,byte[]> typeDefinitions) throws java.lang.ClassNotFoundException
IllegalStateException
is thrown.typeDefinitions
- The types binary representations.java.lang.ClassNotFoundException
- If the class could not be loaded.protected abstract java.util.Map<java.lang.String,java.lang.Class<?>> doDefineClasses(java.util.Map<java.lang.String,byte[]> typeDefinitions) throws java.lang.ClassNotFoundException
typeDefinitions
- The types binary representations.java.lang.ClassNotFoundException
- If the class could not be loaded.