Class AbstractClassFactory<T>

  • Type Parameters:
    T - the type of the superclass
    Direct Known Subclasses:
    AbstractSubclassFactory

    public abstract class AbstractClassFactory<T>
    extends Object
    Base class for all class factories.

    Sub classes should override generateClass() to perform the actual class generation. The class will only be generated once at most

    Author:
    Stuart Douglas
    • Field Detail

      • classFile

        protected org.jboss.classfilewriter.ClassFile classFile
        The class file that is used to generate the class.

        Note that this object is not thread safe, so care should be taken by subclasses to ensure that no more than one thread accesses this at once. In normal use this should not be an issue, as generateClass() will only be called once by a single thread.

    • Constructor Detail

      • AbstractClassFactory

        protected AbstractClassFactory​(String className,
                                       Class<T> superClass,
                                       ClassLoader classLoader,
                                       org.jboss.classfilewriter.ClassFactory classFactory,
                                       ProtectionDomain protectionDomain)
        Construct a new instance.
        Parameters:
        className - the generated class name
        superClass - the superclass of the generated class
        classLoader - the class loader used to load the class
        classFactory - the classFactory used to create the class
        protectionDomain - the protection domain of the class
      • AbstractClassFactory

        protected AbstractClassFactory​(String className,
                                       Class<T> superClass,
                                       ClassLoader classLoader,
                                       org.jboss.classfilewriter.ClassFactory classFactory)
        Construct a new instance with a null protection domain.
        Parameters:
        className - the generated class name
        superClass - the superclass of the generated class
        classLoader - the class loader used to load the class
        classFactory - the classFactory used to create the class
      • AbstractClassFactory

        protected AbstractClassFactory​(String className,
                                       Class<T> superClass,
                                       org.jboss.classfilewriter.ClassFactory classFactory)
        Construct a new instance with a null protection domain.
        Parameters:
        className - the generated class name
        superClass - the superclass of the generated class
    • Method Detail

      • generateClass

        protected abstract void generateClass()
        Generate the class.
      • cleanup

        protected abstract void cleanup()
        Cleans up any resources left over from generating the class. Implementors should ensure they call super.cleanup();
      • afterClassLoad

        public void afterClassLoad​(Class<?> clazz)
        Hook that is called after the class is loaded, before cleanup() is called.

        This method may be called mutiple times, if the proxy is definined in multiple class loaders

        Parameters:
        clazz - The newly loaded class
      • defineClass

        public Class<? extends T> defineClass()
        Returns the Class object for the generated class, creating it if it does not exist
        Returns:
        the generated class
      • isProxyClassDefined

        public boolean isProxyClassDefined()
        Checks if the proxy class is defined in the factories class loader
        Returns:
        true if the proxy class already exists
      • isProxyClassDefined

        public boolean isProxyClassDefined​(ClassLoader classLoader)
        Checks if the proxy class has been defined in the given class loader
        Parameters:
        classLoader - The class loader to check
        Returns:
        true if the proxy is defined in the class loader
      • buildClassDefinition

        public void buildClassDefinition()
        Generates the class
      • getClassName

        public String getClassName()
        Get the class name.
        Returns:
        the class name
      • getSuperClassName

        public String getSuperClassName()
        Get the superclass name.
        Returns:
        the superclass name
      • getSuperClass

        public Class<T> getSuperClass()
        Get the superclass.
        Returns:
        the superclass
      • getClassLoader

        public ClassLoader getClassLoader()
        Get the defining class loader.
        Returns:
        the defining class loader
      • getProtectionDomain

        public ProtectionDomain getProtectionDomain()
        Get the defined protection domain.
        Returns:
        the protection domain