类 AbstractClassGenerator<T>
- java.lang.Object
- org.springframework.cglib.core.AbstractClassGenerator<T>
- 所有已实现的接口:
org.springframework.cglib.core.ClassGenerator
- 直接已知子类:
Enhancer
,KeyFactory.Generator
public abstract class AbstractClassGenerator<T> extends Object implements org.springframework.cglib.core.ClassGenerator
Abstract class for all code-generating CGLIB utilities. In addition to caching generated classes for performance, it provides hooks for customizing theClassLoader
, name of the generated class, and transformations applied before generation.
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected static class
AbstractClassGenerator.ClassLoaderData
protected static class
AbstractClassGenerator.Source
构造器概要
构造器 限定符 构造器 说明 protected
AbstractClassGenerator(AbstractClassGenerator.Source source)
方法概要
所有方法 静态方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 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 specifiedClassLoader
before generating them.void
setClassLoader(ClassLoader classLoader)
Set theClassLoader
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)
构造器详细资料
AbstractClassGenerator
protected AbstractClassGenerator(AbstractClassGenerator.Source source)
方法详细资料
wrapCachedClass
protected T wrapCachedClass(Class klass)
unwrapCachedValue
protected Object unwrapCachedValue(T cached)
setNamePrefix
protected void setNamePrefix(String namePrefix)
getClassName
protected final String getClassName()
setClassLoader
public void setClassLoader(ClassLoader classLoader)
Set theClassLoader
in which the class will be generated. Concrete subclasses ofAbstractClassGenerator
(such asEnhancer
) will try to choose an appropriate default if this is unset.Classes are cached per-
ClassLoader
using aWeakHashMap
, 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 default
setContextClass
public void setContextClass(Class contextClass)
setNamingPolicy
public void setNamingPolicy(org.springframework.cglib.core.NamingPolicy namingPolicy)
Override the default naming policy.- 参数:
namingPolicy
- the custom policy, or null to use the default- 另请参阅:
DefaultNamingPolicy
getNamingPolicy
public org.springframework.cglib.core.NamingPolicy getNamingPolicy()
setUseCache
public void setUseCache(boolean useCache)
Whether use and update the static cache of generated classes for a class with the same properties. Default istrue
.
getUseCache
public boolean getUseCache()
- 另请参阅:
setUseCache(boolean)
setAttemptLoad
public void setAttemptLoad(boolean attemptLoad)
If set, CGLIB will attempt to load classes from the specifiedClassLoader
before generating them. Because generated class names are not guaranteed to be unique, the default isfalse
.
getAttemptLoad
public boolean getAttemptLoad()
setStrategy
public void setStrategy(org.springframework.cglib.core.GeneratorStrategy strategy)
Set the strategy to use to create the bytecode from this generator. By default an instance ofDefaultGeneratorStrategy
is used.
getStrategy
public org.springframework.cglib.core.GeneratorStrategy getStrategy()
getCurrent
public static AbstractClassGenerator getCurrent()
Used internally by CGLIB. Returns theAbstractClassGenerator
that is being used to generate a class in the current thread.
getClassLoader
public ClassLoader getClassLoader()
getDefaultClassLoader
protected abstract ClassLoader getDefaultClassLoader()
getProtectionDomain
protected ProtectionDomain getProtectionDomain()
Returns the protection domain to use when defining the class.Default implementation returns
null
for using a default protection domain. Sub-classes may override to use a more specific protection domain.- 返回:
- the protection domain (
null
for using a default)
generate
protected Class generate(AbstractClassGenerator.ClassLoaderData data)
firstInstance
protected abstract Object firstInstance(Class type) throws Exception
- 抛出:
Exception
nextInstance
protected abstract Object nextInstance(Object instance) throws Exception
- 抛出:
Exception