org.progeeks.util
Class DelegateInvocationHandler

java.lang.Object
  extended by org.progeeks.util.DelegateInvocationHandler
All Implemented Interfaces:
java.lang.reflect.InvocationHandler

public abstract class DelegateInvocationHandler
extends java.lang.Object
implements java.lang.reflect.InvocationHandler

Adapts an interface or set of interfaces to a delegate object allowing interception of specific methods for local handling. This is useful for cases where interface implementations are too numerous or are unknown until runtime but it is still desirable to override specific methods on those implementations. Right now, the delegate object must implement the same interfaces that this proxy does but that may be relaxed in the future to make this class more like AdapterInvocationHandler in that respect. This class is abstract because it must be subclassed to provide the specific method overrides for the delegate object.

Version:
$Revision: 1.3 $
Author:
Paul Speed

Constructor Summary
protected DelegateInvocationHandler(java.lang.Object delegate)
          Creates a new dynamic proxy that will pass methods defined in any public interface for the delegate to any methods defined on this local implementation but will otherwise pass all methods on to the delegate.
protected DelegateInvocationHandler(java.lang.Object delegate, java.lang.Class[] interfaces)
          Creates a new dynamic proxy that will pass methods defined in the specified interfaces to any methods defined on this local implementation but will otherwise pass all methods on to the delegate.
 
Method Summary
protected  java.lang.Object getDelegate()
           
protected  java.lang.Class[] getMappedInterfaces()
           
 java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
           
static void main(java.lang.String[] args)
           
static java.lang.Object newProxy(java.lang.ClassLoader loader, DelegateInvocationHandler handler)
          Creates a new dynamic proxy that implements the interfaces defined in the handler and passes the method calls directly to the specified DelegateInvocationHandler instance.
static java.lang.Object newProxy(DelegateInvocationHandler handler)
          Creates a new dynamic proxy that implements the interfaces defined in the handler and passes the method calls directly to the specified DelegateInvocationHandler instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegateInvocationHandler

protected DelegateInvocationHandler(java.lang.Object delegate,
                                    java.lang.Class[] interfaces)
Creates a new dynamic proxy that will pass methods defined in the specified interfaces to any methods defined on this local implementation but will otherwise pass all methods on to the delegate.


DelegateInvocationHandler

protected DelegateInvocationHandler(java.lang.Object delegate)
Creates a new dynamic proxy that will pass methods defined in any public interface for the delegate to any methods defined on this local implementation but will otherwise pass all methods on to the delegate.

Method Detail

getDelegate

protected java.lang.Object getDelegate()

getMappedInterfaces

protected java.lang.Class[] getMappedInterfaces()

newProxy

public static java.lang.Object newProxy(DelegateInvocationHandler handler)
Creates a new dynamic proxy that implements the interfaces defined in the handler and passes the method calls directly to the specified DelegateInvocationHandler instance. This is just a convenience method that calls Proxy.newProxyInstance().


newProxy

public static java.lang.Object newProxy(java.lang.ClassLoader loader,
                                        DelegateInvocationHandler handler)
Creates a new dynamic proxy that implements the interfaces defined in the handler and passes the method calls directly to the specified DelegateInvocationHandler instance. This is just a convenience method that calls Proxy.newProxyInstance().


invoke

public java.lang.Object invoke(java.lang.Object proxy,
                               java.lang.reflect.Method method,
                               java.lang.Object[] args)
                        throws java.lang.Throwable
Specified by:
invoke in interface java.lang.reflect.InvocationHandler
Throws:
java.lang.Throwable

main

public static void main(java.lang.String[] args)


Copyright © 2002-2003 Paul Speed. All Rights Reserved.