public abstract class CLITool extends Object implements Logable
Created by Jeff Gaynor
on 9/7/11 at 12:31 PM
Modifier and Type | Field and Description |
---|---|
static String |
CONFIG_FILE_LONG_OPTION |
static String |
CONFIG_FILE_OPTION |
static int |
CONFIG_NAME_ACTION |
static String |
CONFIG_NAME_LONG_OPTION |
static String |
CONFIG_NAME_OPTION |
static String |
DEBUG_LONG_OPTION |
static String |
DEBUG_OPTION |
static String |
DEFAULT_LOG_FILE |
static String |
HELP_LONG_OPTION |
static String |
HELP_OPTION |
static String |
LOG_FILE_LONG_OPTION |
static String |
LOG_FILE_OPTION |
static int |
NO_ACTION
The default action for this tool at startup.
|
static String |
VERBOSE_LONG_OPTION |
static String |
VERBOSE_OPTION |
Constructor and Description |
---|
CLITool() |
Modifier and Type | Method and Description |
---|---|
protected void |
checkAction(String flag,
String longFlag,
int action)
Converts command line arguments into integer action values.
|
void |
debug(String x)
Write a debug message to the log.
|
static void |
defaultHelp(boolean printHeader)
Convenience method.
|
abstract void |
doIt()
Does the actual work.
|
void |
error(String x)
Write an error message to the log.
|
void |
error(String x,
Throwable t) |
int |
getAction()
This application allows you to specify numeric values that determine the behavior of this application.
|
BufferedReader |
getBufferedReader() |
org.apache.commons.cli.CommandLine |
getCommandLine() |
abstract String |
getComponentName()
Returns the name of the configuration component (usually "server" or "client") that identifies the XML
elements which might have the configuration.
|
String |
getConfigFile() |
protected org.apache.commons.configuration.tree.ConfigurationNode |
getConfigurationNode() |
AbstractEnvironment |
getEnvironment() |
abstract ConfigurationLoader<? extends AbstractEnvironment> |
getLoader() |
String |
getLogfileName() |
MyLoggingFacade |
getMyLogger() |
protected org.apache.commons.cli.Options |
getOptions()
Override this to set up your options.
|
protected boolean |
getOptions(String[] args)
Returns true if execution should continue, false if not.
|
protected boolean |
hasOption(String shortForm,
String longForm)
Checks if the long or short form is part of the command line options.
|
abstract void |
help()
This will be automatically invoked for you if the user supplies a help option.
|
void |
info(String x)
Write an informational message to the log
|
void |
initialize()
Sets up the configuration and runtime environment.
|
boolean |
isDebugOn()
Query if debugging is enabled for this logger.
|
boolean |
isVerbose() |
protected void |
parseCommandLine(String[] args) |
protected String |
readline() |
void |
run()
Calls the
initialize() method and then runs the main doIt() method. |
void |
run(String[] args)
Main call.
|
static void |
say(String x)
Prints to the console.
|
void |
say2(String x)
Prints to the console WITHOUT a carriage return.
|
void |
sayv(String x)
Prints to the console only if verbose is enabled.
|
void |
setAction(int action) |
void |
setBufferedReader(BufferedReader bufferedReader) |
void |
setCommandLine(String[] args)
So you can construct the argument list and have this tool use its built in configuration.
|
void |
setConfigFile(String configFile) |
protected void |
setConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode configurationNode) |
void |
setDebugOn(boolean setOn)
Enable/disable debugging for this logger
|
void |
setEnvironment(AbstractEnvironment environment) |
void |
setLogfileName(String logfileName) |
void |
setMyLogger(MyLoggingFacade myLoggingFacade) |
void |
setVerbose(boolean verbose) |
void |
warn(String x)
Write a warning to the log.
|
public static final String VERBOSE_OPTION
public static final String VERBOSE_LONG_OPTION
public static final String DEBUG_OPTION
public static final String DEBUG_LONG_OPTION
public static final String LOG_FILE_OPTION
public static final String LOG_FILE_LONG_OPTION
public static final String HELP_OPTION
public static final String HELP_LONG_OPTION
public static final String CONFIG_FILE_OPTION
public static final String CONFIG_FILE_LONG_OPTION
public static final String DEFAULT_LOG_FILE
public static final String CONFIG_NAME_OPTION
public static final String CONFIG_NAME_LONG_OPTION
public static final int CONFIG_NAME_ACTION
public static final int NO_ACTION
public AbstractEnvironment getEnvironment() throws Exception
Exception
public void setEnvironment(AbstractEnvironment environment)
public abstract String getComponentName()
public abstract ConfigurationLoader<? extends AbstractEnvironment> getLoader() throws Exception
Exception
public BufferedReader getBufferedReader()
public void setBufferedReader(BufferedReader bufferedReader)
protected String readline() throws IOException
IOException
public abstract void doIt() throws Exception
Exception
protected org.apache.commons.configuration.tree.ConfigurationNode getConfigurationNode()
protected void setConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode configurationNode)
public void initialize() throws Exception
getLoader()
method.Exception
public abstract void help()
say(String)
method), rather than logging
the help.public static void defaultHelp(boolean printHeader)
public String getConfigFile()
public void setConfigFile(String configFile)
public String getLogfileName()
public void setLogfileName(String logfileName)
public boolean isVerbose()
public void setVerbose(boolean verbose)
protected boolean getOptions(String[] args) throws Exception
args
- Exception
protected boolean hasOption(String shortForm, String longForm)
shortForm
- longForm
- protected void parseCommandLine(String[] args)
public void setCommandLine(String[] args)
args
- public org.apache.commons.cli.CommandLine getCommandLine()
public int getAction()
getOptions(String[])
method and access them in the doIt()
method. Use of this facility, is optional.public void setAction(int action)
protected void checkAction(String flag, String longFlag, int action)
The only supplied default is NO_ACTION
flag
- longFlag
- action
- protected org.apache.commons.cli.Options getOptions()
Options options = super.getOptions();
options.addOptions(SHORT_FORM, LONG_FORM, ... // This is in the commons documentation
checkAction(SHORT_FORM, LONG_FORM, ACTION_CODE);
getAction()
call in
a switch statement.public void sayv(String x)
x
- public static void say(String x)
x
- public void say2(String x)
x
- public void setMyLogger(MyLoggingFacade myLoggingFacade)
public MyLoggingFacade getMyLogger()
public void debug(String x)
Logable
public boolean isDebugOn()
Logable
public void setDebugOn(boolean setOn)
Logable
setDebugOn
in interface Logable
public void info(String x)
Logable
public void warn(String x)
Logable
public void error(String x)
Logable
public void run() throws Throwable
initialize()
method and then runs the main doIt()
method. Call this if you set
the target and source in the constructor.Throwable
public void run(String[] args) throws Throwable
initialize()
and then invoke doIt()
.args
- Throwable
Copyright © 2019. All Rights Reserved.