Package org.kohsuke.args4j
Class OptionHandlerRegistry
java.lang.Object
org.kohsuke.args4j.OptionHandlerRegistry
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
static interface
Provide custom logic for creatingOptionHandler
implementation. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<Class,
OptionHandlerRegistry.OptionHandlerFactory> AllOptionHandler
s known to theCmdLineParser
.private static OptionHandlerRegistry
The shared reference. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Constructs an option handler manager with the default handlers initialized. -
Method Summary
Modifier and TypeMethodDescriptionprotected OptionHandler
createOptionHandler
(CmdLineParser parser, OptionDef o, Setter setter) private static Constructor<? extends OptionHandler>
getConstructor
(Class<? extends OptionHandler> handlerClass) Finds the constructor for an option handler.static OptionHandlerRegistry
Gets the option handler registry singleton instance.private void
Registers the default handlers.void
registerHandler
(Class valueType, Class<? extends OptionHandler> handlerClass) Registers a user-definedOptionHandler
class with args4j.void
registerHandler
(Class valueType, OptionHandlerRegistry.OptionHandlerFactory factory) Registers a user-definedOptionHandler
class with args4j.
-
Field Details
-
instance
The shared reference.- See Also:
-
handlers
AllOptionHandler
s known to theCmdLineParser
. Constructors ofOptionHandler
-derived class keyed by their supported types.
-
-
Constructor Details
-
OptionHandlerRegistry
private OptionHandlerRegistry()Constructs an option handler manager with the default handlers initialized.
-
-
Method Details
-
getRegistry
Gets the option handler registry singleton instance.- Returns:
- a shared instance of the registry.
-
initHandlers
private void initHandlers()Registers the default handlers. -
getConstructor
private static Constructor<? extends OptionHandler> getConstructor(Class<? extends OptionHandler> handlerClass) Finds the constructor for an option handler. -
registerHandler
Registers a user-definedOptionHandler
class with args4j.This method allows users to extend the behavior of args4j by writing their own
OptionHandler
implementation.- Parameters:
valueType
- The specified handler is used when the field/method annotated byOption
is of this type.handlerClass
- This class must have the constructor that has the same signature asOptionHandler(CmdLineParser, OptionDef, Setter)
- Throws:
NullPointerException
- ifvalueType
orhandlerClass
isnull
.IllegalArgumentException
- ifhandlerClass
is not a subtype ofOptionHandler
.
-
registerHandler
Registers a user-definedOptionHandler
class with args4j.This method allows users to extend the behavior of args4j by writing their own
OptionHandler
implementation.- Parameters:
valueType
- The specified handler is used when the field/method annotated byOption
is of this type.factory
- Factory to instantiate handler upon request.- Throws:
NullPointerException
- ifvalueType
orfactory
isnull
.
-
createOptionHandler
-