mondrian.util
Class DelegatingInvocationHandler

java.lang.Object
  extended by mondrian.util.DelegatingInvocationHandler
All Implemented Interfaces:
java.lang.reflect.InvocationHandler
Direct Known Subclasses:
MondrianOlap4jCell.MyDelegatingInvocationHandler

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

A class derived from DelegatingInvocationHandler handles a method call by looking for a method in itself with identical parameters. If no such method is found, it forwards the call to a fallback object, which must implement all of the interfaces which this proxy implements.

It is useful in creating a wrapper class around an interface which may change over time.

Example:

import java.sql.Connection;
 Connection connection = ...;
 Connection tracingConnection = (Connection) Proxy.newProxyInstance(
     null,
     new Class[] {Connection.class},
     new DelegatingInvocationHandler() {
         protected Object getTarget() {
             return connection;
         }
         Statement createStatement() {
             System.out.println("statement created");
             return connection.createStatement();
         }
     });

Version:
$Id: //open/mondrian/src/main/mondrian/util/DelegatingInvocationHandler.java#7 $
Author:
jhyde

Constructor Summary
DelegatingInvocationHandler()
           
 
Method Summary
protected  java.lang.Object getTarget()
          Returns the object to forward method calls to, should the derived class not implement the method.
 java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DelegatingInvocationHandler

public DelegatingInvocationHandler()
Method Detail

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

getTarget

protected java.lang.Object getTarget()
Returns the object to forward method calls to, should the derived class not implement the method. Generally, this object will be a member of the derived class, supplied as a parameter to its constructor.

The default implementation returns null, which will cause the invoke(Object, java.lang.reflect.Method, Object[]) method to throw an UnsupportedOperationException if the derived class does not have the required method.

Returns:
object to forward method calls to

Get Mondrian at SourceForge.net. Fast, secure and free Open Source software downloads