Package edu.uiuc.ncsa.security.util.cli
Class AbstractCommandsImpl
- java.lang.Object
- 
- edu.uiuc.ncsa.security.util.cli.AbstractCommandsImpl
 
- 
- All Implemented Interfaces:
- Logable,- Commands,- Serializable
 - Direct Known Subclasses:
- CommonCommands2,- ConfigurableCommandsImpl2
 
 public abstract class AbstractCommandsImpl extends Object implements Commands Class that collects the startup logic forCommandsimplementations- See Also:
- Serialized Form
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected StringCL_INPUT_FILE_FLAGprotected StringCL_OUTPUT_FILE_FLAGprotected static StringDEFAULT_NULL_VALUE_PLACEHOLDERprotected StringdefaultIndentstatic StringINDENTstatic StringLOGOprotected StringlogoNamestatic StringNO_HEADERstatic StringNO_LOGOprotected booleanshowHeaderprotected booleanshowLogostatic StringSILENT
 - 
Constructor SummaryConstructors Constructor Description AbstractCommandsImpl(CLIDriver driver)
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidabout(boolean showBanner, boolean showHeader)This will show the boot up logos, header (additional info) etc.InputLinebootstrap(InputLine inputLine)Bootstrap this implementation.InputLinebootstrap(String[] args)voidclear_env(InputLine inputLine)protected voidclearEnvHelp()voidconfigureCommands(CLIDriver cli, AbstractCommandsImpl commands)Take (newly created)CommonCommands2and initialize its driver.voiddebug(String x)Write a debug message to the log.voiderror(String x)Write an error message to the log.voiderror(String x, Throwable t)voidget_env(InputLine inputline)CLIDrivergetDriver()Back reference to the driver that manages this instance.HelpUtilgetHelpUtil()protected StringgetInput(String prompt, String defaultValue)Creates the input prompt and shows the supplied default value.IOInterfacegetIOInterface()StringgetLogoName()protected StringgetPropertyHelp(String propertyName, String prompt, String defaultValue)One of the most important help methods, but only used in subclasses.protected booleangracefulExit(boolean exitNow, String msg)Exit gracefully.protected booleanhasLogger()intindentWidth()voidinfo(String x)Write an informational message to the logvoidinitHelp()abstract voidinitialize()Finish initializing this implementation.booleanisDebugOn()Query if debugging is enabled for this logger.protected booleanisOk(String x)Used when reading lines to check is the user typed a "y" for yes.booleanisShowHeader()Show the header, if any, at startup?booleanisShowLogo()Show the logo, if any, at startup?abstract voidload(InputLine inputLine)Load resources before showing logos etc.voidprint_env(InputLine inputLine)protected voidprintEnvHelp()protected voidprintGetEnvHelp()protected voidprintReadEnvHelp()protected voidprintSaveEnvHelp()protected voidprintSetEnvHelp()voidread_env(InputLine inputline)protected net.sf.json.JSONObjectreadJSON(String filename)protected Stringreadline()protected Stringreadline(String prompt)voidsave_env(InputLine inputLine)protected voidsay()Linefeed.protected voidsay(String x)Prints with the default indent and a linefeed.protected voidsayi(String x)prints with the current indent and a linefeed.protected voidsayv(String x)Use this for verbose mode.voidset_env(InputLine inputline)voidsetDebugOn(boolean setOn)Enable/disable debugging for this loggervoidsetDriver(CLIDriver driver)voidsetLogoName(String logoName)voidsetShowHeader(boolean showHeader)voidsetShowLogo(boolean showLogo)protected booleanshowHelp(InputLine inputLine)returns "true if the command has the flag --help in it.voidwarn(String x)Write a warning to the log.
 
- 
- 
- 
Field Detail- 
NO_LOGOpublic static final String NO_LOGO - See Also:
- Constant Field Values
 
 - 
NO_HEADERpublic static final String NO_HEADER - See Also:
- Constant Field Values
 
 - 
SILENTpublic static final String SILENT - See Also:
- Constant Field Values
 
 - 
LOGOpublic static final String LOGO - See Also:
- Constant Field Values
 
 - 
CL_OUTPUT_FILE_FLAGprotected String CL_OUTPUT_FILE_FLAG 
 - 
CL_INPUT_FILE_FLAGprotected String CL_INPUT_FILE_FLAG 
 - 
DEFAULT_NULL_VALUE_PLACEHOLDERprotected static String DEFAULT_NULL_VALUE_PLACEHOLDER 
 - 
showHeaderprotected boolean showHeader 
 - 
showLogoprotected boolean showLogo 
 - 
logoNameprotected String logoName 
 - 
defaultIndentprotected String defaultIndent 
 - 
INDENTpublic static final String INDENT - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
AbstractCommandsImplpublic AbstractCommandsImpl(CLIDriver driver) 
 
