org.clazzes.util.aop
Class ProxyFactory

java.lang.Object
  extended by org.clazzes.util.aop.ProxyFactory

public class ProxyFactory
extends Object

A lightweight proxy factory for instantiating intercepted instances of interface implementations.

If you need special sets of interceptors and multiple implementing interfaces, use getProxy() for creating proxies.

For most cases it is sufficient to use getTypedProxy(Object, Class), which allows you to use a singleton ProxyFactory for generating multiple proxies.


Constructor Summary
ProxyFactory()
           
 
Method Summary
 ClassLoader getClassLoader()
           
 Pattern getExcludeMethods()
           
 Pattern getIncludeMethods()
           
 org.aopalliance.intercept.MethodInterceptor[] getInterceptors()
           
 Class[] getInterfaces()
           
 Object getMultiTypedProxy(Object _target, Class[] ifaces)
          This method facilitates the use of a proxy singleton to generate more proxies for different targets with a changing set of interfaces but with the same set of interceptors.
 Object getProxy()
           
 Object getTarget()
           
<T> T
getTypedProxy(Object _target, Class<T> iface)
          This method facilitates the use of a proxy singleton to generate more proxies for different targets with changing interfaces but with the same set of interceptors.
 void setClassLoader(ClassLoader classLoader)
           
 void setExcludeMethods(Pattern excludeMethods)
           
 void setIncludeMethods(Pattern includeMethods)
           
 void setInterceptor(org.aopalliance.intercept.MethodInterceptor interceptor)
          Convenience setter, which sets the invoked interceptors to a single instance.
 void setInterceptors(org.aopalliance.intercept.MethodInterceptor[] interceptors)
           
 void setInterface(Class iface)
          Convenience setter, which sets the proxy-implemented interfaces to a single interface.
 void setInterfaces(Class[] interfaces)
           
 void setTarget(Object target)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProxyFactory

public ProxyFactory()
Method Detail

getTypedProxy

public <T> T getTypedProxy(Object _target,
                           Class<T> iface)

This method facilitates the use of a proxy singleton to generate more proxies for different targets with changing interfaces but with the same set of interceptors. If your interceptors are different for each target, use separate ProxyFactory instances with different bean configurations.

This method ignores the target and interfaces bean properties.

Parameters:
_target - The target to wrap.
iface - The interface of the returned proxy.
Returns:
A new JDK proxy which implements the given interface and involves the specified interceptors.

getProxy

public Object getProxy()
Returns:
a new proxy, which implements the given interfaces and involves the specified interceptors.

getMultiTypedProxy

public Object getMultiTypedProxy(Object _target,
                                 Class[] ifaces)

This method facilitates the use of a proxy singleton to generate more proxies for different targets with a changing set of interfaces but with the same set of interceptors. If your interceptors are different for each target, use separate ProxyFactory instances with different bean configurations.

This method ignores the target and interfaces bean properties.

Parameters:
_target - The target to wrap.
ifaces - The list of interface to be implemented by the returned proxy.
Returns:
A new JDK proxy which implements the given interface and involves the specified interceptors.

getTarget

public Object getTarget()
Returns:
The invocation target.

setTarget

public void setTarget(Object target)
Parameters:
target - the target to set. There's no need to call this method, if you use getTypedProxy(Object, Class).

getClassLoader

public ClassLoader getClassLoader()
Returns:
The class loader to set. If null, the class loader of the target object should be used.

setClassLoader

public void setClassLoader(ClassLoader classLoader)
Parameters:
classLoader - the classLoader to set

getInterfaces

public Class[] getInterfaces()
Returns:
the interfaces

setInterfaces

public void setInterfaces(Class[] interfaces)
Parameters:
interfaces - the interfaces, which are implemented by the generated proxy to set. There's no need to call this method, if you use getTypedProxy(Object, Class).

setInterface

public void setInterface(Class iface)
Convenience setter, which sets the proxy-implemented interfaces to a single interface. There's no need to call this method, if you use getTypedProxy(Object, Class).

Parameters:
iface - the interface to set

getInterceptors

public org.aopalliance.intercept.MethodInterceptor[] getInterceptors()
Returns:
the interceptors invoked in the given order. The first interceptor is the outermost one.

setInterceptors

public void setInterceptors(org.aopalliance.intercept.MethodInterceptor[] interceptors)
Parameters:
interceptors - the interceptors to set

setInterceptor

public void setInterceptor(org.aopalliance.intercept.MethodInterceptor interceptor)
Convenience setter, which sets the invoked interceptors to a single instance.

Parameters:
interceptor - the interceptor to set

getIncludeMethods

public Pattern getIncludeMethods()
Returns:
An optional regular expression for selecting methods, which are intercepted. If null, all interface methods are included.

setIncludeMethods

public void setIncludeMethods(Pattern includeMethods)
Parameters:
includeMethods - the includeMethods to set

getExcludeMethods

public Pattern getExcludeMethods()
Returns:
An optional regular expression for omitting methods, which are intercepted. If null, no interface method is omitted.

setExcludeMethods

public void setExcludeMethods(Pattern excludeMethods)
Parameters:
excludeMethods - the excludeMethods to set


Copyright © 2013. All Rights Reserved.