Package org.kohsuke.args4j.spi

## Class OptionHandler<T>

- java.lang.Object
- - org.kohsuke.args4j.spi.OptionHandler<T>

Type Parameters:
  `T` - The `component` type of the field that this `OptionHandler` works with. When I say "component", I mean a field that can hold multiple values (such as `Collection` or array). This should refer to its component time. `Setter` implementations abstract away multi-value-ness by allowing `OptionHandler` to invoke its `Setter.addValue(Object)` multiple times.

Direct Known Subclasses:
  `BooleanOptionHandler`, `DelimitedOptionHandler`, `EnumOptionHandler`, `ExplicitBooleanOptionHandler`, `MacAddressOptionHandler`, `MapOptionHandler`, `OneArgumentOptionHandler`, `PatternOptionHandler`, `RestOfArgumentsHandler`, `StopOptionHandler`, `StringArrayOptionHandler`, `StringOptionHandler`, `SubCommandHandler`, `URIOptionHandler`, `URLOptionHandler`

    public abstract class OptionHandler<T>
    extends java.lang.Object

Code that parses operands of an option into Java.

This class can be extended by application to support additional Java datatypes in option operands.

Implementation of this class needs to be registered to args4j by using `OptionHandlerRegistry.registerHandler(Class,Class)`. For registration to work, subclasses will need to implement the constructor with the signature `OptionHandler(CmdLineParser, OptionDef, Setter)`.

Author:
  Kohsuke Kawaguchi

### Field Summary

Fields
`OptionDef` `option` The annotation.
`CmdLineParser` `owner` The owner to which this handler belongs to.
`Setter<? super T>` `setter` Object to be used for setting value.

### Constructor Summary

Constructors
`protected` `OptionHandler​(CmdLineParser parser, OptionDef option, Setter<? super T> setter)`

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`abstract java.lang.String` `getDefaultMetaVariable()` Gets the default meta variable name used to print the usage screen.
`java.lang.String` `getMetaVariable​(java.util.ResourceBundle rb)`
`java.lang.String` `getNameAndMeta​(java.util.ResourceBundle rb)` Get string representing usage for this option, of the form "name metaval", e.g.
`java.lang.String` `getNameAndMeta​(java.util.ResourceBundle rb, ParserProperties properties)` Get string representing usage for this option, of the form "name metaval" or "name=metaval, e.g.
`abstract int` `parseArguments​(Parameters params)` Called if the option that this owner recognizes is found.
`protected java.lang.String` `print​(T v)` The opposite of the parse operation.
`java.lang.String` `printDefaultValue()` Prints the default value by introspecting the current setter as `Getter`.

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### option

    public final OptionDef option

The annotation.

#### setter

    public final Setter<? super T> setter

Object to be used for setting value.

#### owner

    public final CmdLineParser owner

The owner to which this handler belongs to.

### Constructor Detail

#### OptionHandler

    protected OptionHandler​(CmdLineParser parser,
                            OptionDef option,
                            Setter<? super T> setter)

### Method Detail

#### parseArguments

    public abstract int parseArguments​(Parameters params)
                                throws CmdLineException

Called if the option that this owner recognizes is found.

Parameters:
  `params` - The rest of the arguments. This method can use this object to access the arguments of the option if necessary. The object is valid only during the method call.
Returns:
  The number of arguments consumed. (For example, returns `0` if this option doesn't take any parameters.)
Throws:
  `CmdLineException`

#### getDefaultMetaVariable

    public abstract java.lang.String getDefaultMetaVariable()

Gets the default meta variable name used to print the usage screen. The value returned by this method can be a reference in the `ResourceBundle`, if one was passed to `CmdLineParser`.

Returns:
  `null` to hide a meta variable.

#### getMetaVariable

    public java.lang.String getMetaVariable​(java.util.ResourceBundle rb)

#### getNameAndMeta

    public final java.lang.String getNameAndMeta​(java.util.ResourceBundle rb)

Get string representing usage for this option, of the form "name metaval", e.g. "-foo VALUE" or "--foo VALUE"

Parameters:
  `rb` - ResourceBundle to get localized version of meta string

#### getNameAndMeta

    public final java.lang.String getNameAndMeta​(java.util.ResourceBundle rb,
                                                 ParserProperties properties)

Get string representing usage for this option, of the form "name metaval" or "name=metaval, e.g. "--foo VALUE" or "--foo=VALUE"

Parameters:
  `rb` - ResourceBundle to get localized version of meta string
  `properties` - Affects the formatting behaviours.

#### print

    protected java.lang.String print​(T v)

The opposite of the parse operation. This method is used to print the usage screen.

#### printDefaultValue

    public java.lang.String printDefaultValue()

Prints the default value by introspecting the current setter as `Getter`.

Returns:
  null if the current value of the setter isn't available.