public class ProxyFactory<T> extends Object
BeanInstance
. All proxies implement the Proxy
interface.Modifier and Type | Field and Description |
---|---|
protected static String |
ADDING_METHOD_LOG_PREFIX |
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 |
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 LocLogger |
log |
protected static String |
METHOD_HANDLER_FIELD_NAME |
static String |
PROXY_SUFFIX |
Constructor and Description |
---|
ProxyFactory(Class<?> proxiedBeanType,
Set<? extends Type> typeClosure,
Bean<?> bean)
created a new proxy factory from a bean instance.
|
ProxyFactory(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
|
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.
|
protected void |
addMethods(ClassFile proxyClassType) |
protected void |
addMethodsFromClass(ClassFile proxyClassType) |
protected void |
addSerializationSupport(ClassFile proxyClassType)
Adds special serialization code.
|
protected void |
addSpecialMethods(ClassFile proxyClassType)
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) |
protected void |
createInterceptorBody(ClassMethod classMethod,
MethodInformation method)
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) |
protected void |
generateEqualsMethod(ClassFile proxyClassType)
Generate the body of the proxies equals method.
|
protected void |
generateHashCodeMethod(ClassFile proxyClassType)
Generate the body of the proxies hashCode 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) |
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 static void |
invokeMethodHandler(ClassMethod classMethod,
MethodInformation method,
boolean addReturnInstruction,
BytecodeMethodResolver bytecodeMethodResolver)
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.
|
protected boolean |
isUsingUnsafeInstantiators() |
static ClassLoader |
resolveClassLoaderForBeanProxy(Class<?> proxiedType,
Proxies.TypeInfo typeInfo)
Figures out the correct class loader to use for a proxy for a given bean
|
static <T> void |
setBeanInstance(T proxy,
BeanInstance beanInstance,
Bean<?> bean)
Convenience method to set the underlying bean instance for a proxy.
|
protected static final LocLogger log
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 LJAVA_LANG_STRING
protected static final String LJAVA_LANG_THREAD_LOCAL
protected static final String INIT_METHOD_NAME
protected static final String ADDING_METHOD_LOG_PREFIX
protected static final String METHOD_HANDLER_FIELD_NAME
public ProxyFactory(Class<?> proxiedBeanType, Set<? extends Type> typeClosure, Bean<?> bean)
public ProxyFactory(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 classprotected boolean isCreatingProxy()
public void addInterface(Class<?> newInterface)
newInterface
- an interfacepublic T create(BeanInstance beanInstance)
beanInstance
- the bean instancepublic Class<T> getProxyClass()
protected String getBaseProxyName()
public static boolean isProxy(Object proxySuspect)
proxySuspect
- the object suspected of being a proxypublic static <T> void setBeanInstance(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 void addMethods(ClassFile proxyClassType)
protected void addSerializationSupport(ClassFile proxyClassType)
proxyClassType
- the Javassist class for the proxy classprotected void addMethodsFromClass(ClassFile proxyClassType)
protected void generateHashCodeMethod(ClassFile proxyClassType)
protected void generateEqualsMethod(ClassFile proxyClassType)
proxyClassType
- The class fileprotected void createSpecialMethodBody(ClassMethod proxyClassType, MethodInformation method)
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)
protected void createInterceptorBody(ClassMethod classMethod, MethodInformation method)
classMethod
- the class methodmethod
- any JLR methodprotected static void invokeMethodHandler(ClassMethod classMethod, MethodInformation method, boolean addReturnInstruction, BytecodeMethodResolver bytecodeMethodResolver)
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)
proxyClassType
- the Javassist class description for the proxy typepublic Class<?> getBeanType()
public Bean<?> getBean()
public static ClassLoader resolveClassLoaderForBeanProxy(Class<?> proxiedType, Proxies.TypeInfo typeInfo)
protected boolean isUsingUnsafeInstantiators()
Copyright © 2013 Seam Framework. All Rights Reserved.