public abstract class AbstractClassGenerator<T> extends Object implements org.springframework.cglib.core.ClassGenerator
ClassLoader
, name of the generated class, and transformations
applied before generation.Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractClassGenerator.ClassLoaderData |
protected static class |
AbstractClassGenerator.Source |
Modifier | Constructor and Description |
---|---|
protected |
AbstractClassGenerator(AbstractClassGenerator.Source source) |
Modifier and Type | Method and Description |
---|---|
protected Object |
create(Object key) |
protected abstract Object |
firstInstance(Class type) |
protected Class |
generate(AbstractClassGenerator.ClassLoaderData data) |
boolean |
getAttemptLoad() |
ClassLoader |
getClassLoader() |
protected String |
getClassName() |
static AbstractClassGenerator |
getCurrent()
Used internally by CGLIB.
|
protected abstract ClassLoader |
getDefaultClassLoader() |
org.springframework.cglib.core.NamingPolicy |
getNamingPolicy() |
protected ProtectionDomain |
getProtectionDomain()
Returns the protection domain to use when defining the class.
|
org.springframework.cglib.core.GeneratorStrategy |
getStrategy() |
boolean |
getUseCache() |
protected abstract Object |
nextInstance(Object instance) |
void |
setAttemptLoad(boolean attemptLoad)
If set, CGLIB will attempt to load classes from the specified
ClassLoader before generating them. |
void |
setClassLoader(ClassLoader classLoader)
Set the
ClassLoader in which the class will be generated. |
void |
setContextClass(Class contextClass) |
protected void |
setNamePrefix(String namePrefix) |
void |
setNamingPolicy(org.springframework.cglib.core.NamingPolicy namingPolicy)
Override the default naming policy.
|
void |
setStrategy(org.springframework.cglib.core.GeneratorStrategy strategy)
Set the strategy to use to create the bytecode from this generator.
|
void |
setUseCache(boolean useCache)
Whether use and update the static cache of generated classes
for a class with the same properties.
|
protected Object |
unwrapCachedValue(T cached) |
protected T |
wrapCachedClass(Class klass) |
protected AbstractClassGenerator(AbstractClassGenerator.Source source)
protected void setNamePrefix(String namePrefix)
protected final String getClassName()
public void setClassLoader(ClassLoader classLoader)
ClassLoader
in which the class will be generated.
Concrete subclasses of AbstractClassGenerator
(such as Enhancer
)
will try to choose an appropriate default if this is unset.
Classes are cached per-ClassLoader
using a WeakHashMap
, to allow
the generated classes to be removed when the associated loader is garbage collected.
classLoader
- the loader to generate the new class with, or null to use the defaultpublic void setContextClass(Class contextClass)
public void setNamingPolicy(org.springframework.cglib.core.NamingPolicy namingPolicy)
namingPolicy
- the custom policy, or null to use the defaultDefaultNamingPolicy
public org.springframework.cglib.core.NamingPolicy getNamingPolicy()
public void setUseCache(boolean useCache)
true
.public boolean getUseCache()
setUseCache(boolean)
public void setAttemptLoad(boolean attemptLoad)
ClassLoader
before generating them. Because generated
class names are not guaranteed to be unique, the default is false
.public boolean getAttemptLoad()
public void setStrategy(org.springframework.cglib.core.GeneratorStrategy strategy)
DefaultGeneratorStrategy
is used.public org.springframework.cglib.core.GeneratorStrategy getStrategy()
public static AbstractClassGenerator getCurrent()
AbstractClassGenerator
that is being used to generate a class in the current thread.public ClassLoader getClassLoader()
protected abstract ClassLoader getDefaultClassLoader()
protected ProtectionDomain getProtectionDomain()
Default implementation returns null
for using a default protection domain. Sub-classes may
override to use a more specific protection domain.
null
for using a default)protected Class generate(AbstractClassGenerator.ClassLoaderData data)
protected abstract Object firstInstance(Class type) throws Exception
Exception