Class OptionModule

java.lang.Object
gnu.dtools.ritopt.OptionModule
All Implemented Interfaces:
OptionRegistrar

public class OptionModule extends Object implements OptionRegistrar
This class is used as a repository for options. The Options class maintains an OptionModule repository for general options. The user may create option modules so that their options can overlap and be categorized. Option modules are invoked by specifying the option name delimited with square brackets.

For example, suppose we are writing a program called ServerManager that manages both an ftp and http server. One option that both a ftp and http kernel might have in common is the number of seconds before a request times out. Option modules are used to process two different values with the same option name. The shell command below demonstrates how two different modules are invoked.

  java ServerManager :http: --timeout=15 :ftp: --timeout=25
 
Refer to the tutorial for more information on how to use option modules.
 Copyright (C) Damian Ryan Eads, 2001. All Rights Reserved.

 ritopt is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 ritopt is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with ritopt; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
    The default deprecation status.
    static final String
    The default description.
    static final String
    The default long option.
    static final String
    The default module name.
    static final char
    The default short option.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an OptionModule with the default name.
    Constructs an OptionModule with the name passed.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    action(char shortOption, char text)
    Called by the OptionsProcessor when an option in the target module is invoked.
    void
    action(char shortOption, String text)
    Called by the OptionsProcessor when an option in the target module is invoked.
    void
    action(String longOption, char text)
    Called by the OptionsProcessor when an option in the target module is invoked.
    void
    action(String longOption, String text)
    Called by the OptionsProcessor when an option in the target module is invoked.
    Returns the help information as a String.
    Returns the name of this module.
    getOption(char shortOption)
    Returns the option referred by the long option passed.
    getOption(String longOption)
    Returns the option referred by the long option passed.
    Return an iterator over the option repository contained in this module.
    boolean
    Returns whether this module is deprecated.
    boolean
    optionExists(char shortOption)
    Returns whether the option referred by a short option exists in this module.
    boolean
    Returns whether the option exists in this module.
    boolean
    optionExists(String longOption)
    Returns whether the option referred by a long option exists in this module.
    void
    register(char shortOption, Option option)
    Register an option into the repository as a short option.
    void
    register(String longOption, char shortOption, Option option)
    Register an option into the repository both as a short and long option.
    void
    register(String longOption, char shortOption, String description, Option option)
    Register an option into the repository both as a short and long option.
    void
    register(String longOption, char shortOption, String description, Option option, boolean deprecated)
    Register an option into the repository both as a short and long option.
    void
    register(String longOption, Option option)
    Register an option into the repository as a long option.
    void
    setDeprecated(boolean deprecated)
    Sets whether this module is deprecated.
    void
    Set the name of this module.
    void
    Writes the help information to a print stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_SHORT_OPTION

      public static final char DEFAULT_SHORT_OPTION
      The default short option.
      See Also:
    • DEFAULT_LONG_OPTION

      public static final String DEFAULT_LONG_OPTION
      The default long option.
    • DEFAULT_DESCRIPTION

      public static final String DEFAULT_DESCRIPTION
      The default description.
      See Also:
    • DEFAULT_DEPRECATED

      public static final boolean DEFAULT_DEPRECATED
      The default deprecation status.
      See Also:
    • DEFAULT_MODULE_NAME

      public static final String DEFAULT_MODULE_NAME
      The default module name.
      See Also:
  • Constructor Details

    • OptionModule

      public OptionModule()
      Constructs an OptionModule with the default name.
    • OptionModule

      public OptionModule(String name)
      Constructs an OptionModule with the name passed.
      Parameters:
      name - The name of the module.
  • Method Details

    • register

      public void register(String longOption, Option option)
      Register an option into the repository as a long option.
      Specified by:
      register in interface OptionRegistrar
      Parameters:
      longOption - The long option name.
      option - The option to register.
    • register

      public void register(char shortOption, Option option)
      Register an option into the repository as a short option.
      Specified by:
      register in interface OptionRegistrar
      Parameters:
      shortOption - The short option name.
      option - The option to register.
    • register

      public void register(String longOption, char shortOption, Option option)
      Register an option into the repository both as a short and long option.
      Specified by:
      register in interface OptionRegistrar
      Parameters:
      longOption - The long option name.
      shortOption - The short option name.
      option - The option to register.
    • register

      public void register(String longOption, char shortOption, String description, Option option)
      Register an option into the repository both as a short and long option. Initialize its description with the description passed.
      Specified by:
      register in interface OptionRegistrar
      Parameters:
      longOption - The long option name.
      shortOption - The short option name.
      description - The description of the option.
      option - The option to register.
    • register

      public void register(String longOption, char shortOption, String description, Option option, boolean deprecated)
      Register an option into the repository both as a short and long option. Initialize its description with the description passed.
      Specified by:
      register in interface OptionRegistrar
      Parameters:
      longOption - The long option name.
      shortOption - The short option name.
      description - The description of the option.
      option - The option to register.
      deprecated - A boolean indicating whether an option should be deprecated.
    • optionExists

      public boolean optionExists(Option option)
      Returns whether the option exists in this module.
      Parameters:
      option - The option to check for existance.
      Returns:
      A boolean value indicating whether the option passed exists.
    • optionExists

      public boolean optionExists(char shortOption)
      Returns whether the option referred by a short option exists in this module.
      Parameters:
      shortOption - The option to check for existance.
      Returns:
      A boolean value indicating whether the option passed exists.
    • optionExists

      public boolean optionExists(String longOption)
      Returns whether the option referred by a long option exists in this module.
      Parameters:
      longOption - The option to check for existance.
      Returns:
      A boolean value indicating whether the option passed exists.
    • getOptionIterator

      public Iterator getOptionIterator()
      Return an iterator over the option repository contained in this module.
      Returns:
      An iterator over the repository.
    • getOption

      public Option getOption(char shortOption)
      Returns the option referred by the long option passed.
      Parameters:
      shortOption - The option to retrieve.
      Returns:
      An option referred to by this module. null is returned if it does not exist.
    • getOption

      public Option getOption(String longOption)
      Returns the option referred by the long option passed.
      Parameters:
      longOption - The option to retrieve.
      Returns:
      An option referred to by this module. null is returned if it does not exist.
    • getHelp

      public String getHelp()
      Returns the help information as a String.
      Returns:
      The help information as a String.
    • writeFileToPrintStream

      public void writeFileToPrintStream(PrintStream ps)
      Writes the help information to a print stream.
      Parameters:
      ps - The print stream to write to.
    • isDeprecated

      public boolean isDeprecated()
      Returns whether this module is deprecated.
      Returns:
      A boolean value indicating whether this module is deprecated.
    • setDeprecated

      public void setDeprecated(boolean deprecated)
      Sets whether this module is deprecated.
      Parameters:
      deprecated - The new status.
    • action

      public void action(char shortOption, char text)
      Called by the OptionsProcessor when an option in the target module is invoked.
      Parameters:
      shortOption - The option to invoke.
      text - The text to pass to the modifier.
    • action

      public void action(String longOption, char text)
      Called by the OptionsProcessor when an option in the target module is invoked.
      Parameters:
      longOption - The option to invoke.
      text - The text to pass to the modifier.
    • action

      public void action(char shortOption, String text)
      Called by the OptionsProcessor when an option in the target module is invoked.
      Parameters:
      shortOption - The option to invoke.
      text - The text to pass to the modifier.
    • action

      public void action(String longOption, String text)
      Called by the OptionsProcessor when an option in the target module is invoked.
      Parameters:
      longOption - The option to invoke.
      text - The text to pass to the modifier.
    • setName

      public void setName(String name)
      Set the name of this module.
      Parameters:
      name - The new name.
    • getName

      public String getName()
      Returns the name of this module.
      Returns:
      The name of this module.