public class OptionModule extends java.lang.Object implements OptionRegistrar
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
Modifier and Type | Field and Description |
---|---|
static boolean |
DEFAULT_DEPRECATED
The default deprecation status.
|
static java.lang.String |
DEFAULT_DESCRIPTION
The default description.
|
static java.lang.String |
DEFAULT_LONG_OPTION
The default long option.
|
static java.lang.String |
DEFAULT_MODULE_NAME
The default module name.
|
static char |
DEFAULT_SHORT_OPTION
The default short option.
|
Constructor and Description |
---|
OptionModule()
Constructs an OptionModule with the default name.
|
OptionModule(java.lang.String name)
Constructs an OptionModule with the name passed.
|
Modifier and Type | Method and 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.
|
public static final char DEFAULT_SHORT_OPTION
public static final java.lang.String DEFAULT_LONG_OPTION
public static final java.lang.String DEFAULT_DESCRIPTION
public static final boolean DEFAULT_DEPRECATED
public static final java.lang.String DEFAULT_MODULE_NAME
public OptionModule()
public OptionModule(java.lang.String name)
name
- The name of the module.public void register(java.lang.String longOption, Option option)
register
in interface OptionRegistrar
longOption
- The long option name.option
- The option to register.public void register(char shortOption, Option option)
register
in interface OptionRegistrar
shortOption
- The short option name.option
- The option to register.public void register(java.lang.String longOption, char shortOption, Option option)
register
in interface OptionRegistrar
longOption
- The long option name.shortOption
- The short option name.option
- The option to register.public void register(java.lang.String longOption, char shortOption, java.lang.String description, Option option)
register
in interface OptionRegistrar
longOption
- The long option name.shortOption
- The short option name.description
- The description of the option.option
- The option to register.public void register(java.lang.String longOption, char shortOption, java.lang.String description, Option option, boolean deprecated)
register
in interface OptionRegistrar
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.public boolean optionExists(Option option)
option
- The option to check for existance.public boolean optionExists(char shortOption)
shortOption
- The option to check for existance.public boolean optionExists(java.lang.String longOption)
longOption
- The option to check for existance.public java.util.Iterator getOptionIterator()
public Option getOption(char shortOption)
shortOption
- The option to retrieve.public Option getOption(java.lang.String longOption)
longOption
- The option to retrieve.public java.lang.String getHelp()
public void writeFileToPrintStream(java.io.PrintStream ps)
ps
- The print stream to write to.public boolean isDeprecated()
public void setDeprecated(boolean deprecated)
deprecated
- The new status.public void action(char shortOption, char text)
shortOption
- The option to invoke.text
- The text to pass to the modifier.public void action(java.lang.String longOption, char text)
longOption
- The option to invoke.text
- The text to pass to the modifier.public void action(char shortOption, java.lang.String text)
shortOption
- The option to invoke.text
- The text to pass to the modifier.public void action(java.lang.String longOption, java.lang.String text)
longOption
- The option to invoke.text
- The text to pass to the modifier.public void setName(java.lang.String name)
name
- The new name.public java.lang.String getName()