net.dpml.cli.commandline

Class PropertiesCommandLine

Implemented Interfaces:
CommandLine

public class PropertiesCommandLine
extends CommandLineImpl

A CommandLine implementation using a java Properties instance, useful for constructing a complex DefaultingCommandLine Options are keyed from their property name and presence in the Properties instance is taken as presence in the CommandLine. Argument values are taken from the property value and are optionally separated using the separator char, defined at construction time. Switch values can be specified using a simple value of true or false; obviously this means that Switches with Arguments are not supported by this implementation.
Version:
@PROJECT-VERSION@
Author:
@PUBLISHER-NAME@
See Also:
java.util.Properties, DefaultingCommandLine, Option.getPreferredName()

Constructor Summary

PropertiesCommandLine(Option root, Properties properties)
Creates a new PropertiesCommandLine using the specified root Option, Properties instance.
PropertiesCommandLine(Option root, Properties properties, char separator)
Creates a new PropertiesCommandLine using the specified root Option, Properties instance and value separator.

Method Summary

Option
getOption(String trigger)
Finds the Option with the specified trigger
Set
getOptionTriggers()
Retrieves a list of all Option triggers found in this CommandLine
List
getOptions()
Retrieves a list of all Options found in this CommandLine
Set
getProperties()
Retrieves the set of all property names associated with this CommandLine
String
getProperty(String property, String defaultValue)
Retrieves the value associated with the specified property
Boolean
getSwitch(Option option, Boolean defaultValue)
Retrieves the Boolean value associated with the specified Switch
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.

Methods inherited from class net.dpml.cli.commandline.CommandLineImpl

getOptionCount, getOptionCount, getProperty, getSwitch, getSwitch, getSwitch, getValue, getValue, getValue, getValue, getValues, getValues, getValues, hasOption

Constructor Details

PropertiesCommandLine

public PropertiesCommandLine(Option root,
                             Properties properties)
Creates a new PropertiesCommandLine using the specified root Option, Properties instance. The character 0 is used as the value separator.
Parameters:
root - the CommandLine's root Option
properties - the Properties instance to get values from

PropertiesCommandLine

public PropertiesCommandLine(Option root,
                             Properties properties,
                             char separator)
Creates a new PropertiesCommandLine using the specified root Option, Properties instance and value separator.
Parameters:
root - the CommandLine's root Option
properties - the Properties instance to get values from
separator - the character to split argument values

Method Details

getOption

public Option getOption(String trigger)
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

getOptionTriggers

public Set getOptionTriggers()
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

getOptions

public List getOptions()
Retrieves a list of all Options found in this CommandLine
Specified by:
getOptions in interface CommandLine
Returns:
a none null list of Options

getProperties

public Set getProperties()
Retrieves the set of all property names associated with this CommandLine
Specified by:
getProperties in interface CommandLine
Returns:
a none null set of property names

getProperty

public String getProperty(String property,
                          String defaultValue)
Retrieves the value associated with the specified property
Specified by:
getProperty in interface CommandLine
Parameters:
property - the property name to lookup
defaultValue - the value to use if no other is found
Returns:
the value of the property or defaultValue

getSwitch

public Boolean getSwitch(Option option,
                         Boolean defaultValue)
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

getValues

public List getValues(Option option,
                      List defaultValues)
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

hasOption

public boolean hasOption(Option option)
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