BEA Systems, Inc.

com.beasys.commerce.util
Class ArgsParser

java.lang.Object
  |
  +--com.beasys.commerce.util.ArgsParser

public abstract class ArgsParser
extends java.lang.Object

Parses the arguments passed to public static void main(String args[]) Subclasses specify their application's grammar in the constructor.


Inner Class Summary
static interface ArgsParser.HelpSpecifiedException
          The user specified -? or -h
static interface ArgsParser.UsageException
          The user entered unparseable data
 
Constructor Summary
protected ArgsParser(java.lang.String commandName, java.lang.String commandDefinition, java.lang.String[] args)
           
 
Method Summary
protected  void addParameter(java.lang.String name, boolean required, java.lang.String defaultValue, java.lang.String definition)
          Specify a command parameter.
protected  void addParameter(java.lang.String name, boolean required, java.lang.String defaultValue, java.lang.String[] validValues, java.lang.String definition, java.lang.String[] validValuesDefinition)
          Specify a command parameter, restricted to specific values.
protected  void addQualifier(java.lang.String name, boolean required, java.lang.String defaultValue, java.lang.String definition)
          Specify a command qualifier.
protected  void addQualifier(java.lang.String name, boolean required, java.lang.String defaultValue, java.lang.String[] validValues, java.lang.String definition, java.lang.String[] validValuesDefinition)
          Specify a command qualifier, restricted to specific values.
 boolean getParameterSpecified(java.lang.String name)
           
 java.lang.String getParameterValue(java.lang.String name)
          Retreive the value of a parameter.
 boolean getQualifierSpecified(java.lang.String name)
           
 java.lang.String getQualifierValue(java.lang.String name)
          Retreive the value of a qualifier.
 void parse()
          Parse the command line
 void printUsage(java.io.PrintStream printStream)
          Print a usage message
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArgsParser

protected ArgsParser(java.lang.String commandName,
                     java.lang.String commandDefinition,
                     java.lang.String[] args)
Parameters:
commandName - the name of the command (used in printUsage())
commandDefinition - the definition of the command (used in printUsage())
args - command line arguments (parameter of public static void main(String args[])
Method Detail

printUsage

public void printUsage(java.io.PrintStream printStream)
Print a usage message
Parameters:
printStream - the target stream for the usage message

parse

public void parse()
           throws ArgsParser.UsageException,
                  ArgsParser.HelpSpecifiedException,
                  java.lang.Error
Parse the command line
Throws:
ArgsParser.UsageException - the user entered unparseable data. You should print this exceptions's getMessage(), followed by printUsage()
ArgsParser.HelpSpecifiedException - the user specified "-?" or "-h". You should call printUsage() for this exception.
java.lang.Error - a development bug. call getMessage() for the reason

addQualifier

protected void addQualifier(java.lang.String name,
                            boolean required,
                            java.lang.String defaultValue,
                            java.lang.String[] validValues,
                            java.lang.String definition,
                            java.lang.String[] validValuesDefinition)
Specify a command qualifier, restricted to specific values. Subclasses use this to specify grammar in their constructors.
Parameters:
name - the name of the qualifier. The name must begin with "-"
required - set to true if the qualifier is required
defaultValue - default value of the qualifier. set to null if no default value
validValues - array of restrictions for values of this qualifier
definition - the definition of this qualifier. Used in printUsage()
validValuesDefinition - definition of each valid value. Used in printUsage();

addQualifier

protected void addQualifier(java.lang.String name,
                            boolean required,
                            java.lang.String defaultValue,
                            java.lang.String definition)
Specify a command qualifier. Subclasses use this to specify grammar in their constructors.
Parameters:
name - the name of the qualifier. The name must begin with "-"
required - set to true if the qualifier is required
defaultValue - default value of the qualifier. set to null if no default value
definition - the definition of this qualifier. Used in printUsage()

addParameter

protected void addParameter(java.lang.String name,
                            boolean required,
                            java.lang.String defaultValue,
                            java.lang.String[] validValues,
                            java.lang.String definition,
                            java.lang.String[] validValuesDefinition)
Specify a command parameter, restricted to specific values. Subclasses use this to specify grammar in their constructors.
Parameters:
name - the name of the parameter.
required - set to true if the parameter is required
defaultValue - default value of the parameter. set to null if no default value
validValues - array of restrictions for values of this parameter
definition - the definition of this parameter. Used in printUsage()
validValuesDefinition - definition of each valid value. Used in printUsage();

addParameter

protected void addParameter(java.lang.String name,
                            boolean required,
                            java.lang.String defaultValue,
                            java.lang.String definition)
Specify a command parameter. Subclasses use this to specify grammar in their constructors.
Parameters:
name - the name of the parameter.
required - set to true if the parameter is required
defaultValue - default value of the parameter. set to null if no default value
definition - the definition of this parameter. Used in printUsage()

getQualifierValue

public java.lang.String getQualifierValue(java.lang.String name)
                                   throws java.lang.Error
Retreive the value of a qualifier. If the qualifer was not specified on the command line, the default value is returned if it exists. Otherwise, null is returned. Use getQualifierSpecified() to determine if the qualifier was actually specified on the command line.
Parameters:
name - the name of a qualifier
Returns:
the value of a qualifier. Call this function AFTER calling parse().
Throws:
java.lang.Error - a development bug
See Also:
getQualifierSpecified(java.lang.String)

getQualifierSpecified

public boolean getQualifierSpecified(java.lang.String name)
                              throws java.lang.Error
Parameters:
the - name of a qualifier
Returns:
true if the qualifier was specified on the command line. false if the qualifier was not specified.
Throws:
java.lang.Error - a development bug. call getMessage() for the reason

getParameterValue

public java.lang.String getParameterValue(java.lang.String name)
                                   throws java.lang.Error
Retreive the value of a parameter. If the parameter was not specified on the command line, the default value is returned if it exists. Otherwise, null is returned. Use getParameterSpecified() to determine if the parameter was actually specified on the command line.
Parameters:
name - the name of a parameter
Returns:
the value of a parameter. Call this function AFTER calling parse().
Throws:
java.lang.Error - a development bug. call getMessage() for the reason
See Also:
getParameterSpecified(java.lang.String)

getParameterSpecified

public boolean getParameterSpecified(java.lang.String name)
                              throws java.lang.Error
Parameters:
the - name of a parameter
Returns:
true if the parameter was specified on the command line. false if the parameter was not specified.
Throws:
java.lang.Error - a development bug. call getMessage() for the reason

BEA Systems, Inc.

Copyright © 2000 BEA Systems, Inc. All Rights Reserved