public static enum ClassLoadingStrategy.Default extends Enum<ClassLoadingStrategy.Default> implements ClassLoadingStrategy.Configurable
Modifier and Type | Class and Description |
---|---|
protected static class |
ClassLoadingStrategy.Default.InjectionDispatcher
A class loading strategy which applies a class loader injection while applying a given
ProtectionDomain on class injection. |
protected static class |
ClassLoadingStrategy.Default.WrappingDispatcher
A class loading strategy which creates a wrapping class loader while applying a given
ProtectionDomain on class loading. |
ClassLoadingStrategy.Configurable, ClassLoadingStrategy.Default, ClassLoadingStrategy.ForBootstrapInjection
Enum Constant and Description |
---|
CHILD_FIRST
The child-first class loading strategy is a modified version of the
WRAPPER where the dynamic types are given
priority over any types of a parent class loader with the same name. |
CHILD_FIRST_PERSISTENT
The strategy is identical to
CHILD_FIRST but
exposes the byte arrays that represent a class by ClassLoader.getResourceAsStream(String) . |
INJECTION
This strategy does not create a new class loader but injects all classes into the given
ClassLoader
by reflective access. |
WRAPPER
This strategy creates a new
ByteArrayClassLoader with the given
class loader as its parent. |
WRAPPER_PERSISTENT
The strategy is identical to
WRAPPER but exposes
the byte arrays that represent a class by ClassLoader.getResourceAsStream(String) . |
Modifier and Type | Method and Description |
---|---|
ClassLoadingStrategy.Configurable |
allowExistingTypes()
Determines if this class loading strategy should not throw an exception when attempting to load a class that
was already loaded.
|
Map<TypeDescription,Class<?>> |
load(ClassLoader classLoader,
Map<TypeDescription,byte[]> types)
Loads a given collection of classes given their binary representation.
|
String |
toString() |
static ClassLoadingStrategy.Default |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static ClassLoadingStrategy.Default[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
ClassLoadingStrategy.Configurable |
withAccessControlContext(AccessControlContext accessControlContext)
Defines the supplied access control context to be used for loading classes.
|
ClassLoadingStrategy.Configurable |
withPackageDefinitionStrategy(PackageDefinitionStrategy packageDefinitionStrategy)
Defines the supplied package definition strategy to be used for defining packages.
|
ClassLoadingStrategy.Configurable |
withProtectionDomain(ProtectionDomain protectionDomain)
Overrides the implicitly set default
ProtectionDomain with an explicit one. |
public static final ClassLoadingStrategy.Default WRAPPER
ByteArrayClassLoader
with the given
class loader as its parent. The byte array class loader is aware of a any dynamically created type and can
natively load the given classes. This allows to load classes with cyclic load-time dependencies since the
byte array class loader is queried on each encountered unknown class. Due to the encapsulation of the
classes that were loaded by a byte array class loader, this strategy will lead to the unloading of these
classes once this class loader, its classes or any instances of these classes become unreachable.public static final ClassLoadingStrategy.Default WRAPPER_PERSISTENT
WRAPPER
but exposes
the byte arrays that represent a class by ClassLoader.getResourceAsStream(String)
. For
this purpose, all class files are persisted as byte arrays withing the wrapping class loader.public static final ClassLoadingStrategy.Default CHILD_FIRST
The child-first class loading strategy is a modified version of the
WRAPPER
where the dynamic types are given
priority over any types of a parent class loader with the same name.
Important: This does not replace a type of the same name, but it makes the type invisible by the reach of this class loader.
public static final ClassLoadingStrategy.Default CHILD_FIRST_PERSISTENT
CHILD_FIRST
but
exposes the byte arrays that represent a class by ClassLoader.getResourceAsStream(String)
.
For this purpose, all class files are persisted as byte arrays withing the wrapping class loader.public static final ClassLoadingStrategy.Default INJECTION
This strategy does not create a new class loader but injects all classes into the given ClassLoader
by reflective access. This prevents the loading of classes with cyclic load-time dependencies but avoids the
creation of an additional class loader. The advantage of this strategy is that the loaded classes will have
package-private access to other classes within their package of the class loader into which they are
injected what is not permitted when the wrapper class loader is used. This strategy is implemented using a
ClassInjector.UsingReflection
. Note that this strategy usually yields
a better runtime performance.
Important: This class loader does not define packages for injected classes by default. Therefore, calls to
Class.getPackage()
might return null
. Packages are only defined
public static ClassLoadingStrategy.Default[] values()
for (ClassLoadingStrategy.Default c : ClassLoadingStrategy.Default.values()) System.out.println(c);
public static ClassLoadingStrategy.Default valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic Map<TypeDescription,Class<?>> load(ClassLoader classLoader, Map<TypeDescription,byte[]> types)
ClassLoadingStrategy
load
in interface ClassLoadingStrategy
classLoader
- The class loader to used for loading the classes.types
- Byte array representations of the types to be loaded mapped by their descriptions,
where an iteration order defines an order in which they are supposed to be loaded,
if relevant.public ClassLoadingStrategy.Configurable withProtectionDomain(ProtectionDomain protectionDomain)
ClassLoadingStrategy.Configurable
ProtectionDomain
with an explicit one.withProtectionDomain
in interface ClassLoadingStrategy.Configurable
protectionDomain
- The protection domain to apply.ProtectionDomain
.public ClassLoadingStrategy.Configurable withPackageDefinitionStrategy(PackageDefinitionStrategy packageDefinitionStrategy)
ClassLoadingStrategy.Configurable
withPackageDefinitionStrategy
in interface ClassLoadingStrategy.Configurable
packageDefinitionStrategy
- The package definer to be used.public ClassLoadingStrategy.Configurable withAccessControlContext(AccessControlContext accessControlContext)
ClassLoadingStrategy.Configurable
withAccessControlContext
in interface ClassLoadingStrategy.Configurable
accessControlContext
- The access control context to use for loading classes.public ClassLoadingStrategy.Configurable allowExistingTypes()
ClassLoadingStrategy.Configurable
allowExistingTypes
in interface ClassLoadingStrategy.Configurable
public String toString()
toString
in class Enum<ClassLoadingStrategy.Default>
Copyright © 2014–2016. All rights reserved.