Package org.jboss.invocation.proxy
Class AbstractClassFactory<T>
- java.lang.Object
-
- org.jboss.invocation.proxy.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 overridegenerateClass()to perform the actual class generation. The class will only be generated once at most- Author:
- Stuart Douglas
-
-
Field Summary
Fields Modifier and Type Field Description protected org.jboss.classfilewriter.ClassFileclassFileThe class file that is used to generate the class.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractClassFactory(String className, Class<T> superClass)Deprecated.protectedAbstractClassFactory(String className, Class<T> superClass, ClassLoader classLoader)Deprecated.protectedAbstractClassFactory(String className, Class<T> superClass, ClassLoader classLoader, ProtectionDomain protectionDomain)Deprecated.protectedAbstractClassFactory(String className, Class<T> superClass, ClassLoader classLoader, org.jboss.classfilewriter.ClassFactory classFactory)Construct a new instance with anullprotection domain.protectedAbstractClassFactory(String className, Class<T> superClass, ClassLoader classLoader, org.jboss.classfilewriter.ClassFactory classFactory, ProtectionDomain protectionDomain)Construct a new instance.protectedAbstractClassFactory(String className, Class<T> superClass, org.jboss.classfilewriter.ClassFactory classFactory)Construct a new instance with anullprotection domain.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidafterClassLoad(Class<?> clazz)Hook that is called after the class is loaded, beforecleanup()is called.voidbuildClassDefinition()Generates the classprotected abstract voidcleanup()Cleans up any resources left over from generating the class.Class<? extends T>defineClass()Returns theClassobject for the generated class, creating it if it does not existprotected abstract voidgenerateClass()Generate the class.ClassLoadergetClassLoader()Get the defining class loader.StringgetClassName()Get the class name.ProtectionDomaingetProtectionDomain()Get the defined protection domain.Class<T>getSuperClass()Get the superclass.StringgetSuperClassName()Get the superclass name.booleanisProxyClassDefined()Checks if the proxy class is defined in the factories class loaderbooleanisProxyClassDefined(ClassLoader classLoader)Checks if the proxy class has been defined in the given class loaderTnewInstance()Creates a new instance of the generated class by invoking the default constructor.
-
-
-
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, asgenerateClass()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 namesuperClass- the superclass of the generated classclassLoader- the class loader used to load the classclassFactory- the classFactory used to create the classprotectionDomain- the protection domain of the class
-
AbstractClassFactory
@Deprecated protected AbstractClassFactory(String className, Class<T> superClass, ClassLoader classLoader, ProtectionDomain protectionDomain)
Deprecated.Construct a new instance.- Parameters:
className- the generated class namesuperClass- the superclass of the generated classclassLoader- the class loader used to load the classprotectionDomain- 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 anullprotection domain.- Parameters:
className- the generated class namesuperClass- the superclass of the generated classclassLoader- the class loader used to load the classclassFactory- the classFactory used to create the class
-
AbstractClassFactory
@Deprecated protected AbstractClassFactory(String className, Class<T> superClass, ClassLoader classLoader)
Deprecated.Construct a new instance with anullprotection domain.- Parameters:
className- the generated class namesuperClass- the superclass of the generated classclassLoader- the class loader used to load the class
-
AbstractClassFactory
protected AbstractClassFactory(String className, Class<T> superClass, org.jboss.classfilewriter.ClassFactory classFactory)
Construct a new instance with anullprotection domain.- Parameters:
className- the generated class namesuperClass- the superclass of the generated class
-
AbstractClassFactory
@Deprecated protected AbstractClassFactory(String className, Class<T> superClass)
Deprecated.Construct a new instance with anullprotection domain.- Parameters:
className- the generated class namesuperClass- 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, beforecleanup()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 theClassobject 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
-
newInstance
public T newInstance() throws InstantiationException, IllegalAccessException
Creates a new instance of the generated class by invoking the default constructor. If the generated class has not been defined it will be created.- Returns:
- the new instance
- Throws:
InstantiationException- if the new instance could not be createdIllegalAccessException- if the new constructor is inaccessible for some reason
-
getClassName
public String getClassName()
Get the class name.- Returns:
- the class name
-
getSuperClassName
public String getSuperClassName()
Get the superclass name.- Returns:
- the superclass name
-
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
-
-