org.enhydra.xml.xmlc.commands.options
Class Option

java.lang.Object
  |
  +--org.enhydra.xml.xmlc.commands.options.Option
Direct Known Subclasses:
BooleanOption, FlagOption

public abstract class Option
extends Object

Definition of an option. The general or specific options are classes derived from this class. A general class is parameterizes at instantiation and is able to create parse multiple options. A specific class only parses one option. The Option classes should be immutable; a generic client data object is pass to the parse methods to recieve the configuration.


Field Summary
protected  String help
          Help message for the option.
protected  boolean multipleAllowed
          Are multiple instances of the option allowed?
protected  String name
          The option name, including the leading `-'.
protected  int numArgs
          The number of arguments for the option.
 
Constructor Summary
Option(String name, int numArgs, boolean multipleAllowed, String help)
          Construct a new instance of the object.
 
Method Summary
 boolean equals(Object obj)
          Determine if two options are equal.
 String getHelp()
          Get the help string, including option name.
 boolean getMultipleAllowed()
          Return true if the option maybe specified multiple times, resulting in a list of values.
 String getName()
          Get the option name, including leading `-'.
 int getNumArgs()
          Get the number of arguments for a single instance of the option.
 int hashCode()
          Get the hashcode for the object.
protected abstract  void parse(String[] args, ErrorReporter errorReporter, Object clientData)
          Parse an instance of the option.
 
Methods inherited from class java.lang.Object
, clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected final String name
The option name, including the leading `-'.

numArgs

protected final int numArgs
The number of arguments for the option.

multipleAllowed

protected final boolean multipleAllowed
Are multiple instances of the option allowed?

help

protected String help
Help message for the option.
Constructor Detail

Option

public Option(String name,
              int numArgs,
              boolean multipleAllowed,
              String help)
Construct a new instance of the object.
Parameters:
name - Name of the option, including the leading `-'.
numArgs - Number of arguments the option takes.
multipleAllowed - Can the option be specified multiple times?
help - A string that is used in generating the help message. It should include the arguments, a `-', then one line message. The option name and a space will be prepended.
Method Detail

getName

public String getName()
Get the option name, including leading `-'.

getNumArgs

public int getNumArgs()
Get the number of arguments for a single instance of the option. If the option repeats, the actual number of arguments is a multiple of this.

getMultipleAllowed

public boolean getMultipleAllowed()
Return true if the option maybe specified multiple times, resulting in a list of values. Return false if the option can only be specified once.

getHelp

public String getHelp()
Get the help string, including option name.

equals

public boolean equals(Object obj)
Determine if two options are equal. Only the name is considered. It is illegal to have options with the same name and different attributes.
Overrides:
equals in class Object
Parameters:
obj - This can be either another Option object or a string. If an Option object is supplied, the names are compared.
Returns:
True if this object name is the same as the name in

hashCode

public int hashCode()
Get the hashcode for the object.
Overrides:
hashCode in class Object

parse

protected abstract void parse(String[] args,
                              ErrorReporter errorReporter,
                              Object clientData)
                       throws XMLCException
Parse an instance of the option.
Parameters:
args - The option's arguments. Will always have the number of arguments defined for an option.
errorReporter - Used to report warnings, such as deprecated options. Errors should be thrown.
clientData - Object that is passed to the parser. Normally contains the object to store the configuration in.


Copyright © 1999-2002 enhydra.org (Mark Diekhans, David Li, Richard Kunze). All Rights reserved.