org.apache.commons.proxy
Class ProxyFactory

java.lang.Object
  extended by org.apache.commons.proxy.ProxyFactory
Direct Known Subclasses:
AbstractSubclassingProxyFactory

public class ProxyFactory
extends Object

A ProxyFactory can be used to create three different "flavors" of proxy objects.

Originally, the ProxyFactory class was an interface. However, to allow for future changes to the class without breaking binary or semantic compatibility, it has been changed to a concrete class.

Note: This class uses Java reflection. For more efficient proxies, try using either CglibProxyFactory or JavassistProxyFactory instead.

Since:
1.0
Author:
James Carman

Constructor Summary
ProxyFactory()
           
 
Method Summary
 boolean canProxy(Class[] proxyClasses)
          Returns true if all proxyClasses are interfaces.
 Object createDelegatorProxy(ClassLoader classLoader, ObjectProvider delegateProvider, Class[] proxyClasses)
          Creates a proxy which delegates to the object provided by delegateProvider.
 Object createDelegatorProxy(ObjectProvider delegateProvider, Class[] proxyClasses)
          Creates a proxy which delegates to the object provided by delegateProvider.
 Object createInterceptorProxy(ClassLoader classLoader, Object target, Interceptor interceptor, Class[] proxyClasses)
          Creates a proxy which passes through a interceptor before eventually reaching the target object.
 Object createInterceptorProxy(Object target, Interceptor interceptor, Class[] proxyClasses)
          Creates a proxy which passes through a interceptor before eventually reaching the target object.
 Object createInvokerProxy(ClassLoader classLoader, Invoker invoker, Class[] proxyClasses)
          Creates a proxy which uses the provided Invoker to handle all method invocations.
 Object createInvokerProxy(Invoker invoker, Class[] proxyClasses)
          Creates a proxy which uses the provided Invoker to handle all method invocations.
 
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

canProxy

public boolean canProxy(Class[] proxyClasses)
Returns true if all proxyClasses are interfaces.

Parameters:
proxyClasses - the proxy classes
Returns:
true if all proxyClasses are interfaces

createDelegatorProxy

public Object createDelegatorProxy(ObjectProvider delegateProvider,
                                   Class[] proxyClasses)
Creates a proxy which delegates to the object provided by delegateProvider. The proxy will be generated using the current thread's "context class loader."

Parameters:
delegateProvider - the delegate provider
proxyClasses - the interfaces that the proxy should implement
Returns:
a proxy which delegates to the object provided by the target object provider

createDelegatorProxy

public Object createDelegatorProxy(ClassLoader classLoader,
                                   ObjectProvider delegateProvider,
                                   Class[] proxyClasses)
Creates a proxy which delegates to the object provided by delegateProvider.

Parameters:
classLoader - the class loader to use when generating the proxy
delegateProvider - the delegate provider
proxyClasses - the interfaces that the proxy should implement
Returns:
a proxy which delegates to the object provided by the target delegateProvider>

createInterceptorProxy

public Object createInterceptorProxy(Object target,
                                     Interceptor interceptor,
                                     Class[] proxyClasses)
Creates a proxy which passes through a interceptor before eventually reaching the target object. The proxy will be generated using the current thread's "context class loader."

Parameters:
target - the target object
interceptor - the method interceptor
proxyClasses - the interfaces that the proxy should implement
Returns:
a proxy which passes through a interceptor before eventually reaching the target object.

createInterceptorProxy

public Object createInterceptorProxy(ClassLoader classLoader,
                                     Object target,
                                     Interceptor interceptor,
                                     Class[] proxyClasses)
Creates a proxy which passes through a interceptor before eventually reaching the target object.

Parameters:
classLoader - the class loader to use when generating the proxy
target - the target object
interceptor - the method interceptor
proxyClasses - the interfaces that the proxy should implement.
Returns:
a proxy which passes through a interceptor before eventually reaching the target object.

createInvokerProxy

public Object createInvokerProxy(Invoker invoker,
                                 Class[] proxyClasses)
Creates a proxy which uses the provided Invoker to handle all method invocations. The proxy will be generated using the current thread's "context class loader."

Parameters:
invoker - the invoker
proxyClasses - the interfaces that the proxy should implement
Returns:
a proxy which uses the provided Invoker to handle all method invocations

createInvokerProxy

public Object createInvokerProxy(ClassLoader classLoader,
                                 Invoker invoker,
                                 Class[] proxyClasses)
Creates a proxy which uses the provided Invoker to handle all method invocations.

Parameters:
classLoader - the class loader to use when generating the proxy
invoker - the invoker
proxyClasses - the interfaces that the proxy should implement
Returns:
a proxy which uses the provided Invoker to handle all method invocations


Copyright © 2005-2008 The Apache Software Foundation. All Rights Reserved.