Package net.sf.cglib.core
Class AbstractClassGenerator<T>
java.lang.Object
net.sf.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 classprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate static Map<ClassLoader,AbstractClassGenerator.ClassLoaderData> private ClassLoaderprivate Stringprivate static final ThreadLocalprivate static final booleanprivate Objectprivate Stringprivate NamingPolicyprivate AbstractClassGenerator.Sourceprivate GeneratorStrategyprivate boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected -
Method Summary
Modifier and TypeMethodDescriptionprotected Objectprotected abstract ObjectfirstInstance(Class type) protected Classprivate StringgenerateClassName(Predicate nameTestPredicate) booleanprotected final Stringstatic AbstractClassGeneratorUsed internally by CGLIB.protected abstract ClassLoaderprotected ProtectionDomainReturns the protection domain to use when defining the class.booleanprotected abstract ObjectnextInstance(Object instance) voidsetAttemptLoad(boolean attemptLoad) If set, CGLIB will attempt to load classes from the specifiedClassLoaderbefore generating them.voidsetClassLoader(ClassLoader classLoader) Set theClassLoaderin which the class will be generated.private voidsetClassName(String className) protected voidsetNamePrefix(String namePrefix) voidsetNamingPolicy(NamingPolicy namingPolicy) Override the default naming policy.voidsetStrategy(GeneratorStrategy strategy) Set the strategy to use to create the bytecode from this generator.voidsetUseCache(boolean useCache) Whether use and update the static cache of generated classes for a class with the same properties.protected ObjectunwrapCachedValue(T cached) protected TwrapCachedClass(Class klass) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.sf.cglib.core.ClassGenerator
generateClass
-
Field Details
-
CURRENT
-
CACHE
-
DEFAULT_USE_CACHE
private static final boolean DEFAULT_USE_CACHE -
strategy
-
namingPolicy
-
source
-
classLoader
-
namePrefix
-
key
-
useCache
private boolean useCache -
className
-
attemptLoad
private boolean attemptLoad
-
-
Constructor Details
-
AbstractClassGenerator
-
-
Method Details
-
wrapCachedClass
-
unwrapCachedValue
-
setNamePrefix
-
getClassName
-
setClassName
-
generateClassName
-
setClassLoader
Set theClassLoaderin 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-
ClassLoaderusing 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
-
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 specifiedClassLoaderbefore 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 of is used. -
getStrategy
-
getCurrent
Used internally by CGLIB. Returns theAbstractClassGeneratorthat 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
nullfor using a default protection domain. Sub-classes may override to use a more specific protection domain.- Returns:
- the protection domain (
nullfor using a default)
-
create
-
generate
-
firstInstance
- Throws:
Exception
-
nextInstance
- Throws:
Exception
-