Package gnu.dtools.ritopt
Class OptionModule
java.lang.Object
gnu.dtools.ritopt.OptionModule
- All Implemented Interfaces:
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=25Refer 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 -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an OptionModule with the default name.OptionModule(String name) Constructs an OptionModule with the name passed. -
Method Summary
Modifier and TypeMethodDescriptionvoidaction(char shortOption, char text) Called by the OptionsProcessor when an option in the target module is invoked.voidCalled by the OptionsProcessor when an option in the target module is invoked.voidCalled by the OptionsProcessor when an option in the target module is invoked.voidCalled by the OptionsProcessor when an option in the target module is invoked.getHelp()Returns the help information as a String.getName()Returns the name of this module.getOption(char shortOption) Returns the option referred by the long option passed.Returns the option referred by the long option passed.Return an iterator over the option repository contained in this module.booleanReturns whether this module is deprecated.booleanoptionExists(char shortOption) Returns whether the option referred by a short option exists in this module.booleanoptionExists(Option option) Returns whether the option exists in this module.booleanoptionExists(String longOption) Returns whether the option referred by a long option exists in this module.voidRegister an option into the repository as a short option.voidRegister an option into the repository both as a short and long option.voidRegister an option into the repository both as a short and long option.voidregister(String longOption, char shortOption, String description, Option option, boolean deprecated) Register an option into the repository both as a short and long option.voidRegister an option into the repository as a long option.voidsetDeprecated(boolean deprecated) Sets whether this module is deprecated.voidSet the name of this module.voidWrites the help information to a print stream.
-
Field Details
-
DEFAULT_SHORT_OPTION
public static final char DEFAULT_SHORT_OPTIONThe default short option.- See Also:
-
DEFAULT_LONG_OPTION
The default long option. -
DEFAULT_DESCRIPTION
The default description.- See Also:
-
DEFAULT_DEPRECATED
public static final boolean DEFAULT_DEPRECATEDThe default deprecation status.- See Also:
-
DEFAULT_MODULE_NAME
The default module name.- See Also:
-
-
Constructor Details
-
OptionModule
public OptionModule()Constructs an OptionModule with the default name. -
OptionModule
Constructs an OptionModule with the name passed.- Parameters:
name- The name of the module.
-
-
Method Details
-
register
Register an option into the repository as a long option.- Specified by:
registerin interfaceOptionRegistrar- Parameters:
longOption- The long option name.option- The option to register.
-
register
Register an option into the repository as a short option.- Specified by:
registerin interfaceOptionRegistrar- Parameters:
shortOption- The short option name.option- The option to register.
-
register
Register an option into the repository both as a short and long option.- Specified by:
registerin interfaceOptionRegistrar- Parameters:
longOption- The long option name.shortOption- The short option name.option- The option to register.
-
register
Register an option into the repository both as a short and long option. Initialize its description with the description passed.- Specified by:
registerin interfaceOptionRegistrar- 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:
registerin interfaceOptionRegistrar- 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
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
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
Return an iterator over the option repository contained in this module.- Returns:
- An iterator over the repository.
-
getOption
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
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
Returns the help information as a String.- Returns:
- The help information as a String.
-
writeFileToPrintStream
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
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
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
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
Set the name of this module.- Parameters:
name- The new name.
-
getName
Returns the name of this module.- Returns:
- The name of this module.
-