Class Command

  • Direct Known Subclasses:
    VerboseCommand

    public abstract class Command
    extends java.lang.Object
    A class to represent a command to be executed. Commands are typically read from the command line or from command files.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  Command.Fault
      This exception is used to report problems with a specific command.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_DTMODE
      A value to indicate that a command accepts the default desktop mode.
      static int DESKTOP_NOT_REQUIRED_DTMODE
      A value to indicate that a command does not require the use of a desktop to function.
      static int DESKTOP_REQUIRED_DTMODE
      A value to indicate that a command requires the use of a desktop to function.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Command​(java.lang.String name)
      Create an instance of a command.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addArg​(java.lang.String arg)
      Record another argument in the argument array.
      java.lang.String[] getArgs()
      Get the array of arguments for this command.
      protected InterviewParameters getConfig​(CommandContext ctx)
      A convenience method to get the configuration from a command context, and rewrapping any exception that might occur.
      java.net.URL getCustomSplash()
      Get the classpath to load the custom splash screen from.
      int getDesktopMode()
      Get the desktop mode for this command.
      boolean isActionCommand()
      Check whether this command is an action command or not.
      protected java.lang.String nextArg​(java.util.Iterator<java.lang.String> argIter)
      Get another argument from the iterator, and add it to the argument array.
      protected void putbackArg​(java.util.ListIterator<java.lang.String> argIter)
      Back up the iterator to reject an argument, and remove the corresponding entry from the argument array.
      abstract void run​(CommandContext ctx)
      Execute the work embodied by this command, using the given command context.
      java.lang.String toString()
      Get a printable representation of this command.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Command

        protected Command​(java.lang.String name)
        Create an instance of a command.
        Parameters:
        name - The name for this command. The name will be saved as the first entry as the argument array.
    • Method Detail

      • addArg

        protected void addArg​(java.lang.String arg)
        Record another argument in the argument array.
        Parameters:
        arg - the argument to be added
      • nextArg

        protected java.lang.String nextArg​(java.util.Iterator<java.lang.String> argIter)
        Get another argument from the iterator, and add it to the argument array.
        Parameters:
        argIter - the iterator from which to get the next argument
        Returns:
        the next argument from the iterator
      • putbackArg

        protected void putbackArg​(java.util.ListIterator<java.lang.String> argIter)
        Back up the iterator to reject an argument, and remove the corresponding entry from the argument array.
        Parameters:
        argIter - the iterator from which teh argument was obtained
      • getArgs

        public java.lang.String[] getArgs()
        Get the array of arguments for this command. The first element in the array will be the command name; the subsequent arguments will be the ones added by the addArg method.
        Returns:
        the array of arguments for this command
      • toString

        public java.lang.String toString()
        Get a printable representation of this command. The string is composed of the entries in the argument array.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a printable representation of this command
      • getDesktopMode

        public int getDesktopMode()
        Get the desktop mode for this command. Valid responses are one of DEFAULT_DTMODE, DESKTOP_NOT_REQUIRED_DTMODE, DESKTOP_REQUIRED_DTMODE. The default is DESKTOP_NOT_REQUIRED_DTMODE if isActionCommand is true, and DESKTOP_DEFAULT_DTMODE otherwise.
        Returns:
        a value indicating the desktop mode for this command
        See Also:
        DEFAULT_DTMODE, DESKTOP_NOT_REQUIRED_DTMODE, DESKTOP_REQUIRED_DTMODE
      • getCustomSplash

        public java.net.URL getCustomSplash()
        Get the classpath to load the custom splash screen from. At this location, it is expected that a resource bundle prefixed with "splash" will be available. The search strategy given in ResourceBundle will be used, with the returned File as the classpath for the class loader. The limited classpath/classloader is used to make this operation as fast as possible, rather than requiring that the command's entire context be loaded.

        In the resource bundle, there should be a property named startup.icon.

        Returns:
        the location of the splash screen resource bundle
        Since:
        4.0
        See Also:
        ResourceBundle
      • isActionCommand

        public boolean isActionCommand()
        Check whether this command is an action command or not. Action commands are those that do work such as running tests, writing a report, etc. The default implementation is to return false.
        Returns:
        true if this command is an action command, and false otherwise
      • run

        public abstract void run​(CommandContext ctx)
                          throws Command.Fault
        Execute the work embodied by this command, using the given command context.
        Parameters:
        ctx - context information that may be set up by preceding commands.
        Throws:
        Command.Fault - if there is an error while executing this command
      • getConfig

        protected InterviewParameters getConfig​(CommandContext ctx)
                                         throws Command.Fault
        A convenience method to get the configuration from a command context, and rewrapping any exception that might occur.
        Parameters:
        ctx - the command context from which to get the configuration
        Returns:
        the current configuration from the command context
        Throws:
        Command.Fault - if there is a problem obtaining or evaluating the configuration.