de.jstacs.parameters
Class SimpleParameter

java.lang.Object
  extended by de.jstacs.parameters.Parameter
      extended by de.jstacs.parameters.SimpleParameter
All Implemented Interfaces:
Rangeable, Storable, Cloneable

public class SimpleParameter
extends Parameter
implements Rangeable

Class for a "simple" parameter. Simple parameters are those of the primitive types and single Strings.

Author:
Jan Grau

Nested Class Summary
static class SimpleParameter.DatatypeNotValidException
          Class for an Exception that can be thrown if the provided int-value that represents a datatype is not one of the values defined in the Parameter-interface.
static class SimpleParameter.IllegalValueException
          This exception is thrown if a parameter is not valid.
 
Field Summary
protected  String comment
          A comment on the parameter
protected  DataType datatype
          The data type of the parameter value
protected  Object defaultValue
          The default value of the parameter
protected  String name
          The name of the parameter
protected  boolean required
          if the parameter is required
protected  ParameterValidator validator
          The validator for the parameter values
protected  Object value
          The current value of the parameter
 
Fields inherited from class de.jstacs.parameters.Parameter
neededReference, neededReferenceId, parent
 
Constructor Summary
SimpleParameter(DataType datatype, String name, String comment, boolean required)
          Constructor for a SimpleParameter without validator
SimpleParameter(DataType datatype, String name, String comment, boolean required, Object defaultVal)
          Constructor for a SimpleParameter without ParameterValidator but with a default value
SimpleParameter(DataType datatype, String name, String comment, boolean required, ParameterValidator validator)
          Constructor for a SimpleParameter with a ParameterValidator.
SimpleParameter(DataType datatype, String name, String comment, boolean required, ParameterValidator validator, Object defaultVal)
          Constructor for a SimpleParameter with validator and default value.
SimpleParameter(StringBuffer representation)
          Constructs a SimpleParameter out of an XML representation
 
Method Summary
 boolean checkValue(Object value)
          Checks the value for correctness, e.g. for numerical parameters this might be checking if the value is within specified bounds
 SimpleParameter clone()
           
 boolean equals(Object o2)
           
protected  void fromXML(StringBuffer representation)
          Parses a Parameter from an XML-representation as returned by Parameter.toXML().
 String getComment()
          Returns a comment on this parameter that tells something about useful values, domains, usage of this parameter, etc.
 DataType getDatatype()
          Returns the data type of the parameter
 String getErrorMessage()
          If a value could not be set successfully this method returns the corresponding error message.
 String getName()
          Returns the name of the parameter
 Parameter getRangedInstance()
          Returns an instance of RangeIterator that has the same properties as the current instance, but accepts a range or list of values.
 ParameterValidator getValidator()
          Returns the ParameterValidator used in this SimpleParameter.
 Object getValue()
          Returns the current value of this Parameter
 boolean hasDefaultOrIsSet()
          Returns true if the parameter either has a default value or the value was set by the user.
 boolean isAtomic()
          Returns true if the parameter is of an atomic data type
 boolean isRangeable()
          Returns true if the parameters can be varied over a range of values.
 boolean isRequired()
          Returns true if the parameter is required, false otherwise
 boolean isSet()
          Returns true if the parameter was set by the user.
 void reset()
          Resets the parameter and its contents to the default values or null if not defaults are given.
 void setDefault(Object defaultValue)
          Sets the default value of the parameter to defaultValue
 void setRangeable(boolean rangeable)
          Sets the value returned by isRangeable() to rangeable
 void setValidator(ParameterValidator validator)
          Sets a new ParameterValidator for this SimpleParameter.
 void setValue(Object value2)
          Sets the value of this parameter to value.
 void simplify()
          Simplifies the Parameter and its contents to the relevant information.
 StringBuffer toXML()
          This method returns an XML-representation of an instance of the implementing class.
 
Methods inherited from class de.jstacs.parameters.Parameter
getId, getNeededReference, getNeededReferenceId, getParent, setNeededReference, setParent
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

