com.thoughtworks.proxy.toys.delegate
Class DelegatingInvoker<T>

java.lang.Object
  extended by com.thoughtworks.proxy.toys.delegate.DelegatingInvoker<T>
All Implemented Interfaces:
Invoker, Serializable
Direct Known Subclasses:
HotSwappingInvoker, Pool.PoolingInvoker, PrivilegingInvoker

public class DelegatingInvoker<T>
extends Object
implements Invoker

Invoker that delegates method calls to an object.

This forms the basis of many other proxy toys. The delegation behavior was factored out of HotSwappingInvoker.

Since:
0.1
Author:
Aslak Hellesøy, Paul Hammant, Dan North, Jörg Schaible
See Also:
HotSwappingInvoker, Serialized Form

Constructor Summary
DelegatingInvoker(ProxyFactory proxyFactory, ObjectReference<T> delegateReference, DelegationMode delegationMode)
          Construct a DelegatingInvoker.
DelegatingInvoker(T delegate)
          Construct a DelegatingInvoker with a StandardProxyFactory and DelegationMode.SIGNATURE.
 
Method Summary
protected  T delegate()
          Retrieve the delegated object in derived classes.
 boolean equals(Object obj)
          Compares a DelegatingInvoker with another one for equality.
protected  ObjectReference<T> getDelegateReference()
          Retrieve the ObjectReference of the delegate.
protected  Method getMethodToInvoke(Method method, Object[] args)
          Lookup a matching method.
protected  ProxyFactory getProxyFactory()
          Retrieve the ProxyFactory to use.
 int hashCode()
           
 Object invoke(Object proxy, Method method, Object[] args)
          Invocation of a method of the proxied object.
protected  Object invokeOnDelegate(Method method, Object[] args)
          Invoke the given method on the delegate.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatingInvoker

public DelegatingInvoker(ProxyFactory proxyFactory,
                         ObjectReference<T> delegateReference,
                         DelegationMode delegationMode)
Construct a DelegatingInvoker.

Parameters:
proxyFactory - the ProxyFactory to use
delegateReference - the ObjectReference of the delegate
delegationMode - one of the delegation modes
Throws:
IllegalArgumentException - if the delegationMode is not one of the predefined constants of Delegating
Since:
1.0

DelegatingInvoker

public DelegatingInvoker(T delegate)
Construct a DelegatingInvoker with a StandardProxyFactory and DelegationMode.SIGNATURE.

Parameters:
delegate - the delegated object
Since:
0.1
Method Detail

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Description copied from interface: Invoker
Invocation of a method of the proxied object.

Specified by:
invoke in interface Invoker
Parameters:
proxy - the proxy instance.
method - the method to invoke.
args - the arguments of the method.
Returns:
the result of the invoked method.
Throws:
Throwable - if the invoked method has thrown.

delegate

protected T delegate()
Retrieve the delegated object in derived classes.

Returns:
the delegated object

getMethodToInvoke

protected Method getMethodToInvoke(Method method,
                                   Object[] args)
Lookup a matching method. The lookup will only be done once for every method called on the proxy.

Parameters:
method - the invoked method on the proxy
args - the arguments for the invocation
Returns:
the matching method
Throws:
DelegationException - if no matching method can be found
Since:
0.2

invokeOnDelegate

protected Object invokeOnDelegate(Method method,
                                  Object[] args)
                           throws InvocationTargetException
Invoke the given method on the delegate.

Parameters:
method - the method to invoke
args - the arguments for the invocation
Returns:
the method's result
Throws:
InvocationTargetException - if the invoked method throws any exception
Since:
0.1

getDelegateReference

protected ObjectReference<T> getDelegateReference()
Retrieve the ObjectReference of the delegate.

Returns:
the reference of the delegate
Since:
0.2

getProxyFactory

protected ProxyFactory getProxyFactory()
Retrieve the ProxyFactory to use.

Returns:
the ProxyFactory
Since:
0.2

equals

public boolean equals(Object obj)
Compares a DelegatingInvoker with another one for equality. Two DelegatingInvoker are equal, if they have both the same delegation mode and their delegees are equal.

Overrides:
equals in class Object
Since:
0.2
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2005-2010 Codehaus. All Rights Reserved.