net.sf.cglib.core
Class AbstractClassGenerator

java.lang.Object
  extended by net.sf.cglib.core.AbstractClassGenerator
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

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.


Nested Class Summary
protected static class AbstractClassGenerator.Source
           
 
Constructor Summary
protected AbstractClassGenerator(AbstractClassGenerator.Source source)
           
 
Method Summary
protected  Object create(Object key)
           
protected abstract  Object firstInstance(Class type)
           
 boolean getAttemptLoad()
           
 ClassLoader getClassLoader()
           
protected  String getClassName()
           
static AbstractClassGenerator getCurrent()
          Used internally by CGLIB.
protected abstract  ClassLoader getDefaultClassLoader()
           
 NamingPolicy getNamingPolicy()
           
 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.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.cglib.core.ClassGenerator
generateClass
 

Constructor Detail

AbstractClassGenerator

protected AbstractClassGenerator(AbstractClassGenerator.Source source)
Method Detail

setNamePrefix

protected void setNamePrefix(String namePrefix)

getClassName

protected final String getClassName()

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

getNamingPolicy

public NamingPolicy getNamingPolicy()
See Also:
setNamingPolicy(net.sf.cglib.core.NamingPolicy)

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.


getUseCache

public boolean getUseCache()
See Also:
setUseCache(boolean)

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.


getAttemptLoad

public boolean getAttemptLoad()

setStrategy

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


getStrategy

public GeneratorStrategy getStrategy()
See Also:
setStrategy(net.sf.cglib.core.GeneratorStrategy)

getCurrent

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


getClassLoader

public ClassLoader getClassLoader()

getDefaultClassLoader

protected abstract ClassLoader getDefaultClassLoader()

create

protected Object create(Object key)

firstInstance

protected abstract Object firstInstance(Class type)
                                 throws Exception
Throws:
Exception

nextInstance

protected abstract Object nextInstance(Object instance)
                                throws Exception
Throws:
Exception


Copyright © 2012 Oracle Corporation. All Rights Reserved.