Top Description Inners Fields Constructors Methods
org.kohsuke.args4j

public Class OptionHandlerRegistry

extends Object
Class Inheritance
Imports
java.io.File, java.lang.reflect.Constructor, .InvocationTargetException, java.net.InetAddress, .URI, .URL, java.util.Collections, .HashMap, .Map, java.util.regex.Pattern, org.kohsuke.args4j.spi.BooleanOptionHandler, .ByteOptionHandler, .CharOptionHandler, .DoubleOptionHandler, .EnumOptionHandler, .FileOptionHandler, .FloatOptionHandler, .InetAddressOptionHandler, .IntOptionHandler, .LongOptionHandler, .MapOptionHandler, .OptionHandler, .PathOptionHandler, .PatternOptionHandler, .Setter, .ShortOptionHandler, .StringOptionHandler, .URIOptionHandler, .URLOptionHandler

Manages the registration of option handlers. This is good for registering custom handlers for specific parameter classes not yet implemented. The registry is a singleton that can be retrieved with the getRegistry() call.
Author
Stephan Fuhrmann

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
public static interface
OptionHandlerRegistry.OptionHandlerFactory

Provide custom logic for creating OptionHandler implementation.

Field Summary

Modifier and TypeField and Description
private final Map<Class<T>, OptionHandlerRegistry.OptionHandlerFactory>
private static OptionHandlerRegistry
instance

The shared reference.

Constructor Summary

AccessConstructor and Description
private
OptionHandlerRegistry()

Constructs an option handler manager with the default handlers initialized.

Method Summary

Modifier and TypeMethod and Description
protected OptionHandler<T>
createOptionHandler(CmdLineParser parser, OptionDef o, Setter<T> setter)

Creates an OptionHandler that handles the given Option annotation and the Setter instance.

private static Constructor<? extends OptionHandler<T>>
getConstructor(Class<? extends OptionHandler<T>> handlerClass)

Finds the constructor for an option handler.

public static synchronized OptionHandlerRegistry

Returns:

a shared instance of the registry.
getRegistry
()

Gets the option handler registry singleton instance.

private void
initHandlers()

Registers the default handlers.

public void
registerHandler(Class<T>
The specified handler is used when the field/method annotated by Option is of this type.
valueType
,
Class<? extends OptionHandler<T>>
This class must have the constructor that has the same signature as OptionHandler#OptionHandler(CmdLineParser, OptionDef, Setter)
handlerClass
)

Registers a user-defined OptionHandler class with args4j.

public void
registerHandler(Class<T>
The specified handler is used when the field/method annotated by Option is of this type.
valueType
,
OptionHandlerRegistry.OptionHandlerFactory
Factory to instantiate handler upon request.
factory
)

Registers a user-defined OptionHandler class with args4j.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

handlersback to summary
private final Map<Class<T>, OptionHandlerRegistry.OptionHandlerFactory> handlers

All OptionHandlers known to the CmdLineParser. Constructors of OptionHandler-derived class keyed by their supported types.

instanceback to summary
private static OptionHandlerRegistry instance

The shared reference.

See Also
getRegistry()

Constructor Detail

OptionHandlerRegistryback to summary
private OptionHandlerRegistry()

Constructs an option handler manager with the default handlers initialized.

Method Detail

createOptionHandlerback to summary
protected OptionHandler<T> createOptionHandler(CmdLineParser parser, OptionDef o, Setter<T> setter)

Creates an OptionHandler that handles the given Option annotation and the Setter instance.

Annotations
@SuppressWarnings:unchecked
getConstructorback to summary
private static Constructor<? extends OptionHandler<T>> getConstructor(Class<? extends OptionHandler<T>> handlerClass)

Finds the constructor for an option handler.

getRegistryback to summary
public static synchronized OptionHandlerRegistry getRegistry()

Gets the option handler registry singleton instance.

Returns:OptionHandlerRegistry

a shared instance of the registry.

initHandlersback to summary
private void initHandlers()

Registers the default handlers.

registerHandlerback to summary
public void registerHandler(Class<T> valueType, Class<? extends OptionHandler<T>> handlerClass)

Registers a user-defined OptionHandler class with args4j.

This method allows users to extend the behavior of args4j by writing their own OptionHandler implementation.

Parameters
valueType:Class<T>

The specified handler is used when the field/method annotated by Option is of this type.

handlerClass:Class<? extends OptionHandler<T>>

This class must have the constructor that has the same signature as OptionHandler#OptionHandler(CmdLineParser, OptionDef, Setter)

Exceptions
NullPointerException:
if valueType or handlerClass is null.
IllegalArgumentException:
if handlerClass is not a subtype of OptionHandler.
registerHandlerback to summary
public void registerHandler(Class<T> valueType, OptionHandlerRegistry.OptionHandlerFactory factory)

Registers a user-defined OptionHandler class with args4j.

This method allows users to extend the behavior of args4j by writing their own OptionHandler implementation.

Parameters
valueType:Class<T>

The specified handler is used when the field/method annotated by Option is of this type.

factory:OptionHandlerRegistry.OptionHandlerFactory

Factory to instantiate handler upon request.

Exceptions
NullPointerException:
if valueType or factory is null.
org.kohsuke.args4j back to summary

private Class OptionHandlerRegistry.DefaultConstructorHandlerFactory

extends Object
implements OptionHandlerFactory
Class Inheritance
  • java.lang.Object
  • org.kohsuke.args4j.OptionHandlerRegistry.DefaultConstructorHandlerFactory
All Implemented Interfaces
org.kohsuke.args4j.OptionHandlerRegistry.OptionHandlerFactory

Field Summary

Modifier and TypeField and Description
private final Constructor<? extends OptionHandler<T>>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public OptionHandler<?>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

consback to summary
private final Constructor<? extends OptionHandler<T>> cons

Constructor Detail

DefaultConstructorHandlerFactoryback to summary
public DefaultConstructorHandlerFactory(Class<T> type)

Method Detail

getHandlerback to summary
public OptionHandler<?> getHandler(CmdLineParser parser, OptionDef o, Setter<T> setter)

Implements org.kohsuke.args4j.OptionHandlerRegistry.OptionHandlerFactory.getHandler.

Doc from org.kohsuke.args4j.OptionHandlerRegistry.OptionHandlerFactory.getHandler.

Provide a handler instance to use.

org.kohsuke.args4j back to summary

public Interface OptionHandlerRegistry.OptionHandlerFactory

Known Direct Implementers
org.kohsuke.args4j.OptionHandlerRegistry.DefaultConstructorHandlerFactory

Provide custom logic for creating OptionHandler implementation.
Author
ogondza

Method Summary

Modifier and TypeMethod and Description
public OptionHandler<?>
getHandler(CmdLineParser parser, OptionDef o, Setter<T> setter)

Provide a handler instance to use.

Method Detail

getHandlerback to summary
public OptionHandler<?> getHandler(CmdLineParser parser, OptionDef o, Setter<T> setter)

Provide a handler instance to use.