de.jstacs.parameters
Class FileParameter

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

public class FileParameter
extends Parameter
implements GalaxyConvertible

Class for a Parameter that represents a local file.

Author:
Jan Grau

Nested Class Summary
static class FileParameter.FileRepresentation
          Class that represents a file.
 
Field Summary
 
Fields inherited from class de.jstacs.parameters.Parameter
parent
 
Fields inherited from class de.jstacs.AnnotatedEntity
comment, datatype, name
 
Constructor Summary
FileParameter(StringBuffer buf)
          The standard constructor for the interface Storable.
FileParameter(String name, String comment, String mime, boolean required)
          Creates a FileParameter.
FileParameter(String name, String comment, String mime, boolean required, ParameterValidator validator)
          Constructs a FileParameter.
 
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.
 FileParameter clone()
           
protected  void extractFurtherInfos(StringBuffer buf)
          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, boolean) and sets the values of the Parameter or ParameterSet accordingly.
 String getAcceptedMimeType()
          Returns the MIME-type of the allowed files.
 String getErrorMessage()
          If a value could not be set successfully this method returns the corresponding error message.
 FileParameter.FileRepresentation getFileContents()
          Returns the content of the file.
 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 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 FileParameter to its original state.
 void setDefault(Object defaultValue)
          Sets the default value of the Parameter to defaultValue.
 void setValue(Object value)
          Sets the value of this Parameter to value.
 void toGalaxy(String namePrefix, String configPrefix, int depth, StringBuffer descBuffer, StringBuffer configBuffer, boolean addLine)
          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
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileParameter

public FileParameter(StringBuffer buf)
              throws NonParsableException
The standard constructor for the interface Storable. Restores a FileParameter from an XML representation.

Parameters:
buf - the XML representation as StringBuffer
Throws:
NonParsableException - if the XML code could not be parsed

FileParameter

public FileParameter(String name,
                     String comment,
                     String mime,
                     boolean required)
Creates a FileParameter.

Parameters:
name - the name of the parameter
comment - a comment on the parameter
mime - the MIME-type of allowed files
required - true if this FileParameter is required to continue, false otherwise

FileParameter

public FileParameter(String name,
                     String comment,
                     String mime,
                     boolean required,
                     ParameterValidator validator)
Constructs a FileParameter.

Parameters:
name - the name of the parameter
comment - a comment on the parameter
mime - the MIME-type of allowed files
required - true if this FileParameter is required
validator - a validator that validates e.g. the contents of the file
Method Detail

clone

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

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

reset

public void reset()
Resets the FileParameter to its original state.

Specified by:
reset in class Parameter

getFileContents

public FileParameter.FileRepresentation getFileContents()
Returns the content of the file.

Returns:
the content of the file

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

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

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

setValue

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

Specified by:
setValue in class Parameter
Parameters:
value - 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

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

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 buf)
                            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:
buf - a XML represenation of the main information as StringBuffer
Throws:
NonParsableException - if the XML representation is not parsable
See Also:
AnnotatedEntity.AnnotatedEntity(StringBuffer)

getAcceptedMimeType

public String getAcceptedMimeType()
Returns the MIME-type of the allowed files.

Returns:
the MIME-type of the allowed files

toGalaxy

public void toGalaxy(String namePrefix,
                     String configPrefix,
                     int depth,
                     StringBuffer descBuffer,
                     StringBuffer configBuffer,
                     boolean addLine)
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 configuration 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
addLine - if true, a line is added before the title of a parameter

toString

public String toString()
Overrides:
toString in class Object

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, boolean) 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