Package org.jboss.invocation.proxy
Class AbstractSubclassFactory<T>
- java.lang.Object
-
- org.jboss.invocation.proxy.AbstractClassFactory<T>
-
- 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 extendsAbstractClassFactoryby adding convenience methods to override methods on the superclass.- Author:
- Stuart Douglas
-
-
Field Summary
Fields Modifier and Type Field Description protected ReflectionMetadataSourcereflectionMetadataSourceThe metadata source used to generate the proxy-
Fields inherited from class org.jboss.invocation.proxy.AbstractClassFactory
classFile
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSubclassFactory(String className, Class<T> superClass, ClassLoader classLoader, ProtectionDomain protectionDomain, ReflectionMetadataSource reflectionMetadataSource)protectedAbstractSubclassFactory(String className, Class<T> superClass, ClassLoader classLoader, org.jboss.classfilewriter.ClassFactory classFactory, ProtectionDomain protectionDomain, ReflectionMetadataSource reflectionMetadataSource)Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanaddInterface(Class<?> interfaceClass)Adds an interface to the generated subclass, using the defaultMethodBodyCreatorto generate the method bodies.protected booleanaddInterface(MethodBodyCreator override, Class<?> interfaceClass)Adds an interface to the generated subclass, using the givenMethodBodyCreatorto generate the method bodiesprotected voidcleanup()Cleans up any resources left over from generating the class.protected voidcreateConstructorDelegates()Adds a constructor for every non-private constructor present on the superclass.protected voidcreateConstructorDelegates(ConstructorBodyCreator creator)Adds constructors that delegate the the superclass constructor for all non-private constructors present on the superclassConstructorBodyCreatorgetDefaultConstructorOverride()Returns the defaultConstructorBodyCreatorto use then creating overridden subclasses.MethodBodyCreatorgetDefaultMethodOverride()Returns the defaultMethodBodyCreatorto use when creating overridden methods.protected voidoverrideAllMethods()CallsoverrideAllMethods(MethodBodyCreator)with the defaultMethodBodyCreator.protected voidoverrideAllMethods(MethodBodyCreator override)Overrides all methods on the superclass with the exception ofequals(Object),hashCode(),toString()andfinalize().protected booleanoverrideClone()Override the clone method using the defaultMethodBodyCreator.protected booleanoverrideClone(MethodBodyCreator creator)Override the clone method using the givenMethodBodyCreator.protected booleanoverrideEquals()Override the equals method using the defaultMethodBodyCreator.protected booleanoverrideEquals(MethodBodyCreator creator)Override the equals method using the givenMethodBodyCreator.protected booleanoverrideFinalize()Override the finalize method using the defaultMethodBodyCreator.protected booleanoverrideFinalize(MethodBodyCreator creator)Override the finalize method using the givenMethodBodyCreator.protected booleanoverrideHashcode()Override the hashCode method using the defaultMethodBodyCreator.protected booleanoverrideHashcode(MethodBodyCreator creator)Override the hashCode method using the givenMethodBodyCreator.protected booleanoverrideMethod(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 booleanoverrideMethod(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 voidoverridePublicMethods()CallsoverridePublicMethods(MethodBodyCreator)with the defaultMethodBodyCreator.protected voidoverridePublicMethods(MethodBodyCreator override)Overrides all public methods on the superclass.protected booleanoverrideToString()Override the toString method using the defaultMethodBodyCreatorprotected booleanoverrideToString(MethodBodyCreator creator)Override the toString method using the givenMethodBodyCreator.-
Methods inherited from class org.jboss.invocation.proxy.AbstractClassFactory
afterClassLoad, buildClassDefinition, defineClass, generateClass, getClassLoader, getClassName, getProtectionDomain, getSuperClass, getSuperClassName, isProxyClassDefined, isProxyClassDefined, newInstance
-
-
-
-
Field Detail
-
reflectionMetadataSource
protected final ReflectionMetadataSource reflectionMetadataSource
The metadata source used to generate the proxy
-
-
Constructor Detail
-
AbstractSubclassFactory
@Deprecated protected AbstractSubclassFactory(String className, Class<T> superClass, ClassLoader classLoader, ProtectionDomain protectionDomain, ReflectionMetadataSource reflectionMetadataSource)
Deprecated.Construct a new instance.- Parameters:
className- the class namesuperClass- the superclassclassLoader- the defining class loaderprotectionDomain- the protection domain
-
AbstractSubclassFactory
protected AbstractSubclassFactory(String className, Class<T> superClass, ClassLoader classLoader, org.jboss.classfilewriter.ClassFactory classFactory, ProtectionDomain protectionDomain, ReflectionMetadataSource reflectionMetadataSource)
Construct a new instance.- Parameters:
className- the class namesuperClass- the superclassclassLoader- the defining class loaderprotectionDomain- 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 overrideidentifier- The identifier of the method to overridecreator- TheMethodBodyCreatorused to create the method body- Returns:
trueif the method was successfully overridden,falseotherwise
-
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 overrideidentifier- The identifier of the method to overridecreator- TheMethodBodyCreatorused to create the method body- Returns:
falseif the method has already been overridden
-
cleanup
protected void cleanup()
Cleans up any resources left over from generating the class. Implementors should ensure they call super.cleanup();- Specified by:
cleanupin classAbstractClassFactory<T>
-
overridePublicMethods
protected void overridePublicMethods()
CallsoverridePublicMethods(MethodBodyCreator)with the defaultMethodBodyCreator.
-
overridePublicMethods
protected void overridePublicMethods(MethodBodyCreator override)
Overrides all public methods on the superclass. The givenMethodBodyCreatoris used to generate the class body. Note this will not overrideclone(),equals(Object),finalize(),hashCode()andtoString(), these should be overridden separately usingoverrideClone(MethodBodyCreator)overrideEquals(MethodBodyCreator)overrideFinalize(MethodBodyCreator)overrideHashcode(MethodBodyCreator)overrideToString(MethodBodyCreator)- Parameters:
override- the method body creator to use
-
overrideAllMethods
protected void overrideAllMethods()
CallsoverrideAllMethods(MethodBodyCreator)with the defaultMethodBodyCreator.
-
overrideAllMethods
protected void overrideAllMethods(MethodBodyCreator override)
Overrides all methods on the superclass with the exception ofequals(Object),hashCode(),toString()andfinalize(). The givenMethodBodyCreatoris used to generate the class body. Note this will not overrideclone(),equals(Object),finalize(),hashCode()andtoString(), these should be overridden separately usingoverrideClone(MethodBodyCreator)overrideEquals(MethodBodyCreator)overrideFinalize(MethodBodyCreator)overrideHashcode(MethodBodyCreator)overrideToString(MethodBodyCreator)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 defaultMethodBodyCreator.- Returns:
- true if the method was not already overridden
-
overrideEquals
protected boolean overrideEquals(MethodBodyCreator creator)
Override the equals method using the givenMethodBodyCreator.- 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 defaultMethodBodyCreator.- Returns:
- true if the method was not already overridden
-
overrideHashcode
protected boolean overrideHashcode(MethodBodyCreator creator)
Override the hashCode method using the givenMethodBodyCreator.- 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 defaultMethodBodyCreator- Returns:
- true if the method was not already overridden
-
overrideToString
protected boolean overrideToString(MethodBodyCreator creator)
Override the toString method using the givenMethodBodyCreator.- 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 defaultMethodBodyCreator.- Returns:
- true if the method was not already overridden
-
overrideFinalize
protected boolean overrideFinalize(MethodBodyCreator creator)
Override the finalize method using the givenMethodBodyCreator.- Parameters:
creator- the method body creator to use- Returns:
- true if the method was not already overridden
-
overrideClone
protected boolean overrideClone()
Override the clone method using the defaultMethodBodyCreator.- Returns:
- true if the method was not already overridden
-
overrideClone
protected boolean overrideClone(MethodBodyCreator creator)
Override the clone method using the givenMethodBodyCreator.- Parameters:
creator- the method body creator to use- Returns:
- true if the method was not already overridden
-
addInterface
protected boolean addInterface(Class<?> interfaceClass)
Adds an interface to the generated subclass, using the defaultMethodBodyCreatorto 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 givenMethodBodyCreatorto generate the method bodies- Parameters:
override- the method body creator to useinterfaceClass- 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 defaultConstructorBodyCreator
-
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 defaultMethodBodyCreatorto use when creating overridden methods.- Returns:
- the default method body creator
-
getDefaultConstructorOverride
public ConstructorBodyCreator getDefaultConstructorOverride()
Returns the defaultConstructorBodyCreatorto use then creating overridden subclasses.- Returns:
- the default constructor body creator
-
-