Package adams.core.option
Class AbstractCommandLineHandler
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.option.AbstractCommandLineHandler
-
- All Implemented Interfaces:
LoggingSupporter,SizeOfHandler,Serializable
- Direct Known Subclasses:
AdamsCommandLineHandler,BaseObjectCommandLineHandler,DefaultCommandLineHandler,JenericCommandLineHandler,WekaCommandLineHandler
public abstract class AbstractCommandLineHandler extends LoggingObject
Ancestor for classes that handle commandline options for various frameworks.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringFILENAMEthe props file with the static class name lists.static StringKEY_HANDLERSthe key in the props file with the static class name lists.protected static Hashtable<Class,Class>m_Cachethe cache for object class / handler relation.protected static Class[]m_HandlerClassesthe handlers (classes) currently available.-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCommandLineHandler()Initializes the handler.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ObjectfromArray(String[] args)Generates an object from the commandline options.abstract ObjectfromArray(String[] args, MessageCollection errors)Generates an object from the commandline options.ObjectfromCommandLine(String cmd)Generates an object from the specified commandline.abstract ObjectfromCommandLine(String cmd, MessageCollection errors)Generates an object from the specified commandline.static AbstractCommandLineHandlergetHandler(Class cls)Returns a handler for the specified class.static AbstractCommandLineHandlergetHandler(Object obj)Returns a handler for the specified object.abstract String[]getOptions(Object obj)Returns the commandline options (without classname) of the specified object.abstract booleanhandles(Class cls)Checks whether the given class can be processed.booleanhandles(Object obj)Checks whether the given objects can be processed.protected static voidinitHandlers()Initializes the handlers.protected voidinitialize()For initializing members.abstract StringjoinOptions(String[] args)Turns the option array back into a commandline.abstract booleansetOptions(Object obj, String[] args)Sets the options of the specified object.abstract String[]splitOptions(String cmdline)Splits the commandline into an array.abstract String[]toArray(Object obj)Generates an options array from the specified object.abstract StringtoCommandLine(Object obj)Generates a commandline from the specified object.abstract StringtoShortCommandLine(Object obj)Generates a commandline from the specified object.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
FILENAME
public static final String FILENAME
the props file with the static class name lists.- See Also:
- Constant Field Values
-
KEY_HANDLERS
public static final String KEY_HANDLERS
the key in the props file with the static class name lists.- See Also:
- Constant Field Values
-
m_Cache
protected static Hashtable<Class,Class> m_Cache
the cache for object class / handler relation.
-
m_HandlerClasses
protected static Class[] m_HandlerClasses
the handlers (classes) currently available.
-
-
Method Detail
-
initialize
protected void initialize()
For initializing members.
Default implementation does nothing.
-
fromCommandLine
public Object fromCommandLine(String cmd)
Generates an object from the specified commandline.- Parameters:
cmd- the commandline to create the object from- Returns:
- the created object, null in case of error
-
fromCommandLine
public abstract Object fromCommandLine(String cmd, MessageCollection errors)
Generates an object from the specified commandline.- Parameters:
cmd- the commandline to create the object fromerrors- for recording errors- Returns:
- the created object, null in case of error
-
fromArray
public Object fromArray(String[] args)
Generates an object from the commandline options.- Parameters:
args- the commandline options to create the object from- Returns:
- the created object, null in case of error
-
fromArray
public abstract Object fromArray(String[] args, MessageCollection errors)
Generates an object from the commandline options.- Parameters:
args- the commandline options to create the object fromerrors- for recording errors- Returns:
- the created object, null in case of error
-
toCommandLine
public abstract String toCommandLine(Object obj)
Generates a commandline from the specified object.- Parameters:
obj- the object to create the commandline for- Returns:
- the generated commandline
-
toShortCommandLine
public abstract String toShortCommandLine(Object obj)
Generates a commandline from the specified object. Uses a shortened format, e.g., removing the package from the class.- Parameters:
obj- the object to create the commandline for- Returns:
- the generated commandline
-
toArray
public abstract String[] toArray(Object obj)
Generates an options array from the specified object.- Parameters:
obj- the object to create the array for- Returns:
- the generated array
-
getOptions
public abstract String[] getOptions(Object obj)
Returns the commandline options (without classname) of the specified object.- Parameters:
obj- the object to get the options from- Returns:
- the options
-
setOptions
public abstract boolean setOptions(Object obj, String[] args)
Sets the options of the specified object.- Parameters:
obj- the object to set the options forargs- the options- Returns:
- true if options successfully set
-
splitOptions
public abstract String[] splitOptions(String cmdline)
Splits the commandline into an array.- Parameters:
cmdline- the commandline to split- Returns:
- the generated array of options
-
joinOptions
public abstract String joinOptions(String[] args)
Turns the option array back into a commandline.- Parameters:
args- the options to turn into a commandline- Returns:
- the generated commandline
-
handles
public boolean handles(Object obj)
Checks whether the given objects can be processed.- Parameters:
obj- the object to inspect- Returns:
- true if the handler can process the object
-
handles
public abstract boolean handles(Class cls)
Checks whether the given class can be processed.- Parameters:
cls- the class to inspect- Returns:
- true if the handler can process the class
-
initHandlers
protected static void initHandlers()
Initializes the handlers.
-
getHandler
public static AbstractCommandLineHandler getHandler(Object obj)
Returns a handler for the specified object.- Parameters:
obj- the object to get a commandline handler for- Returns:
- the handler
-
getHandler
public static AbstractCommandLineHandler getHandler(Class cls)
Returns a handler for the specified class.- Parameters:
cls- the class to get a commandline handler for- Returns:
- the handler
-
-