Package org.springframework.cglib.core
Class AbstractClassGenerator<T>
java.lang.Object
org.springframework.cglib.core.AbstractClassGenerator<T>
- All Implemented Interfaces:
ClassGenerator
- Direct Known Subclasses:
BeanCopier.Generator
,BeanGenerator
,BeanMap.Generator
,BulkBean.Generator
,ConstructorDelegate.Generator
,Enhancer
,FastClass.Generator
,ImmutableBean.Generator
,InterfaceMaker
,KeyFactory.Generator
,MethodDelegate.Generator
,Mixin.Generator
,MulticastDelegate.Generator
,ParallelSorter.Generator
,StringSwitcher.Generator
Abstract class for all code-generating CGLIB utilities.
In addition to caching generated classes for performance, it provides hooks for
customizing the
ClassLoader
, name of the generated class, and transformations
applied before generation.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
protected static class
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
-
Method Summary
Modifier and TypeMethodDescriptionprotected Object
protected abstract Object
firstInstance
(Class type) protected Class
boolean
protected final String
static AbstractClassGenerator
Used internally by CGLIB.protected abstract ClassLoader
protected ProtectionDomain
Returns the protection domain to use when defining the class.boolean
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
(NamingPolicy namingPolicy) Override the default naming policy.void
setStrategy
(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) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.cglib.core.ClassGenerator
generateClass
-
Constructor Details
-
AbstractClassGenerator
-
-
Method Details
-
wrapCachedClass
-
unwrapCachedValue
-
setNamePrefix
-
getClassName
-
setClassLoader
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.- Parameters:
classLoader
- the loader to generate the new class with, or null to use the default
-
setContextClass
-
setNamingPolicy
Override the default naming policy.- Parameters:
namingPolicy
- the custom policy, or null to use the default- See Also:
-
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()- See Also:
-
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
Set the strategy to use to create the bytecode from this generator. By default an instance ofDefaultGeneratorStrategy
is used. -
getStrategy
-
getCurrent
Used internally by CGLIB. Returns theAbstractClassGenerator
that is being used to generate a class in the current thread. -
getClassLoader
-
getDefaultClassLoader
-
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.- Returns:
- the protection domain (
null
for using a default)
-
create
-
generate
-
firstInstance
- Throws:
Exception
-
nextInstance
- Throws:
Exception
-