Top Description Fields Constructors Methods
org.springframework.core.env

public Class JOptCommandLinePropertySource

extends CommandLinePropertySource<OptionSet>
Class Inheritance
Annotations
@Deprecated
since:6.1
Imports
java.util.ArrayList, .Collections, .List, joptsimple.OptionSet, .OptionSpec, org.springframework.lang.Nullable, org.springframework.util.CollectionUtils, .StringUtils

Deprecated

since 6.1.

since 6.1 with no plans for a replacement

CommandLinePropertySource implementation backed by a JOpt OptionSet.

Typical usage

Configure and execute an OptionParser against the String[] of arguments supplied to the main method, and create a JOptCommandLinePropertySource using the resulting OptionSet object:
public static void main(String[] args) {
    OptionParser parser = new OptionParser();
    parser.accepts("option1");
    parser.accepts("option2").withRequiredArg();
    OptionSet options = parser.parse(args);
    PropertySource<?> ps = new JOptCommandLinePropertySource(options);
    // ...
}

If an option has several representations, the most descriptive is expected to be set last, and is used as the property name of the associated EnumerablePropertySource#getPropertyNames().

See CommandLinePropertySource for complete general usage examples.

Requires JOpt Simple version 4.3 or higher. Tested against JOpt up until 5.0.

Authors
Chris Beams, Juergen Hoeller, Dave Syer
Since
3.1
See Also
CommandLinePropertySource, joptsimple.OptionParser, joptsimple.OptionSet

Field Summary

Inherited from org.springframework.core.env.CommandLinePropertySource:
COMMAND_LINE_PROPERTY_SOURCE_NAMEDEFAULT_NON_OPTION_ARGS_PROPERTY_NAME

Constructor Summary

AccessConstructor and Description
public
JOptCommandLinePropertySource(OptionSet options)

Create a new JOptCommandLinePropertySource having the default name and backed by the given OptionSet.

public
JOptCommandLinePropertySource(String name, OptionSet options)

Create a new JOptCommandLinePropertySource having the given name and backed by the given OptionSet.

Method Summary

Modifier and TypeMethod and Description
protected boolean
containsOption(String name)

Implements abstract org.springframework.core.env.CommandLinePropertySource.containsOption.

Return whether the set of option arguments parsed from the command line contains an option with the given name.
protected List<String>
getNonOptionArgs()

Implements abstract org.springframework.core.env.CommandLinePropertySource.getNonOptionArgs.

Return the collection of non-option arguments parsed from the command line.
public List<String>
getOptionValues(String name)

Implements abstract org.springframework.core.env.CommandLinePropertySource.getOptionValues.

Return the collection of values associated with the command line option having the given name.
public String[]
getPropertyNames()

Implements abstract org.springframework.core.env.EnumerablePropertySource.getPropertyNames.

Return the names of all properties contained by the source object (never null).
Inherited from org.springframework.core.env.CommandLinePropertySource:
containsPropertygetPropertysetNonOptionArgsPropertyName

Constructor Detail

JOptCommandLinePropertySourceback to summary
public JOptCommandLinePropertySource(OptionSet options)

Create a new JOptCommandLinePropertySource having the default name and backed by the given OptionSet.

See Also
CommandLinePropertySource#COMMAND_LINE_PROPERTY_SOURCE_NAME, CommandLinePropertySource#CommandLinePropertySource(Object)
JOptCommandLinePropertySourceback to summary
public JOptCommandLinePropertySource(String name, OptionSet options)

Create a new JOptCommandLinePropertySource having the given name and backed by the given OptionSet.

Method Detail

containsOptionback to summary
protected boolean containsOption(String name)

Implements abstract org.springframework.core.env.CommandLinePropertySource.containsOption.

Doc from org.springframework.core.env.CommandLinePropertySource.containsOption.

Return whether the set of option arguments parsed from the command line contains an option with the given name.

Annotations
@Override
getNonOptionArgsback to summary
protected List<String> getNonOptionArgs()

Implements abstract org.springframework.core.env.CommandLinePropertySource.getNonOptionArgs.

Doc from org.springframework.core.env.CommandLinePropertySource.getNonOptionArgs.

Return the collection of non-option arguments parsed from the command line. Never null.

Annotations
@Override
getOptionValuesback to summary
public List<String> getOptionValues(String name)

Implements abstract org.springframework.core.env.CommandLinePropertySource.getOptionValues.

Doc from org.springframework.core.env.CommandLinePropertySource.getOptionValues.

Return the collection of values associated with the command line option having the given name.

  • if the option is present and has no argument (e.g.: "--foo"), return an empty collection ([])
  • if the option is present and has a single value (e.g. "--foo=bar"), return a collection having one element (["bar"])
  • if the option is present and the underlying command line parsing library supports multiple arguments (e.g. "--foo=bar --foo=baz"), return a collection having elements for each value (["bar", "baz"])
  • if the option is not present, return null
Annotations
@Override
@Nullable
getPropertyNamesback to summary
public String[] getPropertyNames()

Implements abstract org.springframework.core.env.EnumerablePropertySource.getPropertyNames.

Doc from org.springframework.core.env.EnumerablePropertySource.getPropertyNames.

Return the names of all properties contained by the source object (never null).

Annotations
@Override