datatype

protected DataType datatype
The data type of the parameter value


name

protected String name
The name of the parameter


comment

protected String comment
A comment on the parameter


required

protected boolean required
if the parameter is required


value

protected Object value
The current value of the parameter


defaultValue

protected Object defaultValue
The default value of the parameter


validator

protected ParameterValidator validator
The validator for the parameter values

Constructor Detail

SimpleParameter

public SimpleParameter(StringBuffer representation)
                throws NonParsableException
Constructs a SimpleParameter out of an XML representation

Parameters:
representation - the XML representation
Throws:
NonParsableException - if the SimpleParameter could not be restored from the representation, a NonParsableException is thrown

SimpleParameter

public SimpleParameter(DataType datatype,
                       String name,
                       String comment,
                       boolean required)
                throws SimpleParameter.DatatypeNotValidException
Constructor for a SimpleParameter without validator

Parameters:
datatype - the data type of the parameter value
name - the name of the parameter
comment - a comment on the parameter that tells the user some details about it
required - if the parameter is required
Throws:
SimpleParameter.DatatypeNotValidException - is thrown if datatype is not one of the allowed DataTypes

SimpleParameter

public SimpleParameter(DataType datatype,
                       String name,
                       String comment,
                       boolean required,
                       Object defaultVal)
                throws ParameterException
Constructor for a SimpleParameter without ParameterValidator but with a default value

Parameters:
datatype - the data type of the parameter value
name - the name of the parameter
comment - a comment on the parameter that tells the user some details about it
required - if the parameter is required
defaultVal - the default value
Throws:
ParameterException - is thrown if either the default value is not a valid value with respect to datatype or datatype is not in the values defined in Parameter

SimpleParameter

public SimpleParameter(DataType datatype,
                       String name,
                       String comment,
                       boolean required,
                       ParameterValidator validator)
                throws SimpleParameter.DatatypeNotValidException
Constructor for a SimpleParameter with a ParameterValidator.

Parameters:
datatype - the data type of the parameter value
name - the name of the parameter
comment - a comment on the parameter that tells the user some details about it
required - if the parameter is required
validator - the validator for the parameter values
Throws:
SimpleParameter.DatatypeNotValidException - is thrown if datatype is not in the values allowed for a SimpleParameter

SimpleParameter

public SimpleParameter(DataType datatype,
                       String name,
                       String comment,
                       boolean required,
                       ParameterValidator validator,
                       Object defaultVal)
                throws ParameterException
Constructor for a SimpleParameter with validator and default value.

Parameters:
datatype - the data type of the parameter value
name - the name of the parameter
comment - a comment on the parameter that tells the user some details about it
required - if the parameter is required
validator - the validator for the parameter values
defaultVal - the default value
Throws:
ParameterException - thrown if either the default value is not a valid value with respect to datatype or datatype is not in the values allowed for a SimpleParameter
Method Detail

clone

public SimpleParameter clone()
                      throws CloneNotSupportedException
Overrides:
clone in class Parameter
Throws:
CloneNotSupportedException

hasDefaultOrIsSet

public boolean hasDefaultOrIsSet()
Description copied from class: Parameter
Returns true if the parameter either has a default value or the value was set by the user.

Specified by:
hasDefaultOrIsSet in class Parameter
Returns:
if value has default or is set

isSet

public boolean isSet()
Description copied from class: Parameter
Returns true if the parameter was set by the user.

Specified by:
isSet in class Parameter
Returns:
if the parameter was set

isRangeable

public boolean isRangeable()
Description copied from interface: Rangeable
Returns true if the parameters can be varied over a range of values.

Specified by:
isRangeable in interface Rangeable
Returns:
if the parameter can be varied

setRangeable

public void setRangeable(boolean rangeable)
Sets the value returned by isRangeable() to rangeable

Parameters:
rangeable - the new value

getRangedInstance

