net.sf.jga.fn.property
Class Invoke<R>

java.lang.Object
  extended by net.sf.jga.fn.Functor<R>
      extended by net.sf.jga.fn.property.Invoke<R>
All Implemented Interfaces:
java.io.Serializable, Visitable

public class Invoke<R>
extends Functor<R>

Functor that invokes a method described at construction and returns the result or null if the result is void. The arguments must be passed to the functor in an array, and the values must be assignable to the corresponding classes given at construction.

Note that declaring the return type incorrectly can result in ClassCastExceptions being thrown when the functor is invoked: the compiler cannot check the return type of a reflectively loaded method, unless we add more arguments to the constructor.

Copyright © 2009 David A. Hall

Author:
David A. Hall
See Also:
Serialized Form

Nested Class Summary
static interface Invoke.Visitor
          Interface for classes that may interpret a InvokeMethod function.
 
Constructor Summary
Invoke(java.lang.Class<?> objClass, java.lang.reflect.Method method)
          Builds a InvokeMethod for a given method
Invoke(java.lang.Class<?> objClass, java.lang.String methName, java.lang.Class<?>... argtypes)
          Builds a InvokeMethod for the given method, using the given class array to find the desired method.
Invoke(java.lang.reflect.Method method)
          Builds an InvokeMethod functor for the given method.
 
Method Summary
 void accept(Visitor v)
          Calls the Visitor's visit(InvokeMethod) method, if it implements the nested Visitor interface.
 R eval(java.lang.Object... args)
          A non-typesafe evaluation method for function objects.
 java.lang.reflect.Method getMethod()
          Lazy loads the method
 java.lang.String getMethodName()
          Returns the name of the method that this functor invokes.
 java.lang.Class<?> getObjectType()
          Returns the class which supplied the method is invoked.
 java.lang.Class<R> getReturnType()
          Returns the type of the method
 java.lang.String toString()
           
 
Methods inherited from class net.sf.jga.fn.Functor
bind0th, bindNth, composeNth, composeNth, generateNth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Invoke

public Invoke(java.lang.reflect.Method method)
Builds an InvokeMethod functor for the given method.

NOTE: this constructor has lower type-safety guarantee than the other constructors, in that the compiler cannot check that the method's declaring class is T. When a functor built by this constructor is evaluated, it will throw IllegalArgumentException if given an incompatible argument.

Throws:
java.lang.IllegalArgumentException - if the method is null or if it takes arguments

Invoke

public Invoke(java.lang.Class<?> objClass,
              java.lang.reflect.Method method)
Builds a InvokeMethod for a given method

Throws:
java.lang.IllegalArgumentException - if the method or class is null; or if the method is not supplied by the given class;

Invoke

public Invoke(java.lang.Class<?> objClass,
              java.lang.String methName,
              java.lang.Class<?>... argtypes)
Builds a InvokeMethod for the given method, using the given class array to find the desired method.

Throws:
java.lang.IllegalArgumentException - if class, method name, or argument type array is null; or if the class does not supply the described method.
Method Detail

getObjectType

public java.lang.Class<?> getObjectType()
Returns the class which supplied the method is invoked.


getMethodName

public java.lang.String getMethodName()
Returns the name of the method that this functor invokes.


getReturnType

public java.lang.Class<R> getReturnType()
Returns the type of the method


getMethod

public java.lang.reflect.Method getMethod()
                                   throws java.lang.NoSuchMethodException
Lazy loads the method

Throws:
java.lang.NoSuchMethodException

eval

public R eval(java.lang.Object... args)
Description copied from class: Functor
A non-typesafe evaluation method for function objects. The number and types of arguments is not checked at compile time: an invalid number of arguments may cause IndexOutOfBoundsException (or cause extraneous arguments to be ignored); an argument of an invalid type may cause a ClassCastException.

Specified by:
eval in class Functor<R>

accept

public void accept(Visitor v)
Calls the Visitor's visit(InvokeMethod) method, if it implements the nested Visitor interface.

Specified by:
accept in interface Visitable
Overrides:
accept in class Functor<R>

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2002-2006 David A. Hall. All Rights Reserved.