Package org.codehaus.groovy.runtime
Class ConversionHandler
- java.lang.Object
- 
- org.codehaus.groovy.runtime.ConversionHandler
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- java.lang.reflect.InvocationHandler
 - Direct Known Subclasses:
- ConvertedClosure,- ConvertedMap
 
 public abstract class ConversionHandler extends java.lang.Object implements java.lang.reflect.InvocationHandler, java.io.SerializableThis class is a general adapter to map a call to a Java interface to a given delegate.- See Also:
- Serialized Form
 
- 
- 
Constructor SummaryConstructors Constructor Description ConversionHandler(java.lang.Object delegate)Creates a ConversionHandler with an delegate.
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected booleancheckMethod(java.lang.reflect.Method method)booleanequals(java.lang.Object obj)Indicates whether some other object is "equal to" this one.java.lang.ObjectgetDelegate()Returns the delegate.inthashCode()Returns a hash code value for the delegate.java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)This method is a default implementation for the invoke method given in InvocationHandler.abstract java.lang.ObjectinvokeCustom(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)This method is called for all Methods not defined on Object.static booleanisCoreObjectMethod(java.lang.reflect.Method method)Checks whether a method is a core method from java.lang.Object.protected booleanisDefaultMethod(java.lang.reflect.Method method)java.lang.StringtoString()Returns a String version of the delegate.
 
- 
- 
- 
Method Detail- 
getDelegatepublic java.lang.Object getDelegate() Returns the delegate.- Returns:
- the delegate
 
 - 
invokepublic java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.ThrowableThis 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() and default methods 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. Interface default methods from Java 8 on the other hand are considered being default implementations you don't normally want to change. So they are called directly too In many scenarios, it is better to overwrite the invokeCustom method where the core Object related methods are filtered out. - Specified by:
- invokein interface- java.lang.reflect.InvocationHandler
- Parameters:
- proxy- the proxy
- method- the method
- args- the arguments
- Returns:
- the result of the invocation by method or delegate
- Throws:
- java.lang.Throwable- if caused by the delegate or the method
- See Also:
- invokeCustom(Object, Method, Object[]),- InvocationHandler.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
 
 - 
isDefaultMethodprotected boolean isDefaultMethod(java.lang.reflect.Method method) 
 - 
checkMethodprotected boolean checkMethod(java.lang.reflect.Method method) 
 - 
invokeCustompublic abstract java.lang.Object invokeCustom(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.ThrowableThis method is called for all Methods not defined on Object. The delegate should be called here.- Parameters:
- proxy- the proxy
- method- the method
- args- the arguments
- Returns:
- the result of the invocation of the delegate
- Throws:
- java.lang.Throwable- any exception causes by the delegate
- See Also:
- invoke(Object, Method, Object[]),- InvocationHandler.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
 
 - 
equalspublic boolean equals(java.lang.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.- Overrides:
- equalsin class- java.lang.Object
- See Also:
- Object.equals(java.lang.Object)
 
 - 
hashCodepublic int hashCode() Returns a hash code value for the delegate.- Overrides:
- hashCodein class- java.lang.Object
- See Also:
- Object.hashCode()
 
 - 
toStringpublic java.lang.String toString() Returns a String version of the delegate.- Overrides:
- toStringin class- java.lang.Object
- See Also:
- Object.toString()
 
 - 
isCoreObjectMethodpublic static boolean isCoreObjectMethod(java.lang.reflect.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.- Parameters:
- method- the method to check
- Returns:
- true if the method is deemed to be a core method
 
 
- 
 
-