Package org.springframework.core.env

# Class JOptCommandLinePropertySource

java.lang.Object
org.springframework.core.env.PropertySource<T>
org.springframework.core.env.EnumerablePropertySource<T>
org.springframework.core.env.CommandLinePropertySource<joptsimple.OptionSet>
org.springframework.core.env.JOptCommandLinePropertySource

@Deprecated(since="6.1") public class JOptCommandLinePropertySource extends CommandLinePropertySource<joptsimple.OptionSet>
Deprecated.
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.

Since:
  3.1
Author:
  Chris Beams, Juergen Hoeller, Dave Syer
See Also:
  - `CommandLinePropertySource`
  - `OptionParser`
  - `OptionSet`

## Nested Class Summary

## Nested classes/interfaces inherited from class org.springframework.core.env.PropertySource

`PropertySource.StubPropertySource`

## Field Summary

### Fields inherited from class org.springframework.core.env.CommandLinePropertySource

`COMMAND_LINE_PROPERTY_SOURCE_NAME, DEFAULT_NON_OPTION_ARGS_PROPERTY_NAME`

### Fields inherited from class org.springframework.core.env.PropertySource

`logger, name, source`

## Constructor Summary

Constructors
Constructor
Description
`JOptCommandLinePropertySource(String name, joptsimple.OptionSet options)`
Deprecated.
Create a new `JOptCommandLinePropertySource` having the given name and backed by the given `OptionSet`.
`JOptCommandLinePropertySource(joptsimple.OptionSet options)`
Deprecated.
Create a new `JOptCommandLinePropertySource` having the default name and backed by the given `OptionSet`.

## Method Summary

Modifier and Type
Method
Description
`protected boolean`
`containsOption(String name)`
Deprecated.
Return whether the set of option arguments parsed from the command line contains an option with the given name.
`protected List<String>`
`getNonOptionArgs()`
Deprecated.
Return the collection of non-option arguments parsed from the command line.
`List<String>`
`getOptionValues(String name)`
Deprecated.
Return the collection of values associated with the command line option having the given name.
`String[]`
`getPropertyNames()`
Deprecated.
Return the names of all properties contained by the source object (never `null`).

### Methods inherited from class org.springframework.core.env.CommandLinePropertySource

`containsProperty, getProperty, setNonOptionArgsPropertyName`

### Methods inherited from class org.springframework.core.env.PropertySource

`equals, getName, getSource, hashCode, named, toString`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Constructor Details

### JOptCommandLinePropertySource

public JOptCommandLinePropertySource(joptsimple.OptionSet options)
Deprecated.
Create a new `JOptCommandLinePropertySource` having the default name and backed by the given `OptionSet`.

See Also:
  - `CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME`
  - `CommandLinePropertySource(Object)`

### JOptCommandLinePropertySource

public JOptCommandLinePropertySource(String name, joptsimple.OptionSet options)
Deprecated.
Create a new `JOptCommandLinePropertySource` having the given name and backed by the given `OptionSet`.

## Method Details

### containsOption

protected boolean containsOption(String name)
Deprecated.
Description copied from class: `CommandLinePropertySource`
Return whether the set of option arguments parsed from the command line contains an option with the given name.

Specified by:
  `containsOption` in class `CommandLinePropertySource<joptsimple.OptionSet>`

### getPropertyNames

public String[] getPropertyNames()
Deprecated.
Description copied from class: `EnumerablePropertySource`
Return the names of all properties contained by the source object (never `null`).

Specified by:
  `getPropertyNames` in class `EnumerablePropertySource<joptsimple.OptionSet>`

### getOptionValues

@Nullable public List<String> getOptionValues(String name)
Deprecated.
Description copied from class: `CommandLinePropertySource`
Return the collection of values associated with the command line option having the given name.

- if the option is present and has no argument (for example: "--foo"), return an empty collection (`[]`)
- if the option is present and has a single value (for example, "--foo=bar"), return a collection having one element (`["bar"]`)
- if the option is present and the underlying command line parsing library supports multiple arguments (for example, "--foo=bar --foo=baz"), return a collection having elements for each value (`["bar", "baz"]`)
- if the option is not present, return `null`

Specified by:
  `getOptionValues` in class `CommandLinePropertySource<joptsimple.OptionSet>`

### getNonOptionArgs

protected List<String> getNonOptionArgs()
Deprecated.
Description copied from class: `CommandLinePropertySource`
Return the collection of non-option arguments parsed from the command line. Never `null`.

Specified by:
  `getNonOptionArgs` in class `CommandLinePropertySource<joptsimple.OptionSet>`