Groovy 1.7.0

org.codehaus.groovy.runtime
Class ConversionHandler

java.lang.Object
  org.codehaus.groovy.runtime.ConversionHandler
All Implemented Interfaces:
InvocationHandler

class ConversionHandler
extends Object

This class is a general adapter to map a call to a Java interface to a given delegate.

author:
Ben Yu
author:
Jochen Theodorou


Constructor Summary
ConversionHandler(Object delegate)

Creates a ConversionHandler with an delegate.

 
Method Summary
protected boolean checkMethod(Method method)

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

Object getDelegate()

Returns the delegate.

int hashCode()

Returns a hash code value for the delegate.

Object invoke(Object proxy, Method method, Object[] args)

This method is a default implementation for the invoke method given in Invocationhandler.

Object invokeCustom(Object proxy, Method method, Object[] args)

This method is called for all Methods not defined on Object.

static boolean isCoreObjectMethod(Method method)

Checks whether a method is a core method from java.lang.Object.

String toString()

Returns a String version of the delegate.

 
Methods inherited from class Object
wait, wait, wait, hashCode, getClass, equals, toString, notify, notifyAll
 

Constructor Detail

ConversionHandler

public ConversionHandler(Object delegate)
Creates a ConversionHandler with an delegate.
param:
delegate the delegate
throws:
IllegalArgumentException if the given delegate is null


 
Method Detail

checkMethod

protected boolean checkMethod(Method method)


equals

public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one. The delegate is used if the class of the parameter and the current class are equal. In other cases the method will return false. The exact class is here used, if inheritance is needed, this method must be overwritten.
see:
Object#equals


getDelegate

public Object getDelegate()
Returns the delegate.
return:
the delegate


hashCode

public int hashCode()
Returns a hash code value for the delegate.
see:
Object#hashCode


invoke

public Object invoke(Object proxy, Method method, Object[] args)
This method is a default implementation for the invoke method given in Invocationhandler. Any call to a method with a declaring class that is not Object, excluding toString(), is redirected to invokeCustom. Methods like equals and hashcode are called on the class itself instead of the delegate because they are considered fundamental methods that should not be overwritten. The toString() method gets special treatment as it is deemed to be a method that you might wish to override when called from Groovy. In many scenarios, it is better to overwrite the invokeCustom method where the core Object related methods are filtered out.
param:
proxy the proxy
param:
method the method
param:
args the arguments
return:
the result of the invocation by method or delegate
throws:
Throwable if caused by the delegate or the method
see:
#invokeCustom(Object, Method, Object[])
see:
InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])


invokeCustom

public Object invokeCustom(Object proxy, Method method, Object[] args)
This method is called for all Methods not defined on Object. The delegate should be called here.
param:
proxy the proxy
param:
method the method
param:
args the arguments
return:
the result of the invocation of the delegate
throws:
Throwable any exception causes by the delegate
see:
#invoke(Object, Method, Object[])
see:
InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])


isCoreObjectMethod

public static boolean isCoreObjectMethod(Method method)
Checks whether a method is a core method from java.lang.Object. Such methods often receive special treatment because they are deemed fundamental enough to not be tampered with.
param:
method the method to check
return:
true if the method is deemed to be a core method


toString

public String toString()
Returns a String version of the delegate.
see:
Object#toString


 

Copyright © 2003-2009 The Codehaus. All rights reserved.