allensoft.util
Class OptionsParser

java.lang.Object
  |
  +--allensoft.util.OptionsParser
Direct Known Subclasses:
AddOptionsParser, CheckoutOptionsParser, CommitOptionsParser, DiffOptionsParser, ExportOptionsParser, GlobalOptionsParser, ImportOptionsParser, RemoveOptionsParser, TagOptionsParser, UpdateOptionsParser

public abstract class OptionsParser
extends java.lang.Object

A useful class for parsing options specified in a string. Subclasses should override the processOption method to process each option parsed by the parser.


Inner Class Summary
protected static class OptionsParser.ListOfOptions
          Defines a list of options.
protected static class OptionsParser.Option
          Defines an option parsed from a command line.
static class OptionsParser.OptionDefinition
          Describes an option and how it can be specified on a command line.
static class OptionsParser.OptionGroup
          Defines agroup for mutually exclusive options.
 
Constructor Summary
OptionsParser()
           
 
Method Summary
protected  OptionsParser.OptionDefinition addOptionDefinition(java.lang.String sName)
          Adds a new option description to the list of options.
protected abstract  java.lang.Object createOptions()
          Creates the Options object for this parser.
 boolean getAllowSingleCharFlagsToBeGroupedTogether()
           
 OptionsParser.OptionDefinition getOptionDefinition(int nIndex)
           
 OptionsParser.OptionDefinition getOptionDefinition(java.lang.String sOption)
           
 int getOptionDefinitionCount()
           
 char getOptionIdentifier()
           
 java.lang.Object parseOptions(java.lang.String sOptions, java.text.ParsePosition p)
          Parses the supllied string and calls the processOption method for each option found in the string.
protected  void processOption(java.lang.Object options, OptionsParser.Option option, OptionsParser.ListOfOptions previousOptions)
          Override this method to process an individual option.
protected  void processUnrecognizedOption(java.lang.String sOption, int nStartOfOption)
           
 void setAllowSingleCharFlagsToBeGroupedTogether(boolean b)
           
 void setOptionIdentifier(char cIdentifier)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OptionsParser

public OptionsParser()
Method Detail

getOptionDefinitionCount

public int getOptionDefinitionCount()

getOptionDefinition

public OptionsParser.OptionDefinition getOptionDefinition(int nIndex)

getOptionDefinition

public OptionsParser.OptionDefinition getOptionDefinition(java.lang.String sOption)

getOptionIdentifier

public char getOptionIdentifier()

setOptionIdentifier

public void setOptionIdentifier(char cIdentifier)

getAllowSingleCharFlagsToBeGroupedTogether

public boolean getAllowSingleCharFlagsToBeGroupedTogether()

setAllowSingleCharFlagsToBeGroupedTogether

public void setAllowSingleCharFlagsToBeGroupedTogether(boolean b)

createOptions

protected abstract java.lang.Object createOptions()
Creates the Options object for this parser.

parseOptions

public java.lang.Object parseOptions(java.lang.String sOptions,
                                     java.text.ParsePosition p)
                              throws java.text.ParseException
Parses the supllied string and calls the processOption method for each option found in the string.
Returns:
the options object that represents the options.

processOption

protected void processOption(java.lang.Object options,
                             OptionsParser.Option option,
                             OptionsParser.ListOfOptions previousOptions)
                      throws java.text.ParseException
Override this method to process an individual option.
Parameters:
options - the options object to update the state of given this option. This object is created by the createOptions method.
option - an option parsed from the command line
previousOptions - a list of previously parsed options before this option was reached (ie options specified on the command line before this option).

addOptionDefinition

protected OptionsParser.OptionDefinition addOptionDefinition(java.lang.String sName)
Adds a new option description to the list of options.

processUnrecognizedOption

protected void processUnrecognizedOption(java.lang.String sOption,
                                         int nStartOfOption)
                                  throws java.text.ParseException