Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.groovy.runtime
Class ConversionHandler

    java.lang.Object
      org.codehaus.groovy.runtime.ConversionHandler

All Implemented Interfaces:
  InvocationHandler

Direct Known Subclasses:
  ConvertedClosure, ConvertedMap

    public abstract class ConversionHandler

extends Object
implements InvocationHandler

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

Author:
  Ben Yu, Jochen Theodorou

Constructor Summary
`ConversionHandler(Object delegate)` Creates a ConversionHandler with an deleagte.

Method Summary
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`Object` | `getDelegate()` gets 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.
`abstract Object` | `invokeCustom(Object proxy, Method method, Object[] args)` This method is called for all Methods not defined on Object.
`String` | `toString()` Returns a String version of the delegate.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### ConversionHandler

    public ConversionHandler(Object delegate)

  Creates a ConversionHandler with an deleagte.

  Parameters:
    `delegate` - the delegate
  Throws:
    `IllegalArgumentException` - if the given delegate is null

Method Detail

### getDelegate

    public Object getDelegate()

  gets the delegate.

  Returns:
    the delegate

### invoke

    public Object invoke(Object proxy,
                         Method method,
                         Object[] args)
                  throws Throwable

  This method is a default implementation for the invoke method given in Invocationhandler. Any call to an method with an declaring class that is not Object is redirected to invokeCustom. Methods like tostring, equals and hashcode are called on the class itself instead of the delegate. It is better to overwrite the invokeCustom method where the Object related methods are filtered out.

  Specified by:
    `invoke` in interface `InvocationHandler`
  Parameters:
    `proxy` - the proxy
    `method` - the method
    `args` - the arguments
  Returns:
    the result of the invocation by method or delegate
  Throws:
    `Throwable` - any exception 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[])`

### invokeCustom

    public abstract Object invokeCustom(Object proxy,
                                        Method method,
                                        Object[] args)
                                 throws Throwable

  This 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:
    `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[])`

### 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.

  Overrides:
    `equals` in class `Object`
  See Also:
    `Object.equals(java.lang.Object)`

### hashCode

    public int hashCode()

  Returns a hash code value for the delegate.

  Overrides:
    `hashCode` in class `Object`
  See Also:
    `Object.hashCode()`

### toString

    public String toString()

  Returns a String version of the delegate.

  Overrides:
    `toString` in class `Object`
  See Also:
    `Object.toString()`

Overview | Package | Class | Tree | Deprecated | Index | Help
| Copyright © 2003-2008 The Codehaus. All rights reserved.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD