org.mmbase.util.functions
Class Parameter

java.lang.Object
  extended byorg.mmbase.core.AbstractDescriptor
      extended byorg.mmbase.util.functions.Parameter
All Implemented Interfaces:
Cloneable, Descriptor, Serializable
Direct Known Subclasses:
Parameter.Wrapper, ReturnType

public class Parameter
extends AbstractDescriptor
implements Serializable

Each (function) argument is specified by a Parameter object. A Parameter contains a name and type (it does not contain a value). An array of this is returned by Function.getParameterDefinition(), and this same array is used to create new empty Parameters object (by Function.createParameters()), which can contain actual values for each Parameter.

Since:
MMBase-1.7
Version:
$Id: Parameter.java,v 1.30 2006/06/20 20:13:55 michiel Exp $
Author:
Daniel Ockeloen (MMFunctionParam), Michiel Meeuwissen
See Also:
Parameters, Serialized Form

Nested Class Summary
static class Parameter.Wrapper
          A Parameter.Wrapper wraps one Parameter around a Parameter[] (then you can put it in a Parameter[]).
 
Field Summary
static Parameter CLOUD
           
static Parameter CORENODE
           
protected  DataType dataType
          The parameter's data type
static Parameter[] EMPTY
          An empty Parameter array.
static Parameter FIELD
           
static Parameter LANGUAGE
          Parameter which might be needed in lots of Parameter definitions.
static Parameter LOCALE
           
static Parameter NODE
          'system' parameter set for nodefunctions.
static Parameter REQUEST
           
static Parameter RESPONSE
           
static Parameter USER
           
 
Fields inherited from class org.mmbase.core.AbstractDescriptor
description, guiName, key
 
Constructor Summary
Parameter(Parameter p, boolean required)
          Copy-constructor, just to copy it with different requiredness
Parameter(Parameter p, Object defaultValue)
          Copy-constructor, just to copy it with different defaultValue (which implies that it is not required now)
Parameter(String name, Class type)
          Create a Parameter object
Parameter(String name, Class type, boolean required)
          Create a Parameter object
Parameter(String name, Class type, Object defaultValue)
          Create a Parameter object
Parameter(String name, DataType dataType)
          Create a Parameter object
Parameter(String name, DataType dataType, boolean copy)
          Create a Parameter object
 
Method Summary
protected  Object autoCast(Object value)
          Tries to 'cast' an object for use with this parameter.
 void checkType(Object value)
          Checks if the passed object is of the correct class (compatible with the type of this Parameter), and throws an IllegalArgumentException if it doesn't.
 boolean equals(Object o)
          Whether parameter equals to other parameter.
 DataType getDataType()
          Returns the data type of this parameter.
 Object getDefaultValue()
          Returns the default value of this parameter (derived from the datatype).
 Class getTypeAsClass()
          Returns the type of values that this parameter accepts.
 int hashCode()
           
 boolean isRequired()
          Returns whether the parameter requires a value.
 void setDefaultValue(Object defaultValue)
          Sets the default value of this parameter.
 String toString()
           
 
Methods inherited from class org.mmbase.core.AbstractDescriptor
clone, clone, getDefaultLocale, getDescription, getDescription, getGUIName, getGUIName, getLocalizedDescription, getLocalizedGUIName, getName, setDescription, setDescription, setGUIName, setGUIName, setLocalizedDescription, setLocalizedGUIName
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LANGUAGE

public static final Parameter LANGUAGE
Parameter which might be needed in lots of Parameter definitions. These parameters are 'standard' parameters, which can be filled in by the system. E.g. the mmbase taglib uses these constants, and if it has a cloud ('mm:cloud is used'), then cloud-parameters are filled automaticly.


LOCALE

public static final Parameter LOCALE

USER

public static final Parameter USER

RESPONSE

public static final Parameter RESPONSE

REQUEST

public static final Parameter REQUEST

CLOUD

public static final Parameter CLOUD

NODE

public static final Parameter NODE
'system' parameter set for nodefunctions.

Since:
MMBaes-1.8

CORENODE

public static final Parameter CORENODE

FIELD

public static final Parameter FIELD

EMPTY

public static final Parameter[] EMPTY
An empty Parameter array.


dataType

protected DataType dataType
The parameter's data type

Since:
MMBase-1.8
Constructor Detail

Parameter

public Parameter(String name,
                 DataType dataType)
Create a Parameter object

Parameters:
name - the name of the parameter
dataType - the datatype of the parameter to copy
Since:
MMBase-1.8

Parameter

public Parameter(String name,
                 DataType dataType,
                 boolean copy)
Create a Parameter object

Parameters:
name - the name of the parameter
dataType - the datatype of the parameter to assign or copy
copy - if true, teh datatype is copied. if not, it is assigned directly, that is, changing condfiitons on the parameter changes the passed datatype instance.
Since:
MMBase-1.8

Parameter

public Parameter(String name,
                 Class type)
Create a Parameter object

Parameters:
name - the name of the parameter
type - the class of the parameter's possible value

Parameter

public Parameter(String name,
                 Class type,
                 boolean required)
Create a Parameter object

Parameters:
name - the name of the parameter
type - the class of the parameter's possible value
required - whether the parameter requires a value

Parameter

public Parameter(String name,
                 Class type,
                 Object defaultValue)
Create a Parameter object

Parameters:
name - the name of the parameter
type - the class of the parameter's possible value
defaultValue - the value to use if the parameter has no value set

Parameter

public Parameter(Parameter p,
                 boolean required)
Copy-constructor, just to copy it with different requiredness


Parameter

public Parameter(Parameter p,
                 Object defaultValue)
Copy-constructor, just to copy it with different defaultValue (which implies that it is not required now)

Method Detail

getDefaultValue

public Object getDefaultValue()
Returns the default value of this parameter (derived from the datatype).

Returns:
the default value

setDefaultValue

public void setDefaultValue(Object defaultValue)
Sets the default value of this parameter.

Parameters:
defaultValue - the default value

getDataType

public DataType getDataType()
Returns the data type of this parameter.

Returns:
the datatype
Since:
MMBase-1.8

getTypeAsClass

public Class getTypeAsClass()
Returns the type of values that this parameter accepts.

Returns:
the type as a Class

isRequired

public boolean isRequired()
Returns whether the parameter requires a value.

Returns:
true if a value is required

checkType

public void checkType(Object value)
Checks if the passed object is of the correct class (compatible with the type of this Parameter), and throws an IllegalArgumentException if it doesn't.

Parameters:
value - teh value whose type (class) to check
Throws:
IllegalArgumentException - if the type is not compatible

autoCast

protected Object autoCast(Object value)
Tries to 'cast' an object for use with this parameter. E.g. if value is a String, but this parameter is of type Integer, then the string can be parsed to Integer.

Parameters:
value - The value to be filled in in this Parameter.

hashCode

public int hashCode()

equals

public boolean equals(Object o)
Whether parameter equals to other parameter. Only key and type are consided. DefaultValue and required propererties are only 'utilities'.

Returns:
true if o is Parameter of which key and type equal to this' key and type.

toString

public String toString()
Overrides:
toString in class AbstractDescriptor


MMBase build 1.8.1.20060716