Package edu.uiuc.ncsa.security.util.cli
Class CLITool2
- java.lang.Object
- 
- edu.uiuc.ncsa.security.util.cli.CLITool2
 
- 
- All Implemented Interfaces:
- Logable
 
 public abstract class CLITool2 extends Object implements Logable Basic class for writing command line tools. This allows for verbose, debug and help options automatically. It supports logging to a file and specifying a configuration file names. In short, a lot of the random grunt work for using the commons command line toolkit is here.Created by Jeff Gaynor 
 on 9/7/11 at 12:31 PM
- 
- 
Field SummaryFields Modifier and Type Field Description static StringCONFIG_FILE_LONG_OPTIONstatic StringCONFIG_FILE_OPTIONstatic intCONFIG_NAME_ACTIONstatic StringCONFIG_NAME_LONG_OPTIONstatic StringCONFIG_NAME_OPTIONstatic StringDEBUG_LONG_OPTIONstatic StringDEBUG_OPTIONstatic StringDEFAULT_LOG_FILEstatic StringHELP_LONG_OPTIONstatic StringHELP_OPTIONstatic StringLOG_FILE_LONG_OPTIONstatic StringLOG_FILE_OPTIONstatic intNO_ACTIONThe default action for this tool at startup.static StringVERBOSE_LONG_OPTIONstatic StringVERBOSE_OPTION
 - 
Constructor SummaryConstructors Constructor Description CLITool2()
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voiddebug(String x)Write a debug message to the log.static voiddefaultHelp(boolean printHeader)Convenience method.abstract voiddoIt()Does the actual work.voiderror(String x)Write an error message to the log.voiderror(String x, Throwable t)BufferedReadergetBufferedReader()abstract StringgetComponentName()Returns the name of the configuration component (usually "server" or "client") that identifies the XML elements which might have the configuration.StringgetConfigFile()StringgetConfigName()protected org.apache.commons.configuration.tree.ConfigurationNodegetConfigurationNode()AbstractEnvironmentgetEnvironment()InputLinegetInputLine()Get the original input line.static IOInterfacegetIoInterface()abstract ConfigurationLoader<? extends AbstractEnvironment>getLoader()StringgetLogfileName()MyLoggingFacadegetMyLogger()protected booleangetOptions(String[] args)Returns true if execution should continue, false if not.booleanhasConfigFile()booleanhasConfigName()abstract voidhelp()This will be automatically invoked for you if the user supplies a help option.voidinfo(String x)Write an informational message to the logvoidinitialize()Sets up the configuration and runtime environment.booleanisDebugOn()Query if debugging is enabled for this logger.booleanisVerbose()protected Stringreadline()voidrun()Calls theinitialize()method and then runs the maindoIt()method.voidrun(String[] args)Main call.static voidsay(String x)Prints to the console.voidsay2(String x)Prints to the console WITHOUT a carriage return.voidsayv(String x)Prints to the console only if verbose is enabled.voidsetBufferedReader(BufferedReader bufferedReader)voidsetConfigFile(String configFile)voidsetConfigName(String configName)protected voidsetConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode configurationNode)voidsetDebugOn(boolean setOn)Enable/disable debugging for this loggervoidsetEnvironment(AbstractEnvironment environment)voidsetInputLine(InputLine inputLine)static voidsetIoInterface(IOInterface newIOInterface)voidsetLogfileName(String logfileName)voidsetMyLogger(MyLoggingFacade myLoggingFacade)voidsetVerbose(boolean verbose)voidwarn(String x)Write a warning to the log.
 
- 
- 
- 
Field Detail- 
VERBOSE_OPTIONpublic static final String VERBOSE_OPTION - See Also:
- Constant Field Values
 
 - 
VERBOSE_LONG_OPTIONpublic static final String VERBOSE_LONG_OPTION - See Also:
- Constant Field Values
 
 - 
DEBUG_OPTIONpublic static final String DEBUG_OPTION - See Also:
- Constant Field Values
 
 - 
DEBUG_LONG_OPTIONpublic static final String DEBUG_LONG_OPTION - See Also:
- Constant Field Values
 
 - 
LOG_FILE_OPTIONpublic static final String LOG_FILE_OPTION - See Also:
- Constant Field Values
 
 - 
LOG_FILE_LONG_OPTIONpublic static final String LOG_FILE_LONG_OPTION - See Also:
- Constant Field Values
 
 - 
HELP_OPTIONpublic static final String HELP_OPTION - See Also:
- Constant Field Values
 
 - 
HELP_LONG_OPTIONpublic static final String HELP_LONG_OPTION - See Also:
- Constant Field Values
 
 - 
CONFIG_FILE_OPTIONpublic static final String CONFIG_FILE_OPTION - See Also:
- Constant Field Values
 
 - 
CONFIG_FILE_LONG_OPTIONpublic static final String CONFIG_FILE_LONG_OPTION - See Also:
- Constant Field Values
 
 - 
DEFAULT_LOG_FILEpublic static final String DEFAULT_LOG_FILE - See Also:
- Constant Field Values
 
 - 
CONFIG_NAME_OPTIONpublic static final String CONFIG_NAME_OPTION - See Also:
- Constant Field Values
 
 - 
