eaLib API Docs
Last Modified : January 7 2002

mss.ea.core
Class CommandLineParser

java.lang.Object
  |
  +--mss.ea.core.CommandLineParser

public class CommandLineParser
extends java.lang.Object

Command Line Parser. The command line string must have the following format:
[-short-option]|[--long-option][-short-option=value] [--long-option=value] command
The options and the command are stored in the configuration under the keys mss.ea.core.CommandLineParser.command and mss.ea.core.CommandLineParser.options.

Since:
0.2
Version:
$Revision: 1.4 $ $Date: 2001/12/20 14:42:56 $
Author:
Andreas Rummler

Constructor Summary
CommandLineParser()
           
 
Method Summary
protected  int containsEqualSign(java.lang.String s)
          Checks if this string contains an equal sign.
protected  java.lang.String[] getKeyValue(java.lang.String s, int equalSignIndex)
          Extracts option and value from a string.
protected  java.lang.String getLongOption(java.lang.String s)
          Returns the long option from an option string.
protected  java.lang.String getShortOption(java.lang.String s)
          Returns the short option from an option string.
protected  boolean isLetter(char c)
          Checks if this character is a letter.
protected  boolean isWord(java.lang.String s)
          Checks if the given string contains only characters of a "-" sign.
 void parse(java.lang.String commandLine)
          Parses the given string.
 void parse(java.lang.String[] commandLine)
          Parses the given array of strings.
protected  void parseCommand(java.util.LinkedList tokenList)
          Detects the command from the input tokens.
protected  void parseOptions(java.util.LinkedList tokenList)
          Extracts the options from the token lists.
protected  void storeOption(java.lang.String key, java.lang.String value)
          Stores the found options and values in the internal hashtable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLineParser

public CommandLineParser()
Method Detail

parse

public void parse(java.lang.String[] commandLine)
           throws CommandLineParserException
Parses the given array of strings.
Parameters:
commandLine - array of strings to parse
Throws:
CommandLineParserException - thrown in case parsing fails

parse

public void parse(java.lang.String commandLine)
           throws CommandLineParserException
Parses the given string.
Parameters:
commandLine - string to parse
Throws:
CommandLineParserException - thrown in case parsing fails

parseCommand

protected void parseCommand(java.util.LinkedList tokenList)
                     throws CommandLineParserException
Detects the command from the input tokens.
Parameters:
tokenList - string token list
Throws:
CommandLineParserException - thrown in case the last token in the list is not a valid command

parseOptions

protected void parseOptions(java.util.LinkedList tokenList)
                     throws CommandLineParserException
Extracts the options from the token lists.
Parameters:
tokenList - list of string tokens
Throws:
CommandLineParserException - thrown in case the parsing fails

getLongOption

protected java.lang.String getLongOption(java.lang.String s)
Returns the long option from an option string. This checks if the given string starts with "--" and has a length greater 3.
Parameters:
s - string to check for being a long option
Returns:
returns the long option minus the starting "--", null if the given string is not a long option

getShortOption

protected java.lang.String getShortOption(java.lang.String s)
Returns the short option from an option string. This checks if the given string starts with "-" and has a length greater 1.
Parameters:
s - string to check for being a short option
Returns:
returns the short option minus the starting "-", null if the given string is not a short option

getKeyValue

protected java.lang.String[] getKeyValue(java.lang.String s,
                                         int equalSignIndex)
Extracts option and value from a string. The string is cut into two pieces, from start to the given index and from index to end.
Parameters:
s - string to break up
equalSignIndex - index of the equals sign
Returns:
key and value contained in an array

isWord

protected boolean isWord(java.lang.String s)
Checks if the given string contains only characters of a "-" sign.
Parameters:
s - string to check
Returns:
result of the check

isLetter

protected boolean isLetter(char c)
Checks if this character is a letter.
Parameters:
c - character to check
Returns:
result of the test

containsEqualSign

protected int containsEqualSign(java.lang.String s)
Checks if this string contains an equal sign.
Parameters:
s - string to check
Returns:
index of the found equals sign, or -1 instead

storeOption

protected void storeOption(java.lang.String key,
                           java.lang.String value)
Stores the found options and values in the internal hashtable.
Parameters:
key - key to store
value - value to store

eaLib API Docs
Last Modified : January 7 2002

Copyright © 2000-2001 Technical University of Ilmenau, Department ESS