Top Description Fields Constructors Methods
org.kohsuke.args4j.spi

public abstract Class OptionHandler<T>

extends Object
Class Inheritance
Known Direct Subclasses
org.kohsuke.args4j.spi.PatternOptionHandler, org.kohsuke.args4j.spi.RestOfArgumentsHandler, org.kohsuke.args4j.spi.StopOptionHandler, org.kohsuke.args4j.spi.StringArrayOptionHandler, org.kohsuke.args4j.spi.StringOptionHandler, org.kohsuke.args4j.spi.SubCommandHandler, org.kohsuke.args4j.spi.URIOptionHandler, org.kohsuke.args4j.spi.URLOptionHandler, org.kohsuke.args4j.spi.BooleanOptionHandler, org.kohsuke.args4j.spi.DelimitedOptionHandler, org.kohsuke.args4j.spi.EnumOptionHandler, org.kohsuke.args4j.spi.ExplicitBooleanOptionHandler, org.kohsuke.args4j.spi.MacAddressOptionHandler, org.kohsuke.args4j.spi.MapOptionHandler, org.kohsuke.args4j.spi.OneArgumentOptionHandler
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.
Imports
org.kohsuke.args4j.*, java.util.Collection, .List, .ResourceBundle

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#OptionHandler(CmdLineParser, OptionDef, Setter).

Author
Kohsuke Kawaguchi

Field Summary

Modifier and TypeField and Description
public final OptionDef
option

The annotation.

public final CmdLineParser
owner

The owner to which this handler belongs to.

public final Setter<? super T>
setter

Object to be used for setting value.

Constructor Summary

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

Method Summary

Modifier and TypeMethod and Description
public abstract String

Returns:

null to hide a meta variable.
getDefaultMetaVariable
()

Gets the default meta variable name used to print the usage screen.

public String
public final String
getNameAndMeta(ResourceBundle
ResourceBundle to get localized version of meta string
rb
)

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

public final String
getNameAndMeta(ResourceBundle
ResourceBundle to get localized version of meta string
rb
,
ParserProperties
Affects the formatting behaviours.
properties
)

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

public abstract int

Returns:

The number of arguments consumed. (For example, returns 0 if this option doesn't take any parameters.)
parseArguments
(Parameters
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.
params
)

Called if the option that this owner recognizes is found.

public String

Returns:

null if the current value of the setter isn't available.
printDefaultValue
()

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

optionback to summary
public final OptionDef option

The annotation.

ownerback to summary
public final CmdLineParser owner

The owner to which this handler belongs to.

setterback to summary
public final Setter<? super T> setter

Object to be used for setting value.

Constructor Detail

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

Method Detail

getDefaultMetaVariableback to summary
public abstract 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:String

null to hide a meta variable.

getMetaVariableback to summary
public String getMetaVariable(ResourceBundle rb)
getNameAndMetaback to summary
public final String getNameAndMeta(ResourceBundle rb)

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

Parameters
rb:ResourceBundle

ResourceBundle to get localized version of meta string

getNameAndMetaback to summary
public final String getNameAndMeta(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

ResourceBundle to get localized version of meta string

properties:ParserProperties

Affects the formatting behaviours.

parseArgumentsback to summary
public abstract int parseArguments(Parameters params) throws CmdLineException

Called if the option that this owner recognizes is found.

Parameters
params:Parameters

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:int

The number of arguments consumed. (For example, returns 0 if this option doesn't take any parameters.)

printDefaultValueback to summary
public String printDefaultValue()

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

Returns:String

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