proper.io
Class CommandLine

java.lang.Object
  extended by proper.io.CommandLine
All Implemented Interfaces:
XMLAccessInterface

public class CommandLine
extends java.lang.Object
implements XMLAccessInterface

This class process an array of strings and aligns the commandline parameter and its value. A parameter starts with "-" or "/" and the value is separated by a blank. The parameters are case-sensitive, i.e. "-o" and "-O" are two different parameters.

Version:
$Revision: 1.3 $
Author:
FracPete

Constructor Summary
CommandLine()
          initializes the object
CommandLine(java.lang.String[] args)
          initializes the object and parses the array
CommandLine(java.util.Vector args)
          initializes the object and parses the string vector
 
Method Summary
 void addParameterDefinition(CommandLineParameter p)
          adds the given parameter to the definition list
 void clearParameterDefinitions()
          removes all the parameter definitions
 boolean exists(java.lang.String parameter)
          tests whether the given parameter was provided in the array
 void fromXML(Element node)
          reads all the data stored in the children of the given node (= container) The children must be provided in an ANT compatible way, i.e.
 java.util.Vector getErroneous()
          returns a vector with all the erroneous parameters (the names)
 java.util.Vector getMissing()
          returns a vector with all the missing parameters (the names)
 java.util.Vector getParameterDefinitions()
          returns all the stored definitions of parameters
 java.util.Vector getParameters()
          returns all the parameters (not the values!) in the commandline
 java.util.Vector getUndefined()
          returns a vector with all the undefined parameters (the names)
 java.lang.String getValue(java.lang.String parameter)
          returns the value that is associated with the given parameter
 java.lang.String getValue(java.lang.String parameter, java.lang.String defaultValue)
          returns the value that is associated with the given parameter
 boolean hasValue(java.lang.String parameter)
          tests whether the given parameter has a value
 boolean isComplete()
          checks whether all necessary parameters were provided
static void main(java.lang.String[] args)
          for testing only
 void setArguments(java.lang.String[] args)
          sets the parameters to parse
 void setValue(java.lang.String parameter, java.lang.String value)
          sets the value for the given parameter, e.g.
 java.lang.String[] toArray()
          returns the parameters as an string array
 java.lang.String toString()
          the commandline parameters in string representation
 java.util.Vector toVector()
          returns the arguments in an vector
 Element toXML()
          returns the content in an XML structure, where the actual data is stored in the children of the returned Element, i.e.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CommandLine

public CommandLine()
initializes the object


CommandLine

public CommandLine(java.util.Vector args)
initializes the object and parses the string vector


CommandLine

public CommandLine(java.lang.String[] args)
initializes the object and parses the array

Method Detail

clearParameterDefinitions

public void clearParameterDefinitions()
removes all the parameter definitions


addParameterDefinition

public void addParameterDefinition(CommandLineParameter p)
adds the given parameter to the definition list

Parameters:
p - the parameter definition to add

getParameterDefinitions

public java.util.Vector getParameterDefinitions()
returns all the stored definitions of parameters

Returns:
the stored parameter definitions

setArguments

public void setArguments(java.lang.String[] args)
sets the parameters to parse

Parameters:
args - the parameters to use

isComplete

public boolean isComplete()
checks whether all necessary parameters were provided


exists

public boolean exists(java.lang.String parameter)
tests whether the given parameter was provided in the array

Parameters:
parameter - the parameter to check for existence
Returns:
whether the parameter is in the commandline

hasValue

public boolean hasValue(java.lang.String parameter)
tests whether the given parameter has a value

Parameters:
parameter - the parameter to check for its value
Returns:
whether the parameter has a value

getValue

public java.lang.String getValue(java.lang.String parameter)
returns the value that is associated with the given parameter

Parameters:
parameter - the parameter to retrieve the value from
Returns:
the value associated with the parameter

getValue

public java.lang.String getValue(java.lang.String parameter,
                                 java.lang.String defaultValue)
returns the value that is associated with the given parameter

Parameters:
parameter - the parameter to retrieve the value from
defaultValue - the default value of this parameter if it is non existing
Returns:
the value associated with the parameter

setValue

public void setValue(java.lang.String parameter,
                     java.lang.String value)
sets the value for the given parameter, e.g. for overriding command line parameters

Parameters:
parameter - the name of the parameter to set
value - the value of the parameter

getParameters

public java.util.Vector getParameters()
returns all the parameters (not the values!) in the commandline

Returns:
all parameters in the commandline

getErroneous

public java.util.Vector getErroneous()
returns a vector with all the erroneous parameters (the names)


getMissing

public java.util.Vector getMissing()
returns a vector with all the missing parameters (the names)


getUndefined

public java.util.Vector getUndefined()
returns a vector with all the undefined parameters (the names)


toString

public java.lang.String toString()
the commandline parameters in string representation

Overrides:
toString in class java.lang.Object

toVector

public java.util.Vector toVector()
returns the arguments in an vector


toArray

public java.lang.String[] toArray()
returns the parameters as an string array


toXML

public Element toXML()
returns the content in an XML structure, where the actual data is stored in the children of the returned Element, i.e. the returned node acts only as a container. The arguments are returned in an ANT compatible way, i.e. as <arg value="..."> nodes

Specified by:
toXML in interface XMLAccessInterface
Returns:
the Element containing the data in its children

fromXML

public void fromXML(Element node)
reads all the data stored in the children of the given node (= container) The children must be provided in an ANT compatible way, i.e. as <arg value="..."> nodes

Specified by:
fromXML in interface XMLAccessInterface
Parameters:
node - the Element node containing the data in its children

main

public static void main(java.lang.String[] args)
for testing only