org.logicalcobwebs.cglib.core
Class AbstractClassGenerator

java.lang.Object
  extended by org.logicalcobwebs.cglib.core.AbstractClassGenerator
All Implemented Interfaces:
ClassGenerator
Direct Known Subclasses:
ConstructorDelegate.Generator, Enhancer, FastClass.Generator, KeyFactory.Generator, MethodDelegate.Generator, Mixin.Generator, MulticastDelegate.Generator, ParallelSorter.Generator, StringSwitcher.Generator

public abstract class AbstractClassGenerator
extends java.lang.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
           
 
Field Summary
private  java.lang.ClassLoader classLoader
           
private  java.lang.Object key
           
private static java.lang.Object NAME_KEY
           
private  java.lang.String namePrefix
           
private  NamingPolicy namingPolicy
           
private  AbstractClassGenerator.Source source
           
private  GeneratorStrategy strategy
           
private  boolean useCache
           
 
Constructor Summary
protected AbstractClassGenerator(AbstractClassGenerator.Source source)
           
 
Method Summary
protected  java.lang.Object create(java.lang.Object key)
           
protected abstract  java.lang.Object firstInstance(java.lang.Class type)
           
protected  java.lang.ClassLoader getClassLoader()
           
protected  java.lang.String getClassName()
           
private  java.lang.String getClassName(java.lang.ClassLoader loader)
           
private  java.util.Set getClassNameCache(java.lang.ClassLoader loader)
           
protected abstract  java.lang.ClassLoader getDefaultClassLoader()
           
protected abstract  java.lang.Object nextInstance(java.lang.Object instance)
           
 void setClassLoader(java.lang.ClassLoader classLoader)
          Set the ClassLoader in which the class will be generated.
protected  void setNamePrefix(java.lang.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 org.logicalcobwebs.cglib.core.ClassGenerator
generateClass
 

Field Detail

NAME_KEY

private static final java.lang.Object NAME_KEY

strategy

private GeneratorStrategy strategy

namingPolicy

private NamingPolicy namingPolicy

source

private AbstractClassGenerator.Source source

classLoader

private java.lang.ClassLoader classLoader

namePrefix

private java.lang.String namePrefix

key

private java.lang.Object key

useCache

private boolean useCache
Constructor Detail

AbstractClassGenerator

protected AbstractClassGenerator(AbstractClassGenerator.Source source)
Method Detail

setNamePrefix

protected void setNamePrefix(java.lang.String namePrefix)

getClassName

protected final java.lang.String getClassName()

getClassName

private java.lang.String getClassName(java.lang.ClassLoader loader)

getClassNameCache

private java.util.Set getClassNameCache(java.lang.ClassLoader loader)

setClassLoader

public void setClassLoader(java.lang.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

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.


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.


getClassLoader

protected java.lang.ClassLoader getClassLoader()

getDefaultClassLoader

protected abstract java.lang.ClassLoader getDefaultClassLoader()

create

protected java.lang.Object create(java.lang.Object key)

firstInstance

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

nextInstance

protected abstract java.lang.Object nextInstance(java.lang.Object instance)
                                          throws java.lang.Exception
Throws:
java.lang.Exception