- 
 - 
Method Detail- 
showHelpprotected 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:
 
 - 
getPropertyHelpprotected String getPropertyHelp(String propertyName, String prompt, String defaultValue) throws IOException One of the most important help methods, but only used in subclasses.Use this to get a property and also allow for getting help. This is just getInput(String, String)but with the optional lookup of help for the propertyName if the user enters --help or /help. It will then re-prompt for the input.- Parameters:
- propertyName-
- prompt-
- defaultValue-
- Returns:
- Throws:
- IOException
 
 - 
getInputprotected String getInput(String prompt, String defaultValue) throws IOException Creates the input prompt and shows the supplied default value. This returns the default if the default value is chosen and the input value otherwise. If supplied the default value is a null, then this is shown too.- Parameters:
- prompt-
- defaultValue-
- Returns:
- Throws:
- IOException
 
 - 
readlineprotected String readline(String prompt) throws IOException - Throws:
- IOException
 
 - 
readlineprotected String readline() 
 - 
getDriverpublic CLIDriver getDriver() Description copied from interface:CommandsBack reference to the driver that manages this instance.
 - 
bootstrappublic InputLine bootstrap(InputLine inputLine) throws Throwable Bootstrap this implementation. This callsCLIDriver.bootstrap(String[]). The sequence this follows is- call CLIDriver.bootstrap(InputLine)
- Turn off console ouput (loggin unaffected) if not verbose mode
- Call load(InputLine)
- Turn back on output
- Show header with about(boolean, boolean)
- Call initialize()
- Call initHelp()
 
- call 
 - 
isShowHeaderpublic boolean isShowHeader() Show the header, if any, at startup?- Returns:
 
 - 
setShowHeaderpublic void setShowHeader(boolean showHeader) 
 - 
isShowLogopublic boolean isShowLogo() Show the logo, if any, at startup?- Returns:
 
 - 
setShowLogopublic void setShowLogo(boolean showLogo) 
 - 
getLogoNamepublic String getLogoName() 
 - 
setLogoNamepublic void setLogoName(String logoName) 
 - 
aboutpublic abstract void about(boolean showBanner, boolean showHeader)This will show the boot up logos, header (additional info) etc. if any
 - 
initializepublic abstract void initialize() throws ThrowableFinish initializing this implementation.- Throws:
- Throwable
 
 - 
loadpublic abstract void load(InputLine inputLine) throws Throwable Load resources before showing logos etc. This is typically called on your behalf inbootstrap(InputLine)amd should load resources needed. Note that an exception in this does not stop booting. This allows you to start a system with a missing configuration file (for instnace) and prompt for it.
 Seeinitialize()which is called after this and is charged with actually starting- Parameters:
- inputLine-
- Throws:
- Throwable
 
 - 
hasLoggerprotected boolean hasLogger() 
 - 
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
 
 - 
debugpublic void debug(String x) Description copied from interface:LogableWrite a debug message to the log.
 - 
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.
 - 
isOkprotected boolean isOk(String x) Used when reading lines to check is the user typed a "y" for yes.- Parameters:
- x-
- Returns:
 
 - 
getHelpUtilpublic HelpUtil getHelpUtil() 
 - 
printReadEnvHelpprotected void printReadEnvHelp() 
 - 
printSetEnvHelpprotected void printSetEnvHelp() 
 - 
printGetEnvHelpprotected void printGetEnvHelp() 
 - 
printSaveEnvHelpprotected void printSaveEnvHelp() 
 - 
printEnvHelpprotected void printEnvHelp() 
 - 
clearEnvHelpprotected void clearEnvHelp() 
 - 
gracefulExitprotected boolean gracefulExit(boolean exitNow, String msg)Exit gracefully. That is to say, if the exitNow flag is true, do a system shutdown in batch mode and otherwise, do nothing. If the flag is true and the mode is interactive, then print the message and return true, prompting the system to return;- Parameters:
- exitNow-
- msg-
- Returns:
 
 - 
sayprotected void say(String x) Prints with the default indent and a linefeed.- Parameters:
- x-
 
 - 
sayprotected void say() Linefeed.
 - 
sayvprotected void sayv(String x) Use this for verbose mode.- Parameters:
- x-
 
 - 
readJSONprotected net.sf.json.JSONObject readJSON(String filename) throws Throwable - Throws:
- Throwable
 
 - 
sayiprotected void sayi(String x) prints with the current indent and a linefeed.- Parameters:
- x-
 
 - 
indentWidthpublic int indentWidth() 
 - 
getIOInterfacepublic IOInterface getIOInterface() - Specified by:
- getIOInterfacein interface- Commands
 
 - 
configureCommandspublic void configureCommands(CLIDriver cli, AbstractCommandsImpl 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
 
 
- 
 
-