public Parameter getRangedInstance()
                            throws Exception
Description copied from interface: Rangeable
Returns an instance of RangeIterator that has the same properties as the current instance, but accepts a range or list of values. These values can be obtained by the methods of RangeIterator.

Specified by:
getRangedInstance in interface Rangeable
Returns:
the instance
Throws:
Exception - is thrown if isRangeable() returns false or the ranged instance could not be created for some other reason

isAtomic

public boolean isAtomic()
Description copied from class: Parameter
Returns true if the parameter is of an atomic data type

Specified by:
isAtomic in class Parameter
Returns:
if the parameter is atomic

getName

public String getName()
Description copied from class: Parameter
Returns the name of the parameter

Specified by:
getName in class Parameter
Returns:
the name

getDatatype

public DataType getDatatype()
Description copied from class: Parameter
Returns the data type of the parameter

Specified by:
getDatatype in class Parameter
Returns:
the data type

getComment

public String getComment()
Description copied from class: Parameter
Returns a comment on this parameter that tells something about useful values, domains, usage of this parameter, etc.

Specified by:
getComment in class Parameter
Returns:
the comment

isRequired

public boolean isRequired()
Description copied from class: Parameter
Returns true if the parameter is required, false otherwise

Specified by:
isRequired in class Parameter
Returns:
if the parameter is required

checkValue

public boolean checkValue(Object value)
Description copied from class: Parameter
Checks the value for correctness, e.g. for numerical parameters this might be checking if the value is within specified bounds

Specified by:
checkValue in class Parameter
Parameters:
value - the value to be checked
Returns:
if the value is valid

getErrorMessage

public String getErrorMessage()
Description copied from class: Parameter
If a value could not be set successfully this method returns the corresponding error message.

Specified by:
getErrorMessage in class Parameter
Returns:
the error message

setDefault

public void setDefault(Object defaultValue)
                throws SimpleParameter.IllegalValueException
Description copied from class: Parameter
Sets the default value of the parameter to defaultValue

Specified by:
setDefault in class Parameter
Parameters:
defaultValue - the default value
Throws:
SimpleParameter.IllegalValueException

simplify

public void simplify()
Description copied from class: Parameter
Simplifies the Parameter and its contents to the relevant information. This could be e.g. to reset the contents of those values of a CollectionParameter that are not selected.

Specified by:
simplify in class Parameter

reset

public void reset()
Description copied from class: Parameter
Resets the parameter and its contents to the default values or null if not defaults are given.

Specified by:
reset in class Parameter

setValue

public void setValue(Object value2)
              throws SimpleParameter.IllegalValueException
Description copied from class: Parameter
Sets the value of this parameter to value.

Specified by:
setValue in class Parameter
Parameters:
value2 - the new value
Throws:
SimpleParameter.IllegalValueException - if the specified value is not valid for this Parameter an IllegalValueException is thrown

getValue

public Object getValue()
Description copied from class: Parameter
Returns the current value of this Parameter

Specified by:
getValue in class Parameter
Returns:
the current value

toXML

public StringBuffer toXML()
Description copied from interface: Storable
This method returns an XML-representation of an instance of the implementing class.

Specified by:
toXML in interface Storable
Overrides:
toXML in class Parameter
Returns:
the XML-representation

fromXML

protected void fromXML(StringBuffer representation)
                throws NonParsableException
Description copied from class: Parameter
Parses a Parameter from an XML-representation as returned by Parameter.toXML().

Overrides:
fromXML in class Parameter
Parameters:
representation - the XML-representation
Throws:
NonParsableException - is thrown if the XML-code could not be parsed

equals

public boolean equals(Object o2)
Overrides:
equals in class Object

getValidator

public ParameterValidator getValidator()
Returns the ParameterValidator used in this SimpleParameter. This may be null.

Returns:
the validator

setValidator

public void setValidator(ParameterValidator validator)
Sets a new ParameterValidator for this SimpleParameter.

Parameters:
validator - the new validator