de.jstacs.parameters
Class SimpleParameter

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

public class SimpleParameter
extends Parameter
implements Rangeable, GalaxyConvertible

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 data type is not one of the values defined in DataType.
static class SimpleParameter.IllegalValueException
          This exception is thrown if a parameter is not valid.
 
Field Summary
protected  Object defaultValue
          The default value of the parameter
protected  boolean required
          Determines 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
parent
 
Fields inherited from class de.jstacs.AnnotatedEntity
comment, datatype, name
 
Constructor Summary
SimpleParameter(DataType datatype, String name, String comment, boolean required)
          Constructor for a SimpleParameter without ParameterValidator.
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)
          The standard constructor for the interface Storable.
 
Method Summary
protected  void appendFurtherInfos(StringBuffer buf)
          This method can be used in the method Storable.toXML() to extract further information (name, comment, datatype).
 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 extractFurtherInfos(StringBuffer representation)
          This method can be used in the constructor with parameter StringBuffer to extract the further information.
 void fromGalaxy(String namePrefix, StringBuffer command)
          Parses the contents of command in the format defined by configBuffer of GalaxyConvertible.toGalaxy(String, String, int, StringBuffer, StringBuffer) and sets the values of the Parameter or ParameterSet accordingly.
 String getErrorMessage()
          If a value could not be set successfully this method returns the corresponding error message.
 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 value of the AnnotatedEntity.
 String getXMLTag()
          This method returns a tag used as outer tag of the XML description.
 boolean hasDefaultOrIsSet()
          Returns true if the parameter either has a default value or the value was set by the user, false otherwise.
 boolean isAtomic()
          Returns true if the parameter is of an atomic data type, false otherwise.
 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, false otherwise.
 void reset()
          Resets the parameter and its contents to the default values or null if no 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 toGalaxy(String namePrefix, String configPrefix, int depth, StringBuffer descBuffer, StringBuffer configBuffer)
          Creates an Galaxy XML-representation of the parameters and appends it to descBuffer and variable configuration and appends it to configBuffer.
 String toString()
           
 
Methods inherited from class de.jstacs.parameters.Parameter
getParent, isComparable, setParent
 
Methods inherited from class de.jstacs.AnnotatedEntity
getComment, getDatatype, getName, toXML
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

required

protected boolean required
Determines 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
The standard constructor for the interface Storable. Constructs a SimpleParameter out of an XML representation.

Parameters:
representation - the XML representation as StringBuffer
Throws:
NonParsableException - if the SimpleParameter could not be restored from the StringBuffer representation

SimpleParameter

public SimpleParameter(DataType datatype,
                       String name,
                       String comment,
                       boolean required)
                throws SimpleParameter.DatatypeNotValidException
Constructor for a SimpleParameter without 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 - determines if the parameter is required
Throws:
SimpleParameter.DatatypeNotValidException - if datatype is not one of the allowed DataTypes

SimpleParameter

public SimpleParameter(DataType datatype,
                       String name,
                       String comment,
                       boolean required,
                       Object defaultVal)
                throws SimpleParameter.DatatypeNotValidException,
                       SimpleParameter.IllegalValueException
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 - determines if the parameter is required
defaultVal - the default value
Throws:
SimpleParameter.DatatypeNotValidException - if datatype is not in the values allowed for a SimpleParameter
SimpleParameter.IllegalValueException - if the default value is not a valid value with respect to datatype

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 - determines if the parameter is required
validator - the validator for the parameter values
Throws:
SimpleParameter.DatatypeNotValidException - 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 - determines if the parameter is required
validator - the validator for the parameter values
defaultVal - the default value
Throws:
ParameterException - 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, false otherwise.

Specified by:
hasDefaultOrIsSet in class Parameter
Returns:
true if value has a default value or was set, false otherwise

isSet

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

Specified by:
isSet in class Parameter
Returns:
true if the parameter was set, false otherwise

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:
true if the parameter can be varied, false otherwise

setRangeable

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

Parameters:
rangeable - the new value that determines if this SimpleParameter is rangeable

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:
an instance with the same properties as the current instance
Throws:
Exception - is thrown if Rangeable.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, false otherwise.

Specified by:
isAtomic in class Parameter
Returns:
true if the parameter is atomic, false otherwise

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:
true if the Parameter is required, false otherwise

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:
true if the value is valid, false otherwise

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:
an error message if a value could not be set successfully

setDefault

public void setDefault(Object defaultValue)
                throws SimpleParameter.IllegalValueException
Description copied from class: Parameter
Sets the default value of the Parameter to defaultValue. This method also sets the current value of this Parameter to the default.

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

reset

public void reset()
Description copied from class: Parameter
Resets the parameter and its contents to the default values or null if no 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 of the Parameter
Throws:
SimpleParameter.IllegalValueException - if the specified value is not valid for this Parameter

getValue

public Object getValue()
Description copied from class: AnnotatedEntity
Returns the value of the AnnotatedEntity.

Specified by:
getValue in class AnnotatedEntity
Returns:
the value of the AnnotatedEntity

getXMLTag

public String getXMLTag()
Description copied from class: AnnotatedEntity
This method returns a tag used as outer tag of the XML description.

Specified by:
getXMLTag in class AnnotatedEntity
Returns:
a tag used as outer tag of the XML description

appendFurtherInfos

protected void appendFurtherInfos(StringBuffer buf)
Description copied from class: AnnotatedEntity
This method can be used in the method Storable.toXML() to extract further information (name, comment, datatype).

Overrides:
appendFurtherInfos in class Parameter
Parameters:
buf - a XML representation of the main information as StringBuffer
See Also:
Storable.toXML()

extractFurtherInfos

protected void extractFurtherInfos(StringBuffer representation)
                            throws NonParsableException
Description copied from class: AnnotatedEntity
This method can be used in the constructor with parameter StringBuffer to extract the further information.

Overrides:
extractFurtherInfos in class Parameter
Parameters:
representation - a XML represenation of the main information as StringBuffer
Throws:
NonParsableException - if the XML representation is not parsable
See Also:
AnnotatedEntity.AnnotatedEntity(StringBuffer)

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 used in this SimpleParameter

setValidator

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

Parameters:
validator - the new parameter validator

toString

public String toString()
Overrides:
toString in class Object

toGalaxy

public void toGalaxy(String namePrefix,
                     String configPrefix,
                     int depth,
                     StringBuffer descBuffer,
                     StringBuffer configBuffer)
              throws Exception
Description copied from interface: GalaxyConvertible
Creates an Galaxy XML-representation of the parameters and appends it to descBuffer and variable configuration and appends it to configBuffer. The variable configuation is also used to parse user-supplied values returned by Galaxy.

Specified by:
toGalaxy in interface GalaxyConvertible
Parameters:
namePrefix - the prefix of the variable name used in Galaxy
configPrefix - the prefix for conditionals
depth - the depth in the parameter hierarchy, used for graphical representation of nesting
descBuffer - the buffer for the parameter description
configBuffer - the buffer for the configuration line
Throws:
Exception - if the conversion fails

fromGalaxy

public void fromGalaxy(String namePrefix,
                       StringBuffer command)
                throws Exception
Description copied from interface: GalaxyConvertible
Parses the contents of command in the format defined by configBuffer of GalaxyConvertible.toGalaxy(String, String, int, StringBuffer, StringBuffer) and sets the values of the Parameter or ParameterSet accordingly.

Specified by:
fromGalaxy in interface GalaxyConvertible
Parameters:
namePrefix - the prefix of the variable name
command - the command string
Throws:
Exception - if the command string could not be parsed