org.javasimon.proxy
Class DelegatingProxyFactory<T>

java.lang.Object
  extended by org.javasimon.proxy.DelegatingProxyFactory<T>
Type Parameters:
T - Type of the wrapped class
All Implemented Interfaces:
InvocationHandler, Delegating<T>
Direct Known Subclasses:
ExecutorProxyFactory, StopwatchProxyFactory

public class DelegatingProxyFactory<T>
extends Object
implements InvocationHandler, Delegating<T>

Produces proxy that wrap and existing class using Proxy class. This class is used to do lightweight AOP.

Author:
gerald

Field Summary
private  T delegate
          Wrapped class and concrete implementation
 
Constructor Summary
DelegatingProxyFactory(T delegate)
          Main constructor
 
Method Summary
 T getDelegate()
          Return Wrapped class and concrete implementation.
protected  Object invoke(DelegatingMethodInvocation<T> delegatingMethodInvocation)
          Method to override in child classes
 Object invoke(Object proxy, Method method, Object[] args)
          
 Object newProxy(Class<?>... interfaces)
          Create a proxy using given classloader and interfaces.
<X> X
newProxy(Class<X> interfaces)
          Create a proxy using given classloader and interfaces
 Object newProxy(ClassLoader classLoader, Class<?>... interfaces)
          Create a proxy using given classloader and interfaces
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

delegate

private final T delegate
Wrapped class and concrete implementation

Constructor Detail

DelegatingProxyFactory

public DelegatingProxyFactory(T delegate)
Main constructor

Parameters:
delegate - Wrapped class and concrete implementation
Method Detail

invoke

public final Object invoke(Object proxy,
                           Method method,
                           Object[] args)
                    throws Throwable

Specified by:
invoke in interface InvocationHandler
Throws:
Throwable

invoke

protected Object invoke(DelegatingMethodInvocation<T> delegatingMethodInvocation)
                 throws Throwable
Method to override in child classes

Parameters:
delegatingMethodInvocation - Method invocation (arguments, method name, etc.)
Returns:
Method invocation results
Throws:
Throwable - Method invocation raised exception

getDelegate

public T getDelegate()
Return Wrapped class and concrete implementation.

Specified by:
getDelegate in interface Delegating<T>
Returns:
Wrapped object

newProxy

public Object newProxy(ClassLoader classLoader,
                       Class<?>... interfaces)
Create a proxy using given classloader and interfaces

Parameters:
classLoader - Class loader
interfaces - Interfaces to implement
Returns:
Proxy

newProxy

public Object newProxy(Class<?>... interfaces)
Create a proxy using given classloader and interfaces. Current thread class loaded is used as default classload.

Parameters:
interfaces - Interfaces to implement
Returns:
Proxy

newProxy

public <X> X newProxy(Class<X> interfaces)
Create a proxy using given classloader and interfaces

Parameters:
classLoader - Class loader
interfaces - Interface to implement
Returns:
Proxy


Copyright © 2013. All Rights Reserved.