Package org.kohsuke.args4j
Class OptionHandlerRegistry
- java.lang.Object
-
- org.kohsuke.args4j.OptionHandlerRegistry
-
public class OptionHandlerRegistry extends java.lang.Object
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 thegetRegistry()
call.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
OptionHandlerRegistry.DefaultConstructorHandlerFactory
static interface
OptionHandlerRegistry.OptionHandlerFactory
Provide custom logic for creatingOptionHandler
implementation.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Class,OptionHandlerRegistry.OptionHandlerFactory>
handlers
AllOptionHandler
s known to theCmdLineParser
.private static OptionHandlerRegistry
instance
The shared reference.
-
Constructor Summary
Constructors Modifier Constructor Description private
OptionHandlerRegistry()
Constructs an option handler manager with the default handlers initialized.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected OptionHandler
createOptionHandler(CmdLineParser parser, OptionDef o, Setter setter)
private static java.lang.reflect.Constructor<? extends OptionHandler>
getConstructor(java.lang.Class<? extends OptionHandler> handlerClass)
Finds the constructor for an option handler.static OptionHandlerRegistry
getRegistry()
Gets the option handler registry singleton instance.private void
initHandlers()
Registers the default handlers.void
registerHandler(java.lang.Class valueType, java.lang.Class<? extends OptionHandler> handlerClass)
Registers a user-definedOptionHandler
class with args4j.void
registerHandler(java.lang.Class valueType, OptionHandlerRegistry.OptionHandlerFactory factory)
Registers a user-definedOptionHandler
class with args4j.
-
-
-
Field Detail
-
instance
private static OptionHandlerRegistry instance
The shared reference.- See Also:
getRegistry()
-
handlers
private final java.util.Map<java.lang.Class,OptionHandlerRegistry.OptionHandlerFactory> handlers
AllOptionHandler
s known to theCmdLineParser
. Constructors ofOptionHandler
-derived class keyed by their supported types.
-
-
Method Detail
-
getRegistry
public static OptionHandlerRegistry 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 java.lang.reflect.Constructor<? extends OptionHandler> getConstructor(java.lang.Class<? extends OptionHandler> handlerClass)
Finds the constructor for an option handler.
-
registerHandler
public void registerHandler(java.lang.Class valueType, java.lang.Class<? extends OptionHandler> handlerClass)
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:
java.lang.NullPointerException
- ifvalueType
orhandlerClass
isnull
.java.lang.IllegalArgumentException
- ifhandlerClass
is not a subtype ofOptionHandler
.
-
registerHandler
public void registerHandler(java.lang.Class valueType, OptionHandlerRegistry.OptionHandlerFactory factory)
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:
java.lang.NullPointerException
- ifvalueType
orfactory
isnull
.
-
createOptionHandler
protected OptionHandler createOptionHandler(CmdLineParser parser, OptionDef o, Setter setter)
-
-