Invocation API 1.1.0.Final

org.jboss.invocation.proxy
Class AbstractClassFactory<T>

java.lang.Object
  extended by 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 override generateClass() to perform the actual class generation. The class will only be generated once at most

Author:
Stuart Douglas

Field Summary
protected  org.jboss.classfilewriter.ClassFile classFile
          The class file that is used to generate the class.
 
Constructor Summary
protected AbstractClassFactory(String className, Class<T> superClass)
          Construct a new instance with a null protection domain.
protected AbstractClassFactory(String className, Class<T> superClass, ClassLoader classLoader)
          Construct a new instance with a null protection domain.
protected AbstractClassFactory(String className, Class<T> superClass, ClassLoader classLoader, ProtectionDomain protectionDomain)
          Construct a new instance.
 
Method Summary
 void afterClassLoad(Class<?> clazz)
          Hook that is called after the class is loaded, before cleanup() is called.
 void buildClassDefinition()
          Generates the class
protected abstract  void cleanup()
          Cleans up any resources left over from generating the class.
 Class<? extends T> defineClass()
          Returns the Class object for the generated class, creating it if it does not exist
protected abstract  void generateClass()
          Generate the class.
 ClassLoader getClassLoader()
          Get the defining class loader.
 String getClassName()
          Get the class name.
 ProtectionDomain getProtectionDomain()
          Get the defined protection domain.
 Class<T> getSuperClass()
          Get the superclass.
 String getSuperClassName()
          Get the superclass name.
 boolean isProxyClassDefined()
          Checks if the proxy class is defined in the factories class loader
 boolean isProxyClassDefined(ClassLoader classLoader)
          Checks if the proxy class has been defined in the given class loader
 T newInstance()
          Creates a new instance of the generated class by invoking the default constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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,
                               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
protectionDomain - the protection domain of the class

AbstractClassFactory

protected AbstractClassFactory(String className,
                               Class<T> superClass,
                               ClassLoader classLoader)
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

AbstractClassFactory

protected AbstractClassFactory(String className,
                               Class<T> superClass)
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


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 created
IllegalAccessException - 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

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

Invocation API 1.1.0.Final

Copyright © 2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.