org.mmbase.util.functions
Class MethodFunction

java.lang.Object
  extended by org.mmbase.util.functions.AbstractFunction<Object>
      extended by org.mmbase.util.functions.MethodFunction
All Implemented Interfaces:
Serializable, Comparable<Function<Object>>, Function<Object>

public class MethodFunction
extends AbstractFunction<Object>

A function based on an abritrary method. Use the annotation Name to attribute the parameter names. A method function can e.g. be defined like so in the builder xml:


      nl.didactor.component.assessment.LessonChecker
]]>
 
And be implemented like so:
  public static boolean canCloseLesson(@Required @Name("node") Node user,
                                       @Required @Name("lesson") Node lesson) {
   ...
 }

Since:
MMBase-1.7
Version:
$Id: MethodFunction.java 35524 2009-05-29 13:40:17Z michiel $
Author:
Michiel Meeuwissen
See Also:
MMObjectBuilder.executeFunction(org.mmbase.module.core.MMObjectNode, java.lang.String, java.util.List), Node.getFunctionValue(java.lang.String, java.util.List), BeanFunction, Serialized Form

Field Summary
 
Fields inherited from class org.mmbase.util.functions.AbstractFunction
autoReturnType, name, returnType
 
Constructor Summary
MethodFunction(Method method)
           
MethodFunction(Method method, Object instance)
           
MethodFunction(Method method, String name)
           
MethodFunction(Method method, String name, Object instance)
           
 
Method Summary
static Function<Object> getFunction(Class<?> clazz, String name)
          Returns the MethodFunction representing the method 'name' in class 'clazz'.
static Function<Object> getFunction(Method method, String name)
           
static Function<Object> getFunction(Method method, String name, Object instance)
           
 Object getFunctionValue(Parameters parameters)
          Executes the defined function supplying the given arguments.
static Method getMethod(Class<?> clazz, String name)
           
 
Methods inherited from class org.mmbase.util.functions.AbstractFunction
compareTo, createParameters, equals, getDescription, getFunctionValueWithArgs, getFunctionValueWithList, getName, getParameterDefinition, getReturnType, hashCode, setDescription, setParameterDefinition, setReturnType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MethodFunction

public MethodFunction(Method method)
Since:
MMBase-1.9

MethodFunction

public MethodFunction(Method method,
                      String name)

MethodFunction

public MethodFunction(Method method,
                      Object instance)
Since:
MMBase-1.9

MethodFunction

public MethodFunction(Method method,
                      String name,
                      Object instance)
Since:
MMBase-1.9
Method Detail

getFunction

public static Function<Object> getFunction(Method method,
                                           String name)

getFunction

public static Function<Object> getFunction(Method method,
                                           String name,
                                           Object instance)
Since:
MMBase-1.9

getFunction

public static Function<Object> getFunction(Class<?> clazz,
                                           String name)
Returns the MethodFunction representing the method 'name' in class 'clazz'. If there are more methods whith that name, the one with the largest number of by name annotated parameters is taken.

Since:
MMBase-1.9

getMethod

public static Method getMethod(Class<?> clazz,
                               String name)

getFunctionValue

public Object getFunctionValue(Parameters parameters)
Description copied from class: AbstractFunction
Executes the defined function supplying the given arguments.

Specified by:
getFunctionValue in interface Function<Object>
Specified by:
getFunctionValue in class AbstractFunction<Object>
Parameters:
parameters - The parameters for the function. To specify an empty parameter list use Parameters.VOID. Implementors are encouraged to support null too.
Returns:
The function value, which can be of any type compatible to AbstractFunction.getReturnType()
See Also:
AbstractFunction.createParameters()


MMBase 2.0-SNAPSHOT - null