public abstract class ConversionHandler
extends java.lang.Object
implements java.lang.reflect.InvocationHandler, java.io.Serializable
Constructor and Description |
---|
ConversionHandler(java.lang.Object delegate)
Creates a ConversionHandler with an delegate.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkMethod(java.lang.reflect.Method method) |
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.
|
java.lang.Object |
getDelegate()
Returns the delegate.
|
int |
hashCode()
Returns a hash code value for the delegate.
|
java.lang.Object |
invoke(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.Object |
invokeCustom(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 boolean |
isCoreObjectMethod(java.lang.reflect.Method method)
Checks whether a method is a core method from java.lang.Object.
|
protected boolean |
isDefaultMethod(java.lang.reflect.Method method) |
java.lang.String |
toString()
Returns a String version of the delegate.
|
public ConversionHandler(java.lang.Object delegate)
delegate
- the delegatejava.lang.IllegalArgumentException
- if the given delegate is nullpublic java.lang.Object getDelegate()
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
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.
invoke
in interface java.lang.reflect.InvocationHandler
proxy
- the proxymethod
- the methodargs
- the argumentsjava.lang.Throwable
- if caused by the delegate or the methodinvokeCustom(Object, Method, Object[])
,
InvocationHandler.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
protected boolean isDefaultMethod(java.lang.reflect.Method method)
protected boolean checkMethod(java.lang.reflect.Method method)
public abstract java.lang.Object invokeCustom(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
proxy
- the proxymethod
- the methodargs
- the argumentsjava.lang.Throwable
- any exception causes by the delegateinvoke(Object, Method, Object[])
,
InvocationHandler.invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public static boolean isCoreObjectMethod(java.lang.reflect.Method method)
method
- the method to check