public class ProxyFactory<T> extends Object implements PrivilegedAction<T>
BeanInstance
. All proxies implement the Proxy
interface.Modifier and Type | Field and Description |
---|---|
static String |
CONSTRUCTED_FLAG_NAME |
protected static BytecodeMethodResolver |
DEFAULT_METHOD_RESOLVER |
static String |
DEFAULT_PROXY_PACKAGE |
protected static String |
INIT_METHOD_NAME |
protected static String |
LBEAN_IDENTIFIER |
protected static String |
LJAVA_LANG_BYTE |
protected static String |
LJAVA_LANG_CLASS |
protected static String |
LJAVA_LANG_OBJECT |
protected static String |
LJAVA_LANG_REFLECT_METHOD |
protected static String |
LJAVA_LANG_STRING |
protected static String |
LJAVA_LANG_THREAD_LOCAL |
protected static String |
METHOD_HANDLER_FIELD_NAME |
static String |
PROXY_SUFFIX |
Constructor and Description |
---|
ProxyFactory(String contextId,
Class<?> proxiedBeanType,
Set<? extends Type> typeClosure,
Bean<?> bean)
created a new proxy factory from a bean instance.
|
ProxyFactory(String contextId,
Class<?> proxiedBeanType,
Set<? extends Type> typeClosure,
Bean<?> bean,
boolean forceSuperClass) |
ProxyFactory(String contextId,
Class<?> proxiedBeanType,
Set<? extends Type> typeClosure,
String proxyName,
Bean<?> bean)
Creates a new proxy factory when the name of the proxy class is already
known, such as during de-serialization
|
ProxyFactory(String contextId,
Class<?> proxiedBeanType,
Set<? extends Type> typeClosure,
String proxyName,
Bean<?> bean,
boolean forceSuperClass) |
Modifier and Type | Method and Description |
---|---|
protected void |
addAdditionalInterfaces(Set<Class<?>> interfaces)
Sub classes may override to specify additional interfaces the proxy should
implement
|
protected void |
addConstructedGuardToMethodBody(ClassMethod classMethod)
Adds the following code to a delegating method:
if(!this.constructed) return super.thisMethod()
This means that the proxy will not start to delegate to the underlying
bean instance until after the constructor has finished. |
protected void |
addConstructors(ClassFile proxyClassType,
List<DeferredBytecode> initialValueBytecode)
Adds a constructor for the proxy for each constructor declared by the base
bean type.
|
protected void |
addFields(ClassFile proxyClassType,
List<DeferredBytecode> initialValueBytecode) |
void |
addInterface(Class<?> newInterface)
Adds an additional interface that the proxy should implement.
|
void |
addInterfacesFromTypeClosure(Set<? extends Type> typeClosure,
Class<?> proxiedBeanType) |
protected void |
addMethods(ClassFile proxyClassType,
ClassMethod staticConstructor) |
protected void |
addMethodsFromClass(ClassFile proxyClassType,
ClassMethod staticConstructor) |
protected void |
addSerializationSupport(ClassFile proxyClassType)
Adds special serialization code.
|
protected void |
addSpecialMethods(ClassFile proxyClassType,
ClassMethod staticConstructor)
Adds methods requiring special implementations rather than just
delegation.
|
T |
create(BeanInstance beanInstance)
Method to create a new proxy that wraps the bean instance.
|
protected void |
createForwardingMethodBody(ClassMethod classMethod,
MethodInformation method,
ClassMethod staticConstructor) |
protected void |
createInterceptorBody(ClassMethod classMethod,
MethodInformation method,
ClassMethod staticConstructor)
Creates the given method on the proxy class where the implementation
forwards the call directly to the method handler.
|
protected void |
createSpecialMethodBody(ClassMethod proxyClassType,
MethodInformation method,
ClassMethod staticConstructor) |
protected void |
generateEqualsMethod(ClassFile proxyClassType)
Generate the body of the proxies equals method.
|
protected void |
generateGetMethodHandlerBody(ClassMethod method) |
protected void |
generateHashCodeMethod(ClassFile proxyClassType)
Generate the body of the proxies hashCode method.
|
protected void |
generateSetMethodHandlerBody(ClassMethod method) |
Set<Class<?>> |
getAdditionalInterfaces() |
protected String |
getBaseProxyName()
Returns the package and base name for the proxy class.
|
Bean<?> |
getBean() |
Class<?> |
getBeanType() |
protected Class<T> |
getCachedProxyClass(String proxyClassName) |
String |
getContextId() |
protected void |
getMethodHandlerField(ClassFile file,
CodeAttribute b) |
protected Class<? extends MethodHandler> |
getMethodHandlerType() |
Class<T> |
getProxyClass()
Produces or returns the existing proxy class.
|
protected String |
getProxyNameSuffix()
Returns a suffix to append to the name of the proxy class.
|
protected void |
invokeMethodHandler(ClassMethod classMethod,
MethodInformation method,
boolean addReturnInstruction,
BytecodeMethodResolver bytecodeMethodResolver,
ClassMethod staticConstructor)
calls methodHandler.invoke for a given method
|
protected boolean |
isCreatingProxy() |
static boolean |
isProxy(Object proxySuspect)
Convenience method to determine if an object is a proxy generated by this
factory or any derived factory.
|
static ClassLoader |
resolveClassLoaderForBeanProxy(String contextId,
Class<?> proxiedType,
Proxies.TypeInfo typeInfo)
Figures out the correct class loader to use for a proxy for a given bean
|
T |
run() |
static <T> void |
setBeanInstance(String contextId,
T proxy,
BeanInstance beanInstance,
Bean<?> bean)
Convenience method to set the underlying bean instance for a proxy.
|
public static final String PROXY_SUFFIX
public static final String DEFAULT_PROXY_PACKAGE
public static final String CONSTRUCTED_FLAG_NAME
protected static final BytecodeMethodResolver DEFAULT_METHOD_RESOLVER
protected static final String LJAVA_LANG_REFLECT_METHOD
protected static final String LJAVA_LANG_BYTE
protected static final String LJAVA_LANG_CLASS
protected static final String LJAVA_LANG_OBJECT
protected static final String LBEAN_IDENTIFIER
protected static final String LJAVA_LANG_STRING
protected static final String LJAVA_LANG_THREAD_LOCAL
protected static final String INIT_METHOD_NAME
protected static final String METHOD_HANDLER_FIELD_NAME
public ProxyFactory(String contextId, Class<?> proxiedBeanType, Set<? extends Type> typeClosure, Bean<?> bean)
public ProxyFactory(String contextId, Class<?> proxiedBeanType, Set<? extends Type> typeClosure, Bean<?> bean, boolean forceSuperClass)
public ProxyFactory(String contextId, Class<?> proxiedBeanType, Set<? extends Type> typeClosure, String proxyName, Bean<?> bean)
proxiedBeanType
- the super-class for this proxy classtypeClosure
- the bean types of the beanproxyName
- the name of the proxy classpublic void addInterfacesFromTypeClosure(Set<? extends Type> typeClosure, Class<?> proxiedBeanType)
protected boolean isCreatingProxy()
public void addInterface(Class<?> newInterface)
newInterface
- an interfacepublic T create(BeanInstance beanInstance)
beanInstance
- the bean instancepublic T run()
run
in interface PrivilegedAction<T>
public Class<T> getProxyClass()
protected String getBaseProxyName()
public static boolean isProxy(Object proxySuspect)
proxySuspect
- the object suspected of being a proxypublic static <T> void setBeanInstance(String contextId, T proxy, BeanInstance beanInstance, Bean<?> bean)
proxy
- the proxy instancebeanInstance
- the instance of the beanprotected String getProxyNameSuffix()
protected void addAdditionalInterfaces(Set<Class<?>> interfaces)
protected void addConstructors(ClassFile proxyClassType, List<DeferredBytecode> initialValueBytecode)
proxyClassType
- the Javassist class for the proxyinitialValueBytecode
- protected void addFields(ClassFile proxyClassType, List<DeferredBytecode> initialValueBytecode)
protected Class<? extends MethodHandler> getMethodHandlerType()
protected void addMethods(ClassFile proxyClassType, ClassMethod staticConstructor)
protected void addSerializationSupport(ClassFile proxyClassType)
proxyClassType
- the Javassist class for the proxy classprotected void addMethodsFromClass(ClassFile proxyClassType, ClassMethod staticConstructor)
protected void generateHashCodeMethod(ClassFile proxyClassType)
protected void generateEqualsMethod(ClassFile proxyClassType)
proxyClassType
- The class fileprotected void createSpecialMethodBody(ClassMethod proxyClassType, MethodInformation method, ClassMethod staticConstructor)
protected void addConstructedGuardToMethodBody(ClassMethod classMethod)
if(!this.constructed) return super.thisMethod()
This means that the proxy will not start to delegate to the underlying
bean instance until after the constructor has finished.protected void createForwardingMethodBody(ClassMethod classMethod, MethodInformation method, ClassMethod staticConstructor)
protected void createInterceptorBody(ClassMethod classMethod, MethodInformation method, ClassMethod staticConstructor)
classMethod
- the class methodmethod
- any JLR methodprotected void invokeMethodHandler(ClassMethod classMethod, MethodInformation method, boolean addReturnInstruction, BytecodeMethodResolver bytecodeMethodResolver, ClassMethod staticConstructor)
method
- The method informationaddReturnInstruction
- set to true you want to return the result of
the method invocationbytecodeMethodResolver
- The resolver that returns the method to invokeprotected void addSpecialMethods(ClassFile proxyClassType, ClassMethod staticConstructor)
proxyClassType
- the Javassist class description for the proxy typeprotected void generateSetMethodHandlerBody(ClassMethod method)
protected void generateGetMethodHandlerBody(ClassMethod method)
public Class<?> getBeanType()
public Bean<?> getBean()
public String getContextId()
public static ClassLoader resolveClassLoaderForBeanProxy(String contextId, Class<?> proxiedType, Proxies.TypeInfo typeInfo)
protected void getMethodHandlerField(ClassFile file, CodeAttribute b)
Copyright © 2015. All Rights Reserved.