public abstract class OptionProcessor extends Object
ServiceProvider
in order to register it for participation on handling
and processing of command line options initiated by
CommandLine.getDefault()
's
CommandLine.process(java.lang.String...)
.
When the Option
s provided by this processor are found
on the command line and are consistent, this processor's OptionProcessor.process(org.netbeans.spi.sendopts.Env, java.util.Map<org.netbeans.spi.sendopts.Option, java.lang.String[]>)
method is going to be called to handle their values and invoke an action.
Looking forward: consider using declarative annotations
for
registering your options more effectively.
The usual pattern for writing a subclass of processor is:
@
ServiceProvider
(service=OptionProcessor.class) public class MyProcessor extends OptionProcessor { private Option option1 = ...; private Option option2 = ...; private Option option3 = ...; protected Set<Option> getOptions() { Set<Option> set = new HashSet<Option>(); set.add(option1); set.add(option2); set.add(option3); return set; } protected void process(Env env, Map<Option,String[]> values) throwsCommandException
{ if (values.containsKey(option1)) { ... } if (values.containsKey(option2)) { ... } if (values.containsKey(option3)) { ... } } }
Modifier | Constructor and Description |
---|---|
protected |
OptionProcessor()
Constructor for subclasses.
|
Modifier and Type | Method and Description |
---|---|
protected abstract Set<Option> |
getOptions()
Method to override in subclasses to create
the right set of
Option s. |
protected abstract void |
process(Env env,
Map<Option,String[]> optionValues)
Called by the sendopts parsing infrastructure as a result of
CommandLine.process(java.lang.String...) . |
protected abstract Set<Option> getOptions()
Option
s.
See the factory methods that are part of the Option
's javadoc
or read the
usecases for the sendopts API.
OptionProcessor.process(org.netbeans.spi.sendopts.Env, java.util.Map<org.netbeans.spi.sendopts.Option, java.lang.String[]>)
method will be invoked to
handle such option and its valuesprotected abstract void process(Env env, Map<Option,String[]> optionValues) throws CommandException
CommandLine.process(java.lang.String...)
. The method shall read the values
associated with the option(s) this OptionProcessor
defines
and invoke an action to handle them. While doing this it can
communicate with external world using its environment (see Env
).
Such environment provides access to current user directory, standard
output and error streams, as well standard input stream. In case
the processing of options fails, the code shall thrown CommandException
.env
- the environment to communicate withoptionValues
- map of all options that appeared on command line with their valuesCommandException
- in case the processing fails1