org.apache.commons.cli2.commandline
Class WriteableCommandLineImpl

java.lang.Object
  extended by org.apache.commons.cli2.commandline.CommandLineImpl
      extended by org.apache.commons.cli2.commandline.WriteableCommandLineImpl
All Implemented Interfaces:
CommandLine, WriteableCommandLine

public class WriteableCommandLineImpl
extends CommandLineImpl
implements WriteableCommandLine

A WriteableCommandLine implementation allowing Options to write their processed information to a CommandLine.


Constructor Summary
WriteableCommandLineImpl(Option rootOption, List arguments)
          Creates a new WriteableCommandLineImpl rooted on the specified Option, to hold the parsed arguments.
 
Method Summary
 void addOption(Option option)
          Adds an Option to the CommandLine
 void addProperty(Option option, String property, String value)
          Adds a property value to a name in the CommandLine.
 void addProperty(String property, String value)
          Adds a property value to the default property set.
 void addSwitch(Option option, boolean value)
          Adds a switch value to an Option in the CommandLine.
 void addValue(Option option, Object value)
          Adds a value to an Option in the CommandLine.
 Option getCurrentOption()
          Returns the option that is currently processed.
 List getNormalised()
           
 Option getOption(String trigger)
          Finds the Option with the specified trigger
 List getOptions()
          Retrieves a list of all Options found in this CommandLine
 Set getOptionTriggers()
          Retrieves a list of all Option triggers found in this CommandLine
 Set getProperties()
          Retrieves the set of all property names associated with the default property option
 Set getProperties(Option option)
          Retrieves the set of all property names associated with this option
 String getProperty(Option option, String property, String defaultValue)
          Retrieves the value associated with the specified property
 String getProperty(String property)
          Retrieves the value associated with the specified property for the default property set
 Boolean getSwitch(Option option, Boolean defaultValue)
          Retrieves the Boolean value associated with the specified Switch
 List getUndefaultedValues(Option option)
          Retrieves the Argument values specified on the command line for the specified Option, this doesn't return any values supplied programmatically as defaults.
 List getValues(Option option, List defaultValues)
          Retrieves the Argument values associated with the specified Option
 boolean hasOption(Option option)
          Detects the presence of an option in this CommandLine.
 boolean looksLikeOption(String trigger)
          Tests whether the passed in trigger looks like an option.
 void setCurrentOption(Option currentOption)
          Sets the current option.
 void setDefaultSwitch(Option option, Boolean defaultSwitch)
          Sets the default state for a Switch in the CommandLine.
 void setDefaultValues(Option option, List defaults)
          Sets the default values for an Option in the CommandLine
 String toString()
           
 
Methods inherited from class org.apache.commons.cli2.commandline.CommandLineImpl
getOptionCount, getOptionCount, getProperty, getSwitch, getSwitch, getSwitch, getValue, getValue, getValue, getValue, getValues, getValues, getValues, hasOption
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.cli2.CommandLine
getOptionCount, getOptionCount, getProperty, getSwitch, getSwitch, getSwitch, getValue, getValue, getValue, getValue, getValues, getValues, getValues, hasOption
 

Constructor Detail

WriteableCommandLineImpl

public WriteableCommandLineImpl(Option rootOption,
                                List arguments)
Creates a new WriteableCommandLineImpl rooted on the specified Option, to hold the parsed arguments.

Parameters:
rootOption - the CommandLine's root Option
arguments - the arguments this CommandLine represents
Method Detail

getCurrentOption

public Option getCurrentOption()
Description copied from interface: WriteableCommandLine
Returns the option that is currently processed.

Specified by:
getCurrentOption in interface WriteableCommandLine
Returns:
the current option

setCurrentOption

public void setCurrentOption(Option currentOption)
Description copied from interface: WriteableCommandLine
Sets the current option. This method is called by concrete option implementations during command line processing. It enables the command line to keep track about the option that is currently processed.

Specified by:
setCurrentOption in interface WriteableCommandLine
Parameters:
currentOption - the new current option

addOption

public void addOption(Option option)
Description copied from interface: WriteableCommandLine
Adds an Option to the CommandLine

Specified by:
addOption in interface WriteableCommandLine
Parameters:
option - the Option to add

addValue

public void addValue(Option option,
                     Object value)
Description copied from interface: WriteableCommandLine
Adds a value to an Option in the CommandLine.

Specified by:
addValue in interface WriteableCommandLine
Parameters:
option - the Option to add to
value - the value to add

addSwitch

public void addSwitch(Option option,
                      boolean value)
Description copied from interface: WriteableCommandLine
Adds a switch value to an Option in the CommandLine.

Specified by:
addSwitch in interface WriteableCommandLine
Parameters:
option - the Option to add to
value - the switch value to add

hasOption

public boolean hasOption(Option option)
Description copied from interface: CommandLine
Detects the presence of an option in this CommandLine.

