org.sape.carbon.core.util.reflection
Class GenericProxy

java.lang.Object
  |
  +--org.sape.carbon.core.util.reflection.GenericProxy
All Implemented Interfaces:
InvocationHandler
Direct Known Subclasses:
AbstractConfigurationProxy, DefaultComponentProxyInvocationHandler, DefaultConfigurationInterceptor, RemoteMBeanServerProxy

public abstract class GenericProxy
extends Object
implements InvocationHandler

This generic implementation of a DynamicProxy invocation handler will provide the basics of object method handling for the methods hashCode, equals and toString. Any other method calls will be forwarded to subclasses for implementation.

Invocation handlers wishing to provide specialized implementations of the follow methods: { hashCode, toString, equals} should override those versions of the methods defined in this class that start with the key proxy. Copyright 2002 Sapient

Version:
$Revision: 1.3 $($Author: dvoet $ / $Date: 2003/05/05 21:21:23 $)
Author:
Greg Hinkle, December 2001

Field Summary
private static Method equalsMethod
          Preloaded Method object for the equals method of java.lang.Object
private static Method hashCodeMethod
          Preloaded Method object for the hashCode method of java.lang.Object
private static Method toStringMethod
          Preloaded Method object for the toString method of java.lang.Object
 
Constructor Summary
GenericProxy()
           
 
Method Summary
protected abstract  Object handleInvoke(Object proxy, Method m, Object[] args)
          This abstract method should be implemented to handle the specific functionality for an invocation handler.
 Object invoke(Object proxy, Method m, Object[] args)
          This method is called through by the JVM generated DynamicProxy for all calls to the represented object.
protected  Boolean proxyEquals(Object proxy, Object other)
          This method implements the standard proxyEquals method for subclassed invocation handler dynamic proxies.
protected  Integer proxyHashCode(Object proxy)
          Implements the standard hashCode method with a simple call to System.identityHashCode().
protected  String proxyToString(Object proxy)
          Prints out a string representation of the proxy object in the standard Java Object toString format of <classname>@<hashcode>
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hashCodeMethod

private static Method hashCodeMethod
Preloaded Method object for the hashCode method of java.lang.Object


equalsMethod

private static Method equalsMethod
Preloaded Method object for the equals method of java.lang.Object


toStringMethod

private static Method toStringMethod
Preloaded Method object for the toString method of java.lang.Object

Constructor Detail

GenericProxy

public GenericProxy()
Method Detail

invoke

public Object invoke(Object proxy,
                     Method m,
                     Object[] args)
              throws Throwable
This method is called through by the JVM generated DynamicProxy for all calls to the represented object. This method then manages delegating those calls the appropriate implementation. This implementation specially handles the default Object class methods and forwards all other method calls to the abstract handleInvoke method.

Specified by:
invoke in interface InvocationHandler
Parameters:
proxy - the object that is being represented
m - the method descriptor for the method called
args - an array of arguments passed to that method
Returns:
the return value of the delegated method.
Throws:
Throwable - when there is an exception thrown from the delegated method. This may be a Checked exception if the implemented interface declares the exception. Otherwise checked exceptions will be automatically wrapped in an UndeclaredThrowableException. Runtime exceptions are thrown as is.

handleInvoke

protected abstract Object handleInvoke(Object proxy,
                                       Method m,
                                       Object[] args)
                                throws Throwable
This abstract method should be implemented to handle the specific functionality for an invocation handler.

Parameters:
proxy - the object that is being represented
m - the method descriptor for the method called
args - an array of arguments passed to that method
Returns:
the return value of the delegated method.
Throws:
Throwable - when there is an exception thrown from the delegated method. This may be a Checked exception if the implemented interface declares the exception. Otherwise checked exceptions will be automatically wrapped in an UndeclaredThrowableException. Runtime exceptions are thrown as is.

proxyHashCode

protected Integer proxyHashCode(Object proxy)
Implements the standard hashCode method with a simple call to System.identityHashCode().

Parameters:
proxy - the object for which a hashcode should be returned
Returns:
the hash code of the provided object

proxyEquals

protected Boolean proxyEquals(Object proxy,
                              Object other)
This method implements the standard proxyEquals method for subclassed invocation handler dynamic proxies.

Parameters:
proxy - the proxy object for which equals is being handled
other - the other object being compared too
Returns:
true if they are symantically equal, false otherwise

proxyToString

protected String proxyToString(Object proxy)
Prints out a string representation of the proxy object in the standard Java Object toString format of <classname>@<hashcode>

Parameters:
proxy - the proxy object to toString
Returns:
the String representation of the proxy object


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.