net.sf.cglib.core

Class AbstractClassGenerator

public abstract class AbstractClassGenerator extends Object implements ClassGenerator

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.
Method Summary
booleangetAttemptLoad()
ClassLoadergetClassLoader()
static AbstractClassGeneratorgetCurrent()
Used internally by CGLIB.
NamingPolicygetNamingPolicy()
GeneratorStrategygetStrategy()
booleangetUseCache()
voidsetAttemptLoad(boolean attemptLoad)
If set, CGLIB will attempt to load classes from the specified ClassLoader before generating them.
voidsetClassLoader(ClassLoader classLoader)
Set the ClassLoader in which the class will be generated.
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.

Method Detail

getAttemptLoad

public boolean getAttemptLoad()

getClassLoader

public ClassLoader getClassLoader()

getCurrent

public static AbstractClassGenerator getCurrent()
Used internally by CGLIB. Returns the AbstractClassGenerator that is being used to generate a class in the current thread.

getNamingPolicy

public NamingPolicy getNamingPolicy()

See Also: AbstractClassGenerator

getStrategy

public GeneratorStrategy getStrategy()

See Also: AbstractClassGenerator

getUseCache

public boolean getUseCache()

See Also: AbstractClassGenerator

setAttemptLoad

public void setAttemptLoad(boolean attemptLoad)
If set, CGLIB will attempt to load classes from the specified ClassLoader before generating them. Because generated class names are not guaranteed to be unique, the default is false.

setClassLoader

public void setClassLoader(ClassLoader classLoader)
Set the 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.

Parameters: classLoader the loader to generate the new class with, or null to use the default

setNamingPolicy

public void setNamingPolicy(NamingPolicy namingPolicy)
Override the default naming policy.

Parameters: namingPolicy the custom policy, or null to use the default

See Also: DefaultNamingPolicy

setStrategy

public void setStrategy(GeneratorStrategy strategy)
Set the strategy to use to create the bytecode from this generator. By default an instance of {@see DefaultGeneratorStrategy} is used.

setUseCache

public void setUseCache(boolean useCache)
Whether use and update the static cache of generated classes for a class with the same properties. Default is true.
Copyright (c) 2001 - Apache Software Foundation