Package edu.uiuc.ncsa.security.util.cli
Class ConfigurableCommandsImpl
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.cli.ConfigurableCommandsImpl
-
- All Implemented Interfaces:
Logable
,Commands
,ComponentManager
public abstract class ConfigurableCommandsImpl extends Object implements Commands, ComponentManager
Basic implementation of Commands. This 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 actualCommands
implementations that do everything.Created by Jeff Gaynor
on 5/20/13 at 11:35 AM
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConfigurableCommandsImpl.ListOnlyNotification
-
Field Summary
Fields Modifier and Type Field Description static String
COMMENT_START
static String
COMMENT_START_OPTION
static String
CONFIG_FILE_LONG_OPTION
static String
CONFIG_FILE_OPTION
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
ENV_LONG_OPTION
static String
ENV_OPTION
protected String
FILE_SWITCH
static String
HELP_LONG_OPTION
static String
HELP_OPTION
static String
INPUT_OPTION
static String
LOG_FILE_LONG_OPTION
static String
LOG_FILE_OPTION
static String
OUTPUT_OPTION
static String
USE_COMPONENT_LONG_OPTION
static String
USE_COMPONENT_OPTION
static String
VERBOSE_LONG_OPTION
static String
VERBOSE_OPTION
-
Constructor Summary
Constructors Modifier Constructor Description protected
ConfigurableCommandsImpl(MyLoggingFacade logger)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
debug(String x)
Write a debug message to the log.protected List<String>
doListNames(File target)
Figures out by file extension what to list.void
error(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.org.apache.commons.cli.CommandLine
getCommandLine()
abstract String
getComponentName()
For the configuration.String
getConfigFile()
String
getConfigName()
AbstractEnvironment
getEnvironment()
Map<Object,Object>
getGlobalEnv()
IOInterface
getIOInterface()
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.void
info(String x)
Write an informational message to the logvoid
initialize()
Called at initialization to read and process the command line arguments.boolean
isDebugOn()
Query if debugging is enabled for this logger.boolean
isVerbose()
protected void
listConfigs(InputLine inputLine)
protected List<String>
listXMLConfigs(File target)
void
load(InputLine inputLine)
protected void
loadConfig(String filename, String configName)
protected String
padLineWithBlanks(String x, int width)
This will take a String and append the correct number of blanks on the left so it is the right width.protected void
parseCommandLine(String[] args)
void
print_help()
protected void
readEnv(String path, boolean verbose)
protected void
say(String x)
protected void
sayv(String x)
void
setConfigFile(String configFile)
void
setConfigName(String configName)
void
setDebugOn(boolean setOn)
Enable/disable debugging for this loggervoid
setEnvironment(AbstractEnvironment environment)
void
setIOInterface(IOInterface ioInterface)
abstract void
setLoader(ConfigurationLoader<? extends AbstractEnvironment> loader)
void
setLogfileName(String logfileName)
void
setMyLogger(MyLoggingFacade myLoggingFacade)
void
setVerbose(boolean verbose)
protected boolean
showHelp(InputLine inputLine)
returns "true if the command has the flag --help in it.protected void
showLoadHelp()
void
trace(InputLine inputLine)
boolean
use(InputLine inputLine)
Override this to invoke the specific components that make up your CLI.abstract void
useHelp()
void
warn(String x)
Write a warning to the log.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface edu.uiuc.ncsa.security.util.cli.Commands
bootstrap, getHelpUtil, getPrompt
-
Methods inherited from interface edu.uiuc.ncsa.security.util.cli.ComponentManager
listComponents
-
-
-
-
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
-
USE_COMPONENT_OPTION
public static final String USE_COMPONENT_OPTION
- See Also:
- Constant Field Values
-
USE_COMPONENT_LONG_OPTION
public static final String USE_COMPONENT_LONG_OPTION
- See Also:
- Constant Field Values
-
DEFAULT_LOG_FILE
public static final String DEFAULT_LOG_FILE
- 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:
getIOInterface
in interfaceCommands
-
setIOInterface
public void setIOInterface(IOInterface ioInterface)
- Specified by:
setIOInterface
in 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)
-
print_help
public void print_help() throws Exception
- Specified by:
print_help
in interfaceCommands
- Throws:
Exception
-
initialize
public 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)
-
parseCommandLine
protected void parseCommandLine(String[] args) throws org.apache.commons.cli.UnrecognizedOptionException, org.apache.commons.cli.ParseException
- Throws:
org.apache.commons.cli.UnrecognizedOptionException
org.apache.commons.cli.ParseException
-
getCommandLine
public org.apache.commons.cli.CommandLine getCommandLine()
-
getOptions
protected boolean getOptions(String[] args) throws Exception
Returns true if execution should continue, false if not. Call this first to see if execution should proceed.- Parameters:
args
-- Returns:
- Throws:
Exception
-
isDebugOn
public boolean isDebugOn()
Description copied from interface:Logable
Query if debugging is enabled for this logger.
-
setDebugOn
public void setDebugOn(boolean setOn)
Description copied from interface:Logable
Enable/disable debugging for this logger- Specified by:
setDebugOn
in interfaceLogable
-
hasOption
protected boolean hasOption(String shortForm, String longForm)
Checks if the long or short form is part of the command line options.- Parameters:
shortForm
-longForm
-- Returns:
-
getOptions
protected org.apache.commons.cli.Options getOptions()
Override this to set up your options. You should also use this to check the action and set it, .e.g.,
Options options = super.getOptions();
options.addOptions(SHORT_FORM, LONG_FORM, ... // This is in the commons documentation
checkAction(SHORT_FORM, LONG_FORM, ACTION_CODE);
- Returns:
-
setMyLogger
public void setMyLogger(MyLoggingFacade myLoggingFacade)
-
getMyLogger
public MyLoggingFacade getMyLogger()
-
debug
public void debug(String x)
Description copied from interface:Logable
Write a debug message to the log.
-
info
public void info(String x)
Description copied from interface:Logable
Write an informational message to the log
-
warn
public void warn(String x)
Description copied from interface:Logable
Write a warning to the log. This indicates a severe, but non-fatal condition exists.
-
error
public void error(String x)
Description copied from interface:Logable
Write an error message to the log. Typically this is invoked as the last command before throwing an exception.
-
getLogfileName
public String getLogfileName()
-
setLogfileName
public void setLogfileName(String logfileName)
-
isVerbose
public boolean isVerbose()
-
setVerbose
public void setVerbose(boolean verbose)
-
padLineWithBlanks
protected String padLineWithBlanks(String x, int width)
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.- Parameters:
x
-width
-- Returns:
-
useHelp
public abstract void useHelp()
-
-