com.tensegrity.generic.util
Class CommandLine

java.lang.Object
  extended byjava.util.AbstractMap
      extended byjava.util.HashMap
          extended bycom.tensegrity.generic.util.CommandLine
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class CommandLine
extends java.util.HashMap

Applications and Applets often have to be provided with parameters passed to them at startup. Class CommandLine can be used to parse such arguments via the command line (Application) or parameter tags (Applet).

When creating an CommandLine instance, be aware of the defined sequence of parameters in the 2-dimensional array (the second parameter of a particular constructor).

The arguments are described in the array possibleValues. The expected format of this array is described here:

 - Parameter name ([][0]):     
      Name of the parameter without the leading '-'.
 
 - Optional (Boolean) ([][1]): 
      Boolean.TRUE, if this parameter is mandatory.
 
 - Default value ([][2]):
      The default value, if the no value for this parameter is specified. 
 
 - Usage text ([][3]):
      A short description telling what this option does
 

Version:
$Id: CommandLine.java,v 1.31 2006/04/07 14:48:27 BurkhardWick Exp $
Author:
MartinGerlach
See Also:
Serialized Form

Constructor Summary
CommandLine(java.applet.Applet applet, CommandLinePossibleValues possibleValues)
          Constructor for use with applets.
CommandLine(java.applet.Applet applet, java.lang.Object[][] possibleValues)
          Constructor for use with applets.
CommandLine(java.lang.String[] commandLine, CommandLinePossibleValues possibleValues)
          Constructor for use with applications.
CommandLine(java.lang.String[] commandLine, java.lang.Object[][] possibleValues)
          Constructor for use with applications.
 
Method Summary
 boolean booleanValue(java.lang.String parameter)
          Returns true, if the given boolean parameter is given on command line.
 void dumpUsage(java.lang.String indent, java.io.OutputStream stream)
          This methods dumps the descriptions for all registered parameter.
 java.lang.String toString()
          Returns a string representation of this.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

CommandLine

public CommandLine(java.lang.String[] commandLine,
                   CommandLinePossibleValues possibleValues)
            throws java.text.ParseException
Constructor for use with applications.

Parameters:
commandLine - an array holding the command line as given in a main function.
possibleValues - the possible/default commands/values of the command line.
Throws:
java.text.ParseException - if the given strings can't be parsed.

CommandLine

public CommandLine(java.applet.Applet applet,
                   CommandLinePossibleValues possibleValues)
            throws java.text.ParseException
Constructor for use with applets.

Parameters:
applet - the applet.
possibleValues - the possible/default commands/values for the application.
Throws:
java.text.ParseException - if a given parameter is mandatory, but invalid

CommandLine

public CommandLine(java.lang.String[] commandLine,
                   java.lang.Object[][] possibleValues)
            throws java.text.ParseException
Constructor for use with applications.

Parameters:
commandLine - an array holding the command line as given in a main function.
possibleValues - the possible/default commands/values of the command line.
Throws:
java.text.ParseException - if the given strings can't be parsed.

CommandLine

public CommandLine(java.applet.Applet applet,
                   java.lang.Object[][] possibleValues)
            throws java.text.ParseException
Constructor for use with applets.
 [0] - Parameter name
 [1] - Boolean, indicates whether this parameter is mandatory
 [2] - Default value, indicating the type. Valid types are: 
 
       java.lang.String
       java.lang.Boolean
       java.lang.Integer
       java.lang.Double
       java.lang.Float
       java.lang.Long
 
 [3] - usage text
 

Parameters:
applet - the applet.
possibleValues - the possible/default commands/values for the application.
Throws:
java.text.ParseException - if a given parameter is mandatory, but invalid
Method Detail

booleanValue

public boolean booleanValue(java.lang.String parameter)
Returns true, if the given boolean parameter is given on command line. If not, it returns the default value. If the parameter is not found false will be returned.

Parameters:
parameter - the parameter name to look up
Returns:
a boolean value representing the state of the parameter or false if an exception occurs.

dumpUsage

public void dumpUsage(java.lang.String indent,
                      java.io.OutputStream stream)
               throws java.io.IOException
This methods dumps the descriptions for all registered parameter.

Parameters:
indent - a string used to be insert before every line output.
stream - the stream to dump to.
Throws:
java.io.IOException - if an I/O error occurs.

toString

public java.lang.String toString()
Returns a string representation of this.

Returns:
a string representation of this.


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.