CONFIG_NAME_LONG_OPTIONpublic static final String CONFIG_NAME_LONG_OPTION - See Also:
- Constant Field Values
 
 - 
CONFIG_NAME_ACTIONpublic static final int CONFIG_NAME_ACTION - See Also:
- Constant Field Values
 
 - 
NO_ACTIONpublic static final int NO_ACTION The default action for this tool at startup. Do nothing.- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getEnvironmentpublic AbstractEnvironment getEnvironment() throws Exception - Throws:
- Exception
 
 - 
setEnvironmentpublic void setEnvironment(AbstractEnvironment environment) 
 - 
getComponentNamepublic abstract String getComponentName() Returns the name of the configuration component (usually "server" or "client") that identifies the XML elements which might have the configuration. These are resolved by their name attribute.- Returns:
 
 - 
getLoaderpublic abstract ConfigurationLoader<? extends AbstractEnvironment> getLoader() throws Exception - Throws:
- Exception
 
 - 
getBufferedReaderpublic BufferedReader getBufferedReader() 
 - 
setBufferedReaderpublic void setBufferedReader(BufferedReader bufferedReader) 
 - 
readlineprotected String readline() throws IOException - Throws:
- IOException
 
 - 
getIoInterfacepublic static IOInterface getIoInterface() 
 - 
setIoInterfacepublic static void setIoInterface(IOInterface newIOInterface) 
 - 
doItpublic abstract void doIt() throws ExceptionDoes the actual work. This is where you put your executable code.- Throws:
- Exception
 
 - 
getConfigurationNodeprotected org.apache.commons.configuration.tree.ConfigurationNode getConfigurationNode() 
 - 
setConfigurationNodeprotected void setConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode configurationNode) 
 - 
initializepublic void initialize() throws ExceptionSets up the configuration and runtime environment. This is called typically in the constructors before anything else is called. Always call super on this method if you override it! At the end of this method, the configuration node has been found and set for you to call in yourgetLoader()method.- Throws:
- Exception
 
 - 
helppublic abstract void help() This will be automatically invoked for you if the user supplies a help option. This should just print out to the command line (using thesay(String)method), rather than logging the help.
 - 
defaultHelppublic static void defaultHelp(boolean printHeader) Convenience method. This prints out a short message describing the built-in options for this class. Best called at the end of your custom help method. Prints a header (informational line) if you wish.
 - 
hasConfigFilepublic boolean hasConfigFile() 
 - 
getConfigFilepublic String getConfigFile() 
 - 
setConfigFilepublic void setConfigFile(String configFile) 
 - 
getLogfileNamepublic String getLogfileName() 
 - 
setLogfileNamepublic void setLogfileName(String logfileName) 
 - 
isVerbosepublic boolean isVerbose() 
 - 
setVerbosepublic void setVerbose(boolean verbose) 
 - 
getOptionsprotected boolean getOptions(String[] args) Returns true if execution should continue, false if not. Call this first to see if execution should proceed.- Parameters:
- args-
- Returns:
- Throws:
- Exception
 
 - 
getInputLinepublic InputLine getInputLine() Get the original input line.- Returns:
 
 - 
setInputLinepublic void setInputLine(InputLine inputLine) 
 - 
getConfigNamepublic String getConfigName() 
 - 
setConfigNamepublic void setConfigName(String configName) 
 - 
hasConfigNamepublic boolean hasConfigName() 
 - 
sayvpublic void sayv(String x) Prints to the console only if verbose is enabled.- Parameters:
- x-
 
 - 
saypublic static void say(String x) Prints to the console.- Parameters:
- x-
 
 - 
say2public void say2(String x) Prints to the console WITHOUT a carriage return. Useful for imput prompts rather than informational messages.- Parameters:
- x-
 
 - 
setMyLoggerpublic void setMyLogger(MyLoggingFacade myLoggingFacade) 
 - 
getMyLoggerpublic MyLoggingFacade getMyLogger() 
 - 
debugpublic void debug(String x) Description copied from interface:LogableWrite a debug message to the log.
 - 
isDebugOnpublic boolean isDebugOn() Description copied from interface:LogableQuery if debugging is enabled for this logger.
 - 
setDebugOnpublic void setDebugOn(boolean setOn) Description copied from interface:LogableEnable/disable debugging for this logger- Specified by:
- setDebugOnin interface- Logable
 
 - 
infopublic void info(String x) Description copied from interface:LogableWrite an informational message to the log
 - 
warnpublic void warn(String x) Description copied from interface:LogableWrite a warning to the log. This indicates a severe, but non-fatal condition exists.
 - 
errorpublic void error(String x) Description copied from interface:LogableWrite an error message to the log. Typically this is invoked as the last command before throwing an exception.
 - 
runpublic void run() throws ThrowableCalls theinitialize()method and then runs the maindoIt()method. Call this if you set the target and source in the constructor.- Throws:
- Throwable
 
 - 
runpublic void run(String[] args) throws Throwable Main call. This will grab the command line arguments, runinitialize()and then invokedoIt().- Parameters:
- args-
- Throws:
- Throwable
 
 
- 
 
-