org.mmbase.util.functions
Class AbstractFunction

java.lang.Object
  extended byorg.mmbase.util.functions.AbstractFunction
All Implemented Interfaces:
Comparable, Function, Serializable
Direct Known Subclasses:
BeanFunction, MethodFunction, NodeFunction, ProcessorModule.GetNodeListFunction, ProcessorModule.ProcessFunction, ProcessorModule.ReplaceFunction

public abstract class AbstractFunction
extends Object
implements Function, Comparable, Serializable

An abstract representation of a piece of functionality (a 'function'). A function has a name, a return type, and a parameter-definition (which is a Parameter array). The goal of a Function object is to call its getFunctionValue(Parameters) method, which executes it, given the specified parameters.

Since:
MMBase-1.8
Version:
$Id: AbstractFunction.java,v 1.11 2006/02/14 22:52:33 michiel Exp $
Author:
Daniel Ockeloen, Michiel Meeuwissen
See Also:
Parameter, Parameters, Serialized Form

Field Summary
protected  String name
           
protected  ReturnType returnType
           
 
Constructor Summary
AbstractFunction(String name, Parameter[] def, ReturnType returnType)
          Constructor for Function objects.
 
Method Summary
 int compareTo(Object o)
           
 Parameters createParameters()
          Creates an empty 'Parameters' object for you, which you have to fill and feed back to getFunctionValue
 boolean equals(Object o)
           
 String getDescription()
           
abstract  Object getFunctionValue(Parameters parameters)
          Executes the defined function supplying the given arguments.
 Object getFunctionValueWithList(List parameters)
          Executes the defined function supplying the given List of arguments.
 String getName()
          A function must have a name.
 Parameter[] getParameterDefinition()
           
 ReturnType getReturnType()
           
 int hashCode()
           
 void setDescription(String description)
          For documentational purposes a function object needs a description too.
 void setParameterDefinition(Parameter[] params)
          A function object is of no use, as long as it lacks a definition.
 void setReturnType(ReturnType type)
          Sets the ReturnType for this function if not set already.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected String name

returnType

protected ReturnType returnType
Constructor Detail

AbstractFunction

public AbstractFunction(String name,
                        Parameter[] def,
                        ReturnType returnType)
Constructor for Function objects.

Parameters:
name - Every function must have a name
def - Every function must have a parameter definition. It can be left null and then filled later by setParameterDefinition(org.mmbase.util.functions.Parameter[])
returnType - Every function must also specify its return type. It can be left null and then filled later by setReturnType(org.mmbase.util.functions.ReturnType)
Method Detail

createParameters

public Parameters createParameters()
Creates an empty 'Parameters' object for you, which you have to fill and feed back to getFunctionValue

Specified by:
createParameters in interface Function
See Also:
getFunctionValue(Parameters)

getFunctionValue

public abstract Object getFunctionValue(Parameters parameters)
Executes the defined function supplying the given arguments.

Specified by:
getFunctionValue in interface Function
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 getReturnType()
See Also:
createParameters()

getFunctionValueWithList

public final Object getFunctionValueWithList(List parameters)
Executes the defined function supplying the given List of arguments. This is a convenience method, as the List is mapped to a Parameters type and passed to getFunctionValue(Parameters).

Specified by:
getFunctionValueWithList in interface Function
Parameters:
parameters - The parameters for the function. To specify an empty parameter list use Parameters.VOID.
Returns:
The function value, which can be of any type compatible to getReturnType()

setDescription

public void setDescription(String description)
For documentational purposes a function object needs a description too.

Specified by:
setDescription in interface Function

getDescription

public String getDescription()
Specified by:
getDescription in interface Function
See Also:
setDescription(String)

getName

public String getName()
A function must have a name. This is the name which was used to aquire the function object.

Specified by:
getName in interface Function
Returns:
The function's name, never null

getParameterDefinition

public Parameter[] getParameterDefinition()
Specified by:
getParameterDefinition in interface Function
Returns:
The currently set Parameter definition array, or null if not set already.

setParameterDefinition

public void setParameterDefinition(Parameter[] params)
A function object is of no use, as long as it lacks a definition.

Specified by:
setParameterDefinition in interface Function
Parameters:
params - An array of Parameter objects.
Throws:
IllegalStateException - if there was already set a parameter defintion for this function object.

getReturnType

public ReturnType getReturnType()
Specified by:
getReturnType in interface Function
Returns:
The currently set ReturnType, or null if not set already.

setReturnType

public void setReturnType(ReturnType type)
Sets the ReturnType for this function if not set already.

Specified by:
setReturnType in interface Function
Parameters:
type - A ReturnType object. For void functions that could be ReturnType.VOID.
Throws:
IllegalStateException - if there was already set a return type for this function object.

compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable

equals

public boolean equals(Object o)

hashCode

public int hashCode()
See Also:
Object.hashCode()

toString

public String toString()


MMBase build 1.8.1.20060716