net.sf.collections15.functors.transformer
Class InvokerTransformer<I,O>

java.lang.Object
  extended by net.sf.collections15.functors.transformer.InvokerTransformer<I,O>
All Implemented Interfaces:
java.io.Serializable, Transformer<I,O>

public class InvokerTransformer<I,O>
extends java.lang.Object
implements Transformer<I,O>, java.io.Serializable

Transformer implementation whose transform(I) method invokes a specified method on the input object by reflection, returning the resulting return value as the output.

Since:
Collections15 1.0
Author:
Stephen Colebourne, Chris Lambrou (port to Java 5.0)
See Also:
Serialized Form

Constructor Summary
protected InvokerTransformer(java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.Object[] arguments)
          Create a new instance that transforms an input object by invoking a method of the specified signature with the specified arguments via reflection, and returning the return value as the output object.
 
Method Summary
static
<I,O> InvokerTransformer<I,O>
getInstance(java.lang.String methodName)
          Returns an instance that transforms an input object by invoking a method of the specified name and no arguments via reflection, and returning the return value as the output object.
static
<I,O> InvokerTransformer<I,O>
getInstance(java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.Object[] arguments)
          Returns an instance that transforms an input object by invoking a method of the specified signature with the specified arguments via reflection, and returning the return value as the output object.
 O transform(I input)
          Transforms the input by invoking a method on it and returning the resulting return value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InvokerTransformer

protected InvokerTransformer(java.lang.String methodName,
                             java.lang.Class[] parameterTypes,
                             java.lang.Object[] arguments)
Create a new instance that transforms an input object by invoking a method of the specified signature with the specified arguments via reflection, and returning the return value as the output object.

Parameters:
methodName - The name of the method to invoke on an input object.
parameterTypes - The parameter types of the method to invoke on an input object. May be null or empty if arguments is also null or empty, in which case the parameterless mehod of the specified name will be used. The contents of this array are defensively copied.
arguments - The arguments to pass to the method invoked on an input Class.
Throws:
java.lang.IllegalArgumentException - Thrown if the method name argument is null.
java.lang.IllegalArgumentException - Thrown if either of parameterTypes or arguments is null, but the other is not.
java.lang.IllegalArgumentException - Thrown if any element in parameterTypes is null.
java.lang.IllegalArgumentException - Thrown if any none-null element in arguments is not an instance of its corresponding parameterTypes class.
Method Detail

getInstance

public static <I,O> InvokerTransformer<I,O> getInstance(java.lang.String methodName)
Returns an instance that transforms an input object by invoking a method of the specified name and no arguments via reflection, and returning the return value as the output object.

Parameters:
methodName - The name of the method to invoke on an input object.
Returns:
An instance that transforms an input object by invoking a method of the specified name and no arguments via reflection, and returning the return value as the output object.
Throws:
java.lang.IllegalArgumentException - Thrown if the method name argument is null.

getInstance

public static <I,O> InvokerTransformer<I,O> getInstance(java.lang.String methodName,
                                                        java.lang.Class[] parameterTypes,
                                                        java.lang.Object[] arguments)
Returns an instance that transforms an input object by invoking a method of the specified signature with the specified arguments via reflection, and returning the return value as the output object.

Parameters:
methodName - The name of the method to invoke on an input object.
parameterTypes - The parameter types of the method to invoke on an input object. May be null or empty if arguments is also null or empty, in which case the parameterless mehod of the specified name will be used. The contents of this array are defensively copied.
arguments - The arguments to pass to the method invoked on an input Class.
Returns:
An instance that transforms an input object by invoking a method of the specified signature with the specified arguments via reflection, and returning the return value as the output object.
Throws:
java.lang.IllegalArgumentException - Thrown if the method name argument is null.
java.lang.IllegalArgumentException - Thrown if either of parameterTypes or arguments is null, but the other is not.
java.lang.IllegalArgumentException - Thrown if any element in parameterTypes is null.
java.lang.IllegalArgumentException - Thrown if any none-null element in arguments is not an instance of its corresponding parameterTypes class.

transform

public O transform(I input)
            throws FunctorException
Transforms the input by invoking a method on it and returning the resulting return value.

Specified by:
transform in interface Transformer<I,O>
Parameters:
input - The input object to transform.
Returns:
The return value of the method invoked on the input object. If the return type of the method is void, null is returned.
Throws:
FunctorException - Thrown if any of the following is true.
  • The input object is null.
  • A method with the appropriate name and signature doesn't exist or isn't public.
  • The method could not be instantiated for any other reason.
  • The method itself threw an exception.


Copyright © 2001-2005 SourceForge.net. All Rights Reserved.