Class OptionModule

  • All Implemented Interfaces:
    OptionRegistrar

    public class OptionModule
    extends java.lang.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
     
    • Constructor Summary

      Constructors 
      Constructor Description
      OptionModule()
      Constructs an OptionModule with the default name.
      OptionModule​(java.lang.String name)
      Constructs an OptionModule with the name passed.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      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, java.lang.String text)
      Called by the OptionsProcessor when an option in the target module is invoked.
      void action​(java.lang.String longOption, char text)
      Called by the OptionsProcessor when an option in the target module is invoked.
      void action​(java.lang.String longOption, java.lang.String text)
      Called by the OptionsProcessor when an option in the target module is invoked.
      java.lang.String getHelp()
      Returns the help information as a String.
      java.lang.String getName()
      Returns the name of this module.
      Option getOption​(char shortOption)
      Returns the option referred by the long option passed.
      Option getOption​(java.lang.String longOption)
      Returns the option referred by the long option passed.
      java.util.Iterator getOptionIterator()
      Return an iterator over the option repository contained in this module.
      boolean isDeprecated()
      Returns whether this module is deprecated.
      boolean optionExists​(char shortOption)
      Returns whether the option referred by a short option exists in this module.
      boolean optionExists​(Option option)
      Returns whether the option exists in this module.
      boolean optionExists​(java.lang.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​(java.lang.String longOption, char shortOption, Option option)
      Register an option into the repository both as a short and long option.
      void register​(java.lang.String longOption, char shortOption, java.lang.String description, Option option)
      Register an option into the repository both as a short and long option.
      void register​(java.lang.String longOption, char shortOption, java.lang.String description, Option option, boolean deprecated)
      Register an option into the repository both as a short and long option.
      void register​(java.lang.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 setName​(java.lang.String name)
      Set the name of this module.
      void writeFileToPrintStream​(java.io.PrintStream ps)
      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 Detail

      • DEFAULT_SHORT_OPTION

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

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

        public static final java.lang.String DEFAULT_DESCRIPTION
        The default description.
        See Also:
        Constant Field Values
      • DEFAULT_DEPRECATED

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

        public static final java.lang.String DEFAULT_MODULE_NAME
        The default module name.
        See Also:
        Constant Field Values
    • Constructor Detail

      • OptionModule

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

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

      • register

        public void register​(java.lang.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​(java.lang.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​(java.lang.String longOption,
                             char shortOption,
                             java.lang.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​(java.lang.String longOption,
                             char shortOption,
                             java.lang.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​(java.lang.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 java.util.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​(java.lang.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 java.lang.String getHelp()
        Returns the help information as a String.
        Returns:
        The help information as a String.
      • writeFileToPrintStream

        public void writeFileToPrintStream​(java.io.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​(java.lang.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,
                           java.lang.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​(java.lang.String longOption,
                           java.lang.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​(java.lang.String name)
        Set the name of this module.
        Parameters:
        name - The new name.
      • getName

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