org.mmbase.util.functions
Class BeanFunction

java.lang.Object
  extended byorg.mmbase.util.functions.AbstractFunction
      extended byorg.mmbase.util.functions.BeanFunction
All Implemented Interfaces:
Comparable, Function, Serializable

public class BeanFunction
extends AbstractFunction

One or more functions based on a Java-bean. Every setter method of the bean corresponds with one parameter. The default value of the parameter can be defined with the getter method (which will be called immediately after instantiation of such a Class). All other methods (with no arguments) of the class correspond to the functions. So, you can implement more bean-functions in the same class, as long as they have the same parameters. A BeanFunction can be aquired via FunctionFactory.getFunction(Class, String) (which delegates to a static method in this class).

Since:
MMBase-1.8
Version:
$Id: BeanFunction.java,v 1.8 2005/12/08 16:18:21 michiel Exp $
Author:
Michiel Meeuwissen
See Also:
MethodFunction, FunctionFactory, Serialized Form

Field Summary
 
Fields inherited from class org.mmbase.util.functions.AbstractFunction
name, returnType
 
Method Summary
static Class getClass(Class claz, String name)
          Utility function, searches an inner class of a given class.
static Function getFunction(Class claz, String name)
          Gives back a Function object based on the 'bean' concept.
 Object getFunctionValue(Parameters parameters)
          Executes the defined function supplying the given arguments. Instantiates the bean, calls all setters using the parameters, and executes the method associated with this function.
 
Methods inherited from class org.mmbase.util.functions.AbstractFunction
compareTo, createParameters, equals, getDescription, getFunctionValueWithList, getName, getParameterDefinition, getReturnType, hashCode, setDescription, setParameterDefinition, setReturnType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getClass

public static Class getClass(Class claz,
                             String name)
Utility function, searches an inner class of a given class. This inner class can perhaps be used as a bean. Used in JSP/taglib.

Parameters:
claz - The class to be considered
name - The name of the inner class
Throws:
IllegalArgumentException - if claz has no inner class with that name

getFunction

public static Function getFunction(Class claz,
                                   String name)
                            throws IllegalAccessException,
                                   InstantiationException,
                                   InvocationTargetException
Gives back a Function object based on the 'bean' concept. Called from FunctionFactory

Throws:
IllegalAccessException
InstantiationException
InvocationTargetException

getFunctionValue

public Object getFunctionValue(Parameters parameters)
Executes the defined function supplying the given arguments. Instantiates the bean, calls all setters using the parameters, and executes the method associated with this function.

Specified by:
getFunctionValue in interface Function
Specified by:
getFunctionValue in class AbstractFunction
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 build 1.8.1.20060716