net.dpml.cli.option
Class Switch

java.lang.Object
  extended bynet.dpml.cli.option.OptionImpl
      extended bynet.dpml.cli.option.ParentImpl
          extended bynet.dpml.cli.option.Switch
All Implemented Interfaces:
Option, Parent

public class Switch
extends ParentImpl

A Parent implementation representing normal switch options. For example: +d|-d or --enable-x|--disable-x.

Version:
1.0.0
Author:
Digital Product Meta Library

Field Summary
static String DEFAULT_DISABLED_PREFIX
          The default prefix for disabled switches
static String DEFAULT_ENABLED_PREFIX
          The default prefix for enabled switches
static ResourceHelper RESOURCES
          i18n
 
Constructor Summary
Switch(String enabledPrefix, String disabledPrefix, String preferredName, Set aliases, String description, boolean required, Argument argument, Group children, int id, Boolean switchDefault)
          Creates a new Switch with the specified parameters
 
Method Summary
 void appendUsage(StringBuffer buffer, Set helpSettings, Comparator comp)
          Appends usage information to the specified StringBuffer
 void defaults(WriteableCommandLine commandLine)
          Adds defaults to a CommandLine.
 String getPreferredName()
          The preferred name of an option is used for generating help and usage information.
 Set getPrefixes()
          Identifies the argument prefixes that should be considered options.
 Set getTriggers()
          Identifies the argument prefixes that should trigger this option.
 void processParent(WriteableCommandLine commandLine, ListIterator arguments)
          Processes the parent part of the Option.
 void validate(WriteableCommandLine commandLine)
          Checks that the supplied CommandLine is valid with respect to this option.
 
Methods inherited from class net.dpml.cli.option.ParentImpl
canProcess, findOption, getArgument, getChildren, getDescription, helpLines, process
 
Methods inherited from class net.dpml.cli.option.OptionImpl
canProcess, checkPrefixes, equals, getId, hashCode, isRequired, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.dpml.cli.Option
canProcess, getId, isRequired
 

Field Detail

RESOURCES

public static final ResourceHelper RESOURCES
i18n


DEFAULT_ENABLED_PREFIX

public static final String DEFAULT_ENABLED_PREFIX
The default prefix for enabled switches

See Also:
Constant Field Values

DEFAULT_DISABLED_PREFIX

public static final String DEFAULT_DISABLED_PREFIX
The default prefix for disabled switches

See Also:
Constant Field Values
Constructor Detail

Switch

public Switch(String enabledPrefix,
              String disabledPrefix,
              String preferredName,
              Set aliases,
              String description,
              boolean required,
              Argument argument,
              Group children,
              int id,
              Boolean switchDefault)
       throws IllegalArgumentException
Creates a new Switch with the specified parameters

Parameters:
enabledPrefix - the prefix used for enabled switches
disabledPrefix - the prefix used for disabled switches
preferredName - the preferred name of the switch
aliases - the aliases by which the Switch is known
description - a description of the Switch
required - whether the Option is strictly required
argument - the Argument belonging to this Parent, or null
children - the Group children belonging to this Parent, ot null
id - the unique identifier for this Option
switchDefault - the switch default value
Throws:
IllegalArgumentException - if the preferredName or an alias isn't prefixed with enabledPrefix or disabledPrefix
Method Detail

processParent

public void processParent(WriteableCommandLine commandLine,
                          ListIterator arguments)
                   throws OptionException
Processes the parent part of the Option. The combination of parent, argument and children is handled by the process method.

Parameters:
commandLine - the CommandLine to write results to
arguments - a ListIterator over argument strings positioned at the next argument to process
Throws:
OptionException - if an error occurs while processing
See Also:
Option.process(WriteableCommandLine, ListIterator)

getTriggers

public Set getTriggers()
Identifies the argument prefixes that should trigger this option. This is used to decide which of many Options should be tried when processing a given argument string. The returned Set must not be null.

Returns:
The set of triggers for this Option

getPrefixes

public Set getPrefixes()
Identifies the argument prefixes that should be considered options. This is used to identify whether a given string looks like an option or an argument value. Typically an option would return the set [--,-] while switches might offer [-,+]. The returned Set must not be null.

Specified by:
getPrefixes in interface Option
Overrides:
getPrefixes in class ParentImpl
Returns:
The set of prefixes for this Option

validate

public void validate(WriteableCommandLine commandLine)
              throws OptionException
Checks that the supplied CommandLine is valid with respect to this option.

Specified by:
validate in interface Option
Overrides:
validate in class ParentImpl
Parameters:
commandLine - the CommandLine to check.
Throws:
OptionException - if the CommandLine is not valid.

appendUsage

public void appendUsage(StringBuffer buffer,
                        Set helpSettings,
                        Comparator comp)
Appends usage information to the specified StringBuffer

Specified by:
appendUsage in interface Option
Overrides:
appendUsage in class ParentImpl
Parameters:
buffer - the buffer to append to
helpSettings - a set of display settings @see DisplaySetting
comp - a comparator used to sort the Options

getPreferredName

public String getPreferredName()
The preferred name of an option is used for generating help and usage information.

Returns:
The preferred name of the option

defaults

public void defaults(WriteableCommandLine commandLine)
Adds defaults to a CommandLine. Any defaults for this option are applied as well as the defaults for any contained options

Specified by:
defaults in interface Option
Overrides:
defaults in class ParentImpl
Parameters:
commandLine - the CommandLine object to store defaults in