Class 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 actual Commands implementations that do everything.

    Created by Jeff Gaynor
    on 5/20/13 at 11:35 AM

    • 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:
      • 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
      • showLoadHelp

        protected void showLoadHelp()
      • getComponentName

        public abstract String getComponentName()
        For the configuration. This is the tag name (e.g. "client" or "server") in the XML file.
        Returns:
      • readEnv

        protected void readEnv​(String path,
                               boolean verbose)
      • 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.
      • 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.
        Specified by:
        isDebugOn in interface Logable
        Returns:
      • setDebugOn

        public void setDebugOn​(boolean setOn)
        Description copied from interface: Logable
        Enable/disable debugging for this logger
        Specified by:
        setDebugOn in interface Logable
      • 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)
      • debug

        public void debug​(String x)
        Description copied from interface: Logable
        Write a debug message to the log.
        Specified by:
        debug in interface Logable
      • info

        public void info​(String x)
        Description copied from interface: Logable
        Write an informational message to the log
        Specified by:
        info in interface Logable
      • 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.
        Specified by:
        warn in interface Logable
      • 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.
        Specified by:
        error in interface Logable
      • 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()