Invocation API 1.1.0.Final

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

java.lang.Object
  extended by org.jboss.invocation.proxy.AbstractClassFactory<T>
      extended by org.jboss.invocation.proxy.AbstractSubclassFactory<T>
Type Parameters:
T - the superclass type
Direct Known Subclasses:
AbstractProxyFactory

public abstract class AbstractSubclassFactory<T>
extends AbstractClassFactory<T>

Class factory for classes that override superclass methods.

This class extends AbstractClassFactory by adding convenience methods to override methods on the superclass.

Author:
Stuart Douglas

Field Summary
protected  ReflectionMetadataSource reflectionMetadataSource
          The metadata source used to generate the proxy
 
Fields inherited from class org.jboss.invocation.proxy.AbstractClassFactory
classFile
 
Constructor Summary
protected AbstractSubclassFactory(String className, Class<T> superClass, ClassLoader classLoader, ProtectionDomain protectionDomain, ReflectionMetadataSource reflectionMetadataSource)
          Construct a new instance.
 
Method Summary
protected  boolean addInterface(Class<?> interfaceClass)
          Adds an interface to the generated subclass, using the default MethodBodyCreator to generate the method bodies.
protected  boolean addInterface(MethodBodyCreator override, Class<?> interfaceClass)
          Adds an interface to the generated subclass, using the given MethodBodyCreator to generate the method bodies
protected  void cleanup()
          Cleans up any resources left over from generating the class.
protected  void createConstructorDelegates()
          Adds a constructor for every non-private constructor present on the superclass.
protected  void createConstructorDelegates(ConstructorBodyCreator creator)
          Adds constructors that delegate the the superclass constructor for all non-private constructors present on the superclass
 ConstructorBodyCreator getDefaultConstructorOverride()
          Returns the default ConstructorBodyCreator to use then creating overridden subclasses.
 MethodBodyCreator getDefaultMethodOverride()
          Returns the default MethodBodyCreator to use when creating overridden methods.
protected  void overrideAllMethods()
          Calls overrideAllMethods(MethodBodyCreator) with the default MethodBodyCreator.
protected  void overrideAllMethods(MethodBodyCreator override)
          Overrides all methods on the superclass with the exception of equals(Object), hashCode(), toString() and finalize().
protected  boolean overrideEquals()
          Override the equals method using the default MethodBodyCreator.
protected  boolean overrideEquals(MethodBodyCreator creator)
          Override the equals method using the given MethodBodyCreator.
protected  boolean overrideFinalize()
          Override the finalize method using the default MethodBodyCreator.
protected  boolean overrideFinalize(MethodBodyCreator creator)
          Override the finalize method using the given MethodBodyCreator.
protected  boolean overrideHashcode()
          Override the hashCode method using the default MethodBodyCreator.
protected  boolean overrideHashcode(MethodBodyCreator creator)
          Override the hashCode method using the given MethodBodyCreator.
protected  boolean overrideMethod(org.jboss.classfilewriter.ClassMethod method, MethodIdentifier identifier, MethodBodyCreator creator)
          Creates a new method on the generated class that overrides the given methods, unless a method with the same signature has already been overridden.
protected  boolean overrideMethod(Method method, MethodIdentifier identifier, MethodBodyCreator creator)
          Creates a new method on the generated class that overrides the given methods, unless a method with the same signature has already been overridden.
protected  void overridePublicMethods()
          Overrides all public methods on the superclass.
protected  void overridePublicMethods(MethodBodyCreator override)
          Overrides all public methods on the superclass.
protected  boolean overrideToString()
          Override the toString method using the default MethodBodyCreator
protected  boolean overrideToString(MethodBodyCreator creator)
          Override the toString method using the given MethodBodyCreator.
 
Methods inherited from class org.jboss.invocation.proxy.AbstractClassFactory
afterClassLoad, buildClassDefinition, defineClass, generateClass, getClassLoader, getClassName, getProtectionDomain, getSuperClass, getSuperClassName, isProxyClassDefined, isProxyClassDefined, newInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reflectionMetadataSource

protected final ReflectionMetadataSource reflectionMetadataSource
The metadata source used to generate the proxy

Constructor Detail

AbstractSubclassFactory

protected AbstractSubclassFactory(String className,
                                  Class<T> superClass,
                                  ClassLoader classLoader,
                                  ProtectionDomain protectionDomain,
                                  ReflectionMetadataSource reflectionMetadataSource)
Construct a new instance.

Parameters:
className - the class name
superClass - the superclass
classLoader - the defining class loader
protectionDomain - the protection domain
Method Detail

overrideMethod

protected boolean overrideMethod(Method method,
                                 MethodIdentifier identifier,
                                 MethodBodyCreator creator)
Creates a new method on the generated class that overrides the given methods, unless a method with the same signature has already been overridden.