Specified by:
hasOption in interface CommandLine
Parameters:
option - the Option to search for
Returns:
true iff the option is present

getOption

public Option getOption(String trigger)
Description copied from interface: CommandLine
Finds the Option with the specified trigger

Specified by:
getOption in interface CommandLine
Parameters:
trigger - the name of the option to retrieve
Returns:
the Option matching the trigger or null if none exists

getValues

public List getValues(Option option,
                      List defaultValues)
Description copied from interface: CommandLine
Retrieves the Argument values associated with the specified Option

Specified by:
getValues in interface CommandLine
Parameters:
option - the Option associated with the values
defaultValues - the result to return if no values are found
Returns:
a list of values or defaultValues if none are found

getUndefaultedValues

public List getUndefaultedValues(Option option)
Description copied from interface: WriteableCommandLine
Retrieves the Argument values specified on the command line for the specified Option, this doesn't return any values supplied programmatically as defaults.

Specified by:
getUndefaultedValues in interface WriteableCommandLine
Parameters:
option - the Option associated with the values
Returns:
a list of values or an empty List if none are found

getSwitch

public Boolean getSwitch(Option option,
                         Boolean defaultValue)
Description copied from interface: CommandLine
Retrieves the Boolean value associated with the specified Switch

Specified by:
getSwitch in interface CommandLine
Parameters:
option - the Option associated with the value
defaultValue - the Boolean to use if none match
Returns:
the Boolean associated with option or defaultValue if none exists

getProperty

public String getProperty(String property)
Description copied from interface: CommandLine
Retrieves the value associated with the specified property for the default property set

Specified by:
getProperty in interface CommandLine
Parameters:
property - the property name to lookup
Returns:
the value of the property or null

addProperty

public void addProperty(Option option,
                        String property,
                        String value)
Description copied from interface: WriteableCommandLine
Adds a property value to a name in the CommandLine. Replaces any existing value for the property.

Specified by:
addProperty in interface WriteableCommandLine
Parameters:
option - the Option to add to
property - the name of the property
value - the value of the property

addProperty

public void addProperty(String property,
                        String value)
Description copied from interface: WriteableCommandLine
Adds a property value to the default property set. Replaces any existing value for the property.

Specified by:
addProperty in interface WriteableCommandLine
Parameters:
property - the name of the property
value - the value of the property

getProperty

public String getProperty(Option option,
                          String property,
                          String defaultValue)
Description copied from interface: CommandLine
Retrieves the value associated with the specified property

Specified by:
getProperty in interface CommandLine
Parameters:
option - the option i.e., -D
property - the property name to lookup
defaultValue - the value to use if no other is found
Returns:
the value of the property or defaultValue

getProperties

public Set getProperties(Option option)
Description copied from interface: CommandLine
Retrieves the set of all property names associated with this option

Specified by:
getProperties in interface CommandLine
Parameters:
option - the option i.e., -D
Returns:
a none null set of property names

getProperties

public Set getProperties()
Description copied from interface: CommandLine
Retrieves the set of all property names associated with the default property option

Specified by:
getProperties in interface CommandLine
Returns:
a none null set of property names

looksLikeOption

public boolean looksLikeOption(String trigger)
Tests whether the passed in trigger looks like an option. This implementation first checks whether the passed in string starts with a prefix that indicates an option. If this is the case, it is also checked whether an option of this name is known for the current option. (This can lead to reentrant invocations of this method, so care has to be taken about this.)

Specified by:
looksLikeOption in interface WriteableCommandLine
Parameters:
trigger - the command line element to test
Returns:
a flag whether this element seems to be an option

toString

public String toString()
Overrides:
toString in class Object

getOptions

public List getOptions()
Description copied from interface: CommandLine
Retrieves a list of all Options found in this CommandLine

Specified by:
getOptions in interface CommandLine
Returns:
a none null list of Options

getOptionTriggers

public Set getOptionTriggers()
Description copied from interface: CommandLine
Retrieves a list of all Option triggers found in this CommandLine

Specified by:
getOptionTriggers in interface CommandLine
Returns:
a none null list of Option triggers

setDefaultValues

public void setDefaultValues(Option option,
                             List defaults)
Description copied from interface: WriteableCommandLine
Sets the default values for an Option in the CommandLine

Specified by:
setDefaultValues in interface WriteableCommandLine
Parameters:
option - the Option to add to
defaults - the defaults for the option

setDefaultSwitch

public void setDefaultSwitch(Option option,
                             Boolean defaultSwitch)
Description copied from interface: WriteableCommandLine
Sets the default state for a Switch in the CommandLine.

Specified by:
setDefaultSwitch in interface WriteableCommandLine
Parameters:
option - the Option to add to
defaultSwitch - the defaults state for ths switch

getNormalised

public List getNormalised()


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