Class AbstractClassGenerator<T>

  • java.lang.Object
    • org.springframework.cglib.core.AbstractClassGenerator<T>
  • All Implemented Interfaces:
    Direct Known Subclasses:
    Enhancer, KeyFactory.Generator

    public abstract class AbstractClassGenerator<T>
    extends java.lang.Object
    implements org.springframework.cglib.core.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 Detail

      • wrapCachedClass

        protected T wrapCachedClass(java.lang.Class klass)
      • unwrapCachedValue

        protected java.lang.Object unwrapCachedValue(T cached)
      • setNamePrefix

        protected void setNamePrefix(java.lang.String namePrefix)
      • getClassName

        protected final java.lang.String getClassName()
      • 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.

        classLoader - the loader to generate the new class with, or null to use the default
      • setContextClass

        public void setContextClass(java.lang.Class contextClass)
      • setNamingPolicy

        public void setNamingPolicy(org.springframework.cglib.core.NamingPolicy namingPolicy)
        Override the default naming policy.
        namingPolicy - the custom policy, or null to use the default
        See Also:
      • 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.
      • 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(org.springframework.cglib.core.GeneratorStrategy strategy)
        Set the strategy to use to create the bytecode from this generator. By default an instance of DefaultGeneratorStrategy is used.
      • 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 java.lang.ClassLoader getClassLoader()
      • getDefaultClassLoader

        protected abstract java.lang.ClassLoader getDefaultClassLoader()
      • getProtectionDomain

        protected 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.

        the protection domain (null for using a default)
      • 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
      • nextInstance

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