Parameters:
method - The method to override
identifier - The identifier of the method to override
creator - The MethodBodyCreator used to create the method body
Returns:
true if the method was successfully overridden, false otherwise

overrideMethod

protected boolean overrideMethod(org.jboss.classfilewriter.ClassMethod method,
                                 MethodIdentifier identifier,
                                 MethodBodyCreator creator)
Creates a new method on the generated class that overrides the given methods, unless a method with the same signature has already been overridden.

Parameters:
method - The method to override
identifier - The identifier of the method to override
creator - The MethodBodyCreator used to create the method body
Returns:
false if the method has already been overridden

overridePublicMethods

protected void overridePublicMethods()
Overrides all public methods on the superclass. The default MethodBodyCreator is used to generate the class body.

NOTE: This will not override equals(Object), hashCode(), finalize() and toString(), these should be overridden separately using overrideEquals(MethodBodyCreator) overrideHashcode(MethodBodyCreator)overrideToString(MethodBodyCreator) overrideFinalize(MethodBodyCreator)


cleanup

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

Specified by:
cleanup in class AbstractClassFactory<T>

overridePublicMethods

protected void overridePublicMethods(MethodBodyCreator override)
Overrides all public methods on the superclass. The given MethodBodyCreator is used to generate the class body.

NOTE: This will not override equals(Object), hashCode(), finalize() and toString(), these should be overridden separately using overrideEquals(MethodBodyCreator) overrideHashcode(MethodBodyCreator),overrideToString(MethodBodyCreator) and overrideFinalize(MethodBodyCreator)

Parameters:
override - the method body creator to use

overrideAllMethods

protected void overrideAllMethods()
Calls overrideAllMethods(MethodBodyCreator) with the default MethodBodyCreator.


overrideAllMethods

protected void overrideAllMethods(MethodBodyCreator override)
Overrides all methods on the superclass with the exception of equals(Object), hashCode(), toString() and finalize(). The given MethodBodyCreator is used to generate the class body.

Note that private methods are not actually overridden, and if the sub-class is loaded by a different ClassLoader to the parent class then neither will package-private methods. These methods will still be present on the new class however, and can be accessed via reflection

Parameters:
override - the method body creator to use

overrideEquals

protected boolean overrideEquals()
Override the equals method using the default MethodBodyCreator.

Returns:
true if the method was not already overridden

overrideEquals

protected boolean overrideEquals(MethodBodyCreator creator)
Override the equals method using the given MethodBodyCreator.

Parameters:
creator - the method body creator to use
Returns:
true if the method was not already overridden

overrideHashcode

protected boolean overrideHashcode()
Override the hashCode method using the default MethodBodyCreator.

Returns:
true if the method was not already overridden

overrideHashcode

protected boolean overrideHashcode(MethodBodyCreator creator)
Override the hashCode method using the given MethodBodyCreator.

Parameters:
creator - the method body creator to use
Returns:
true if the method was not already overridden

overrideToString

protected boolean overrideToString()
Override the toString method using the default MethodBodyCreator

Returns:
true if the method was not already overridden

overrideToString

protected boolean overrideToString(MethodBodyCreator creator)
Override the toString method using the given MethodBodyCreator.

Parameters:
creator - the method body creator to use
Returns:
true if the method was not already overridden

overrideFinalize

protected boolean overrideFinalize()
Override the finalize method using the default MethodBodyCreator.

Returns:
true if the method was not already overridden

overrideFinalize

protected boolean overrideFinalize(MethodBodyCreator creator)
Override the finalize method using the given MethodBodyCreator.

Parameters:
creator - the method body creator to use

addInterface

protected boolean addInterface(Class<?> interfaceClass)
Adds an interface to the generated subclass, using the default MethodBodyCreator to generate the method bodies.

Parameters:
interfaceClass - the interface to add

addInterface

protected boolean addInterface(MethodBodyCreator override,
                               Class<?> interfaceClass)
Adds an interface to the generated subclass, using the given MethodBodyCreator to generate the method bodies

Parameters:
override - the method body creator to use
interfaceClass - the interface to add
Returns:
true if the interface was not already overridden

createConstructorDelegates

protected void createConstructorDelegates()
Adds a constructor for every non-private constructor present on the superclass. The constructor bodies are generated with the default ConstructorBodyCreator


createConstructorDelegates

protected void createConstructorDelegates(ConstructorBodyCreator creator)
Adds constructors that delegate the the superclass constructor for all non-private constructors present on the superclass

Parameters:
creator - the constructor body creator to use

getDefaultMethodOverride

public MethodBodyCreator getDefaultMethodOverride()
Returns the default MethodBodyCreator to use when creating overridden methods.

Returns:
the default method body creator

getDefaultConstructorOverride

public ConstructorBodyCreator getDefaultConstructorOverride()
Returns the default ConstructorBodyCreator to use then creating overridden subclasses.

Returns:
the default constructor body creator

Invocation API 1.1.0.Final

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