Package edu.uiuc.ncsa.security.util.cli
Class ConfigurableCommandsImpl
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.cli.ConfigurableCommandsImpl
-
- All Implemented Interfaces:
Logable,Commands,Serializable
public abstract class ConfigurableCommandsImpl extends Object implements Commands
Basic implementation of Commands. This is used for loading a single component (e.g. in the OA4MP command line client) and supports loading configurations. NOTE This does not actually run commands! It is a top-level class that delegates to its command implementations (such as for stores, keys). Therefore, you should not put code here that actually executes things. The contract of this is that it manages logging, loading configurations and instantiating the actualCommandsimplementations that do everything.Created by Jeff Gaynor
on 5/20/13 at 11:35 AM- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConfigurableCommandsImpl.ListOnlyNotification
-
Field Summary
Fields Modifier and Type Field Description static StringCOMMENT_STARTstatic StringCOMMENT_START_OPTIONstatic StringCONFIG_FILE_LONG_OPTIONstatic StringCONFIG_FILE_OPTIONstatic StringCONFIG_NAME_LONG_OPTIONstatic StringCONFIG_NAME_OPTIONstatic StringDEBUG_LONG_OPTIONstatic StringDEBUG_OPTIONstatic StringENV_LONG_OPTIONstatic StringENV_OPTIONprotected StringFILE_SWITCHstatic StringHELP_LONG_OPTIONstatic StringHELP_OPTIONstatic StringINPUT_OPTIONstatic StringLOG_FILE_LONG_OPTIONstatic StringLOG_FILE_OPTIONstatic StringOUTPUT_OPTIONstatic StringVERBOSE_LONG_OPTIONstatic StringVERBOSE_OPTION
-
Constructor Summary
Constructors Modifier Constructor Description protectedConfigurableCommandsImpl(MyLoggingFacade logger)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description InputLinebootstrap(InputLine args)Parses command line arguments.voidconfigureCommands(CLIDriver cli, CommonCommands commands)Take (newly created)CommonCommands2and initialize its driver.voiddebug(String x)Write a debug message to the log.protected List<String>doListNames(File target)Figures out by file extension what to list.voiderror(String x)Write an error message to the log.protected abstract ConfigurationLoader<? extends AbstractEnvironment>figureOutLoader(String fileName, String configName)This is done so configurations can be loaded by inheritors.abstract StringgetComponentName()For the configuration.StringgetConfigFile()StringgetConfigName()CLIDrivergetDriver()Back reference to the driver that manages this instance.AbstractEnvironmentgetEnvironment()Map<Object,Object>getGlobalEnv()IOInterfacegetIOInterface()abstract ConfigurationLoader<? extends AbstractEnvironment>getLoader()MyLoggingFacadegetMyLogger()protected booleanhasLogger()voidinfo(String x)Write an informational message to the logprotected voidinitialize()Called at initialization to read and process the command line arguments.booleanisDebugOn()Query if debugging is enabled for this logger.booleanisVerbose()protected voidlistConfigs(InputLine inputLine)protected List<String>listXMLConfigs(File target)voidload(InputLine inputLine)protected voidloadConfig(String filename, String configName)protected StringpadLineWithBlanks(String x, int width)Deprecated.protected voidreadEnv(String path, boolean verbose)protected voidsay(String x)protected voidsayv(String x)voidsetConfigFile(String configFile)voidsetConfigName(String configName)voidsetDebugOn(boolean setOn)Enable/disable debugging for this loggervoidsetDriver(CLIDriver driver)Back reference to the driver for this classvoidsetEnvironment(AbstractEnvironment environment)abstract voidsetLoader(ConfigurationLoader<? extends AbstractEnvironment> loader)voidsetMyLogger(MyLoggingFacade myLoggingFacade)voidsetVerbose(boolean verbose)protected booleanshowHelp(InputLine inputLine)returns "true if the command has the flag --help in it.protected voidshowLoadHelp()protected booleanswitchOrRun(InputLine inputLine, CommonCommands commands)Either switch to another component or (if there are arguments) simply run the single command and return.voidtrace(InputLine inputLine)booleanuse(InputLine inputLine)Override this to invoke the specific components that make up your CLI.abstract voiduseHelp()voidwarn(String x)Write a warning to the log.
-
-
-
Field Detail
-
FILE_SWITCH
protected String FILE_SWITCH
-
VERBOSE_OPTION
public static final String VERBOSE_OPTION
- See Also:
- Constant Field Values
-
VERBOSE_LONG_OPTION
public static final String VERBOSE_LONG_OPTION
- See Also:
- Constant Field Values
-
DEBUG_OPTION
public static final String DEBUG_OPTION
- See Also:
- Constant Field Values
-
DEBUG_LONG_OPTION
public static final String DEBUG_LONG_OPTION
- See Also:
- Constant Field Values
-
LOG_FILE_OPTION
public static final String LOG_FILE_OPTION
- See Also:
- Constant Field Values
-
LOG_FILE_LONG_OPTION
public static final String LOG_FILE_LONG_OPTION
- See Also:
- Constant Field Values
-
HELP_OPTION
public static final String HELP_OPTION
- See Also:
- Constant Field Values
-
HELP_LONG_OPTION
public static final String HELP_LONG_OPTION
- See Also:
- Constant Field Values
-
INPUT_OPTION
public static final String INPUT_OPTION
- See Also:
- Constant Field Values
-
OUTPUT_OPTION
public static final String OUTPUT_OPTION
- See Also:
- Constant Field Values
-
COMMENT_START_OPTION
public static final String COMMENT_START_OPTION
- See Also:
- Constant Field Values
-
COMMENT_START
public static String COMMENT_START
-
CONFIG_FILE_OPTION
public static final String CONFIG_FILE_OPTION
- See Also:
- Constant Field Values
-
CONFIG_FILE_LONG_OPTION
public static final String CONFIG_FILE_LONG_OPTION
- See Also:
- Constant Field Values
-
ENV_OPTION
public static final String ENV_OPTION
- See Also:
- Constant Field Values
-
ENV_LONG_OPTION
public static final String ENV_LONG_OPTION
- See Also:
- Constant Field Values
-
CONFIG_NAME_OPTION
public static final String CONFIG_NAME_OPTION
- See Also:
- Constant Field Values
-
CONFIG_NAME_LONG_OPTION
public static final String CONFIG_NAME_LONG_OPTION
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ConfigurableCommandsImpl
protected ConfigurableCommandsImpl(MyLoggingFacade logger)
-
-
Method Detail
-
showHelp
protected boolean showHelp(InputLine inputLine)
returns "true if the command has the flag --help in it. This is a cue from the user to show the help for a given function. So it the function is called "X" and its help is in the function "showXHelp" then a value of true from this should simply invoke "showXHelp" and return.- Parameters:
inputLine-- Returns:
-
getIOInterface
public IOInterface getIOInterface()
- Specified by:
getIOInterfacein interfaceCommands
-
say
protected void say(String x)
-
sayv
protected void sayv(String x)
-
getConfigName
public String getConfigName()
-
setConfigName
public void setConfigName(String configName)
-
doListNames
protected List<String> doListNames(File target) throws Exception
Figures out by file extension what to list. Override as needed. Default is .xml.- Parameters:
target-- Returns:
- Throws:
Exception
-
listXMLConfigs
protected List<String> listXMLConfigs(File target) throws Exception
- Throws:
Exception
-
showLoadHelp
protected void showLoadHelp()
-
getEnvironment
public AbstractEnvironment getEnvironment() throws Exception
- Throws:
Exception
-
setEnvironment
public void setEnvironment(AbstractEnvironment environment)
-
getComponentName
public abstract String getComponentName()
For the configuration. This is the tag name (e.g. "client" or "server") in the XML file.- Returns:
-
getLoader
public abstract ConfigurationLoader<? extends AbstractEnvironment> getLoader()
-
setLoader
public abstract void setLoader(ConfigurationLoader<? extends AbstractEnvironment> loader)
-
readEnv
protected void readEnv(String path, boolean verbose)
-
initialize
protected void initialize()
Called at initialization to read and process the command line arguments. NOTE that this is not called in this class, but by inheritors.
-
loadConfig
protected void loadConfig(String filename, String configName) throws Throwable
- Throws:
Throwable
-
figureOutLoader
protected abstract ConfigurationLoader<? extends AbstractEnvironment> figureOutLoader(String fileName, String configName) throws Throwable
This is done so configurations can be loaded by inheritors.- Parameters:
fileName-configName-- Returns:
- Throws:
Throwable
-
getConfigFile
public String getConfigFile()
-
setConfigFile
public void setConfigFile(String configFile)
-
bootstrap
public InputLine bootstrap(InputLine args) throws Throwable
Parses command line arguments. This is usually called afterCLIDriver.bootstrap(String[]), which pulls off its startup options
-
isDebugOn
public boolean isDebugOn()
Description copied from interface:LogableQuery if debugging is enabled for this logger.
-
setDebugOn
public void setDebugOn(boolean setOn)
Description copied from interface:LogableEnable/disable debugging for this logger- Specified by:
setDebugOnin interfaceLogable
-
setMyLogger
public void setMyLogger(MyLoggingFacade myLoggingFacade)
-
getMyLogger
public MyLoggingFacade getMyLogger()
-
hasLogger
protected boolean hasLogger()
-
debug
public void debug(String x)
Description copied from interface:LogableWrite a debug message to the log.
-
info
public void info(String x)
Description copied from interface:LogableWrite an informational message to the log
-
warn
public void warn(String x)
Description copied from interface:LogableWrite a warning to the log. This indicates a severe, but non-fatal condition exists.
-
error
public 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.
-
isVerbose
public boolean isVerbose()
-
setVerbose
public void setVerbose(boolean verbose)
-
padLineWithBlanks
protected String padLineWithBlanks(String x, int width)
Deprecated.This will take a String and append the correct number of blanks on the left so it is the right width. This is used for making the banner.Used extensively in subclasses for formatting help
- Returns:
-
useHelp
public abstract void useHelp()
-
use
public boolean use(InputLine inputLine) throws Throwable
Override this to invoke the specific components that make up your CLI.
-
switchOrRun
protected boolean switchOrRun(InputLine inputLine, CommonCommands commands)
Either switch to another component or (if there are arguments) simply run the single command and return. Note that each component has stored state, so these will be run with whatever is in that state. Requiresuse(InputLine)be overridden.- Parameters:
inputLine-commands-- Returns:
-
configureCommands
public void configureCommands(CLIDriver cli, CommonCommands commands) throws Throwable
Take (newly created)CommonCommands2and initialize its driver. This should be called once, right after creation. It is a type of configuration injection.- Parameters:
cli-commands-- Throws:
Throwable
-
getDriver
public CLIDriver getDriver()
Description copied from interface:CommandsBack reference to the driver that manages this instance.
-
-