org.apache.commons.cli2.option
Class DefaultOption

java.lang.Object
  extended by org.apache.commons.cli2.option.OptionImpl
      extended by org.apache.commons.cli2.option.ParentImpl
          extended by org.apache.commons.cli2.option.DefaultOption
All Implemented Interfaces:
Option, Parent

public class DefaultOption
extends ParentImpl

A Parent implementation representing normal options.


Field Summary
static boolean DEFAULT_BURST_ENABLED
          The default value for the burstEnabled constructor parameter
static String DEFAULT_LONG_PREFIX
          The default token used to prefix a long option
static String DEFAULT_SHORT_PREFIX
          The default token used to prefix a short option
 
Constructor Summary
DefaultOption(String shortPrefix, String longPrefix, boolean burstEnabled, String preferredName, String description, Set aliases, Set burstAliases, boolean required, Argument argument, Group children, int id)
          Creates a new DefaultOption
 
Method Summary
 void appendUsage(StringBuffer buffer, Set helpSettings, Comparator comp)
          Appends usage information to the specified StringBuffer
 boolean canProcess(WriteableCommandLine commandLine, String argument)
          Indicates whether this Option will be able to process the particular argument.
 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 org.apache.commons.cli2.option.ParentImpl
defaults, findOption, getArgument, getChildren, getDescription, helpLines, process
 
Methods inherited from class org.apache.commons.cli2.option.OptionImpl
canProcess, checkPrefixes, equals, getId, getParent, hashCode, isRequired, setParent, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.cli2.Option
canProcess, getId, getParent, isRequired, setParent
 

Field Detail

DEFAULT_SHORT_PREFIX

public static final String DEFAULT_SHORT_PREFIX
The default token used to prefix a short option

See Also:
Constant Field Values

DEFAULT_LONG_PREFIX

public static final String DEFAULT_LONG_PREFIX
The default token used to prefix a long option

See Also:
Constant Field Values

DEFAULT_BURST_ENABLED

public static final boolean DEFAULT_BURST_ENABLED
The default value for the burstEnabled constructor parameter

See Also:
Constant Field Values
Constructor Detail

DefaultOption

public DefaultOption(String shortPrefix,
                     String longPrefix,
                     boolean burstEnabled,
                     String preferredName,
                     String description,
                     Set aliases,
                     Set burstAliases,
                     boolean required,
                     Argument argument,
                     Group children,
                     int id)
Creates a new DefaultOption

Parameters:
shortPrefix - the prefix used for short options
longPrefix - the prefix used for long options
burstEnabled - should option bursting be enabled
preferredName - the preferred name for this Option, this should begin with either shortPrefix or longPrefix
description - a description of this Option
aliases - the alternative names for this Option
burstAliases - the aliases that can be burst
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
Throws:
IllegalArgumentException - if the preferredName or an alias isn't prefixed with shortPrefix or longPrefix
Method Detail

canProcess

public boolean canProcess(WriteableCommandLine commandLine,
                          String argument)
Description copied from interface: Option
Indicates whether this Option will be able to process the particular argument.

Specified by:
canProcess in interface Option
Overrides:
canProcess in class ParentImpl
Parameters:
commandLine - The CommandLine to check
argument - The argument to be tested
Returns:
true if the argument can be processed by this Option

processParent

public void processParent(WriteableCommandLine commandLine,
                          ListIterator arguments)
                   throws OptionException
Description copied from interface: Parent
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()
Description copied from interface: Option
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()
Description copied from interface: Option
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
Description copied from interface: Option
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)
Description copied from interface: Option
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()
Description copied from interface: Option
The preferred name of an option is used for generating help and usage information.

Returns:
The preferred name of the option


Copyright © 2002-2010 Apache Software Foundation. All Rights Reserved.