Class DelegatorProxy

java.lang.Object
de.tsl2.nano.util.DelegatorProxy
All Implemented Interfaces:
Serializable, InvocationHandler

public class DelegatorProxy extends Object implements InvocationHandler, Serializable
generic delegator to be usable as base class for simple delegation implementations. the delegator doesn't have to implement the given interface, but has to provide the desired implementation with a method thats name and arguments have to match the interface method.

if you give more than one delegator, they will be asked in the given order to have the desired method - to invoke it.

if no delegator provides the called method, the standard proxy implementation will be used.

the delegator is also usable as instance extender on runtime.

 example:
     public void setBeanFinder(final IBeanFinder<T, Object> beanFinder) {
         Object internalBeanFinder = new Object() {
             Collection getData(T from, Object to) {
                 collection = (COLLECTIONTYPE) beanFinder.getData(from, to);
                 return collection;
             };
         };
         this.beanFinder = DelegatorProxy.delegator(IBeanFinder.class, internalBeanFinder, beanFinder);
     }
 
 
To work directly on interface implementations, use MultipleInheritanceProxy.
Version:
$Revision$
Author:
Thomas Schneider
See Also:
  • Constructor Details

    • DelegatorProxy

      protected DelegatorProxy(Object... delegators)
  • Method Details

    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      Specified by:
      invoke in interface InvocationHandler
      Throws:
      Throwable
    • delegator

      public static final <T> T delegator(Class<T> proxyInterface, Object... delegators)
      delegator
      Type Parameters:
      T -
      Parameters:
      proxyInterface -
      delegators -
      Returns:
    • delegator

      public static final Object delegator(Class[] proxyInterfaces, Object... delegators)
      delegator
      Type Parameters:
      T -
      Parameters:
      proxyInterfaces -
      delegators -
      Returns: