Class CommandContext

java.lang.Object
com.sun.javatest.tool.CommandContext

public class CommandContext extends Object
An object to carry the shared state required and derived from executing a series of commands.

While the object does provide some behavior, as detailed below, much of its functionality is to provide a repository for values to be passed from one command to another.

See Also:
  • Field Details

  • Constructor Details

    • CommandContext

      public CommandContext()
      Create a new context object. The output stream, used by the printXXX methods, is set to System.err.
    • CommandContext

      public CommandContext(PrintWriter out)
      Create a new context object, using a specified PrintWriter for the output stream, used by the printXXX methods.
      Parameters:
      out - the output stream to be used by the printXXX methods.
  • Method Details

    • addCommand

      public void addCommand(Command cmd)
      Add a new command to the set of commands to be executed by this object.
      Parameters:
      cmd - The command to be added
      See Also:
    • getCommands

      public Command[] getCommands()
      Get the set of commands to be executed by this object.
      Returns:
      the set of commands to be executed by this object
      See Also:
    • runCommands

      public void runCommands() throws CommandContext.Fault
      Run the set of commands that have been registered with this object. If none of the commands executed are action commands, and if an "auto-run" command has been registered, it will be executed after all the other commands have been executed.
      Throws:
      CommandContext.Fault - if any of the commands executed throw Command.Fault
    • addHarnessObserver

      public void addHarnessObserver(Harness.Observer o)
      Add an observer to the set of observers maintained by this object.
      Parameters:
      o - the observer to be added
      See Also:
    • getHarnessObservers

      public Harness.Observer[] getHarnessObservers()
      Get the set of observers that have been registered with this object.
      Returns:
      the set of observers that have been registered with this object
      See Also:
    • getAutoRunCommand

      public Command getAutoRunCommand()
      Get the "auto run" command registered with this object. If not null, this command will be executed after the other commands executed by this object, and if none of those commands are action commands.
      Returns:
      the "auto run" command registered with this object
      See Also:
    • setAutoRunCommand

      public void setAutoRunCommand(Command c)
      Set the "auto run" command registered with this object. If not null, this command will be executed after the other commands executed by this object, and if none of those commands are action commands.
      Parameters:
      c - the "auto run" command to be registered with this object
      See Also:
    • getAutoRunReportDir

      public File getAutoRunReportDir()
      Get the "auto run report directory" registered with this object. This is primarily to support backwards compatibility with JT Harness 2.x behavior.
      Returns:
      the "auto run report directory" registered with this object
      See Also:
    • setAutoRunReportDir

      public void setAutoRunReportDir(File dir)
      Set the "auto run report directory" registered with this object. This is primarily to support backwards compatibility with JT Harness 2.x behavior.
      Parameters:
      dir - the "auto run report directory" to be registered with this object
      See Also:
    • addTestStats

      public void addTestStats(int... stats)
      Add test run statistics into the cumulative counts.
      Parameters:
      stats - an array of test counts, indexed by the standard Status.XXX values.
    • getTestStats

      public int[] getTestStats()
      Get the cumulative test run statistics.
      Returns:
      an array of test counts, indexed by the standard Status.XXX values.
    • isCloseDesktopWhenDoneEnabled

      public boolean isCloseDesktopWhenDoneEnabled()
      Check whether this object indicates that the desktop should be closed when all commands are done.
      Returns:
      true if this object indicates that the desktop should be closed when all commands are done, and false otherwise
      See Also:
    • setCloseDesktopWhenDoneEnabled

      public void setCloseDesktopWhenDoneEnabled(boolean b)
      Specify whether this object should remember that the desktop should be closed when all commands are done.
      Parameters:
      b - true if this object should remember that the desktop should be closed when all commands are done, and false otherwise
      See Also:
    • isTestSuiteSet

      public boolean isTestSuiteSet()
      Check whether the test suite has been set yet.
      Returns:
      true if the test suite has been set, and false otherwise
    • getTestSuite

      public TestSuite getTestSuite() throws CommandContext.Fault
      Get the test suite associated with this object.
      Returns:
      the test suite associated with this object
      Throws:
      CommandContext.Fault - if there is a problem determining the test suite from the available parameters
      See Also:
    • setTestSuite

      public void setTestSuite(File path) throws CommandContext.Fault
      Set the path for the test suite to be associated with this object. The path will not be verified until required, so that it can be evaluated in conjunction with other parameters such as the work directory and configuration file.
      Parameters:
      path - the path for the test suite to be associated with this object
      Throws:
      CommandContext.Fault - if the test suite has already ben set
      See Also:
    • setTestSuite

      public void setTestSuite(TestSuite ts) throws CommandContext.Fault, TestSuite.Fault
      Set the test suite to be associated with this object.
      Parameters:
      ts - the test suite to be associated with this object
      Throws:
      CommandContext.Fault - if the test suite has already been set to something else, or if there is a problem evaluating related parameters, such as a configuration file or template, or a work directory.
      TestSuite.Fault - if there is a problem evaluating related parameters.
      See Also:
    • isWorkDirectorySet

      public boolean isWorkDirectorySet()
      Check whether the work directory has been set yet.
      Returns:
      true if the work directory has been set, and false otherwise
    • getWorkDirectory

      public WorkDirectory getWorkDirectory() throws CommandContext.Fault
      Get the work directory associated with this object.
      Returns:
      the work directory associated with this object, or null if not yet set
      Throws:
      CommandContext.Fault - if there is a problem determining the work directory from the available parameters
      See Also:
    • setWorkDirectory

      public void setWorkDirectory(File path) throws CommandContext.Fault
      Set the path for the work directory to be associated with this object. The path will not be verified until required, so that it can be evaluated in conjunction with other parameters such as the test suite and configuration file. The path must identify a work directory that already exists.
      Parameters:
      path - the path for the work directory to be associated with this object
      Throws:
      CommandContext.Fault - if the work directory has already been set
      See Also:
    • setWorkDirectory

      public void setWorkDirectory(WorkDirectory wd) throws CommandContext.Fault, TestSuite.Fault
      Set the work directory to be associated with this object.
      Parameters:
      wd - the work directory to be associated with this object
      Throws:
      CommandContext.Fault - if there is a problem evaluating related parameters, such as a configuration file or template, or a test suite.
      TestSuite.Fault - if there is a problem evaluating related parameters.
      CommandContext.Fault - if the work directory has already been set to something else
      See Also:
    • setWorkDirectory

      public void setWorkDirectory(File path, boolean create) throws CommandContext.Fault
      Set the path for the work directory to be associated with this object. The path will not be verified until required, so that it can be evaluated in conjunction with other parameters such as the test suite and configuration file. The work directory identified by this path may be created if necessary.
      Parameters:
      path - the path for the work directory to be associated with this object
      create - create the work directory if it does not already exist
      Throws:
      CommandContext.Fault - if the work directory has already been set
      See Also:
    • getInterviewParameters

      @Deprecated public InterviewParameters getInterviewParameters() throws CommandContext.Fault
      Deprecated.
      Use getConfig().
      Get the configuration associated with this object.
      Returns:
      the configuration associated with this object
      Throws:
      CommandContext.Fault - if there is a problem evaluating the parameters that define the configuration
      See Also:
    • setInterviewParameters

      @Deprecated public void setInterviewParameters(InterviewParameters p) throws CommandContext.Fault
      Deprecated.
      Use setConfig().
      Set the configuration associated with this object.
      Parameters:
      p - the configuration to be associated with this object
      Throws:
      CommandContext.Fault - if the configuration is incompatible with other parameters that have previously been set up, such as the test suite and work directory.
      See Also:
    • getConfig

      public InterviewParameters getConfig() throws CommandContext.Fault
      Get the configuration associated with this object.
      Returns:
      the configuration associated with this object
      Throws:
      CommandContext.Fault - if there is a problem evaluating the parameters that define the configuration
      See Also:
    • setConfig

      public void setConfig(File path) throws CommandContext.Fault
      Set the path for the configuration information to be associated with this object. The path will not be verified until required, so that it can be evaluated in conjunction with other parameters such as the test suite and work directory.
      Parameters:
      path - the path for the configuration information to be associated with this object.
      Throws:
      CommandContext.Fault - if the configuration has already been evaluated
      See Also:
    • hasConfig

      public boolean hasConfig()
      Check whether a configuration has been set yet.
      Returns:
      true if a configuration has been set, and false otherwise
    • isDesktopRequired

      public boolean isDesktopRequired()
      Check if a desktop is required by the commands registered with this object. A desktop is not required if and only if one or more commands have a desktop mode of "desktop not required", and none have a mode of "desktop required". In other words, "desktop not required" wins over "default", but "desktop required" wins over "desktop not required".
      Returns:
      whether or not a desktop is required by the commands registered with this object
    • getDesktop

      public Desktop getDesktop()
      Get the desktop associated with this object.
      Returns:
      the desktop associated with this object
      See Also:
    • setDesktop

      public void setDesktop(Desktop d)
      Set the desktop associated with this object.
      Parameters:
      d - the desktop to be associated with this object
      Throws:
      NullPointerException - if the argument is null
      See Also:
    • setVerboseMax

      public void setVerboseMax(boolean on)
      Specify whether or not to override the setting of all other verbose options to true.
      Parameters:
      on - If true, the value of all other verbose options will be given as true.
    • isVerboseQuiet

      public boolean isVerboseQuiet()
      Should all verbose output be quieted. This generally overrides any other requests for verbosity.
      Returns:
      True if verboseness should be quieted.
    • setVerboseQuiet

      public void setVerboseQuiet(boolean on)
      Specify whether or not to override the setting of all other verbose options to false.
      Parameters:
      on - If true, the value of all other verbose options will be given as false.
    • setVerboseOptionValue

      public void setVerboseOptionValue(String name, boolean on)
      Specify the value of a verbose option.
      Parameters:
      name - the name of the verbose option
      on - the value of the verbose option
      See Also:
    • getVerboseOptionValue

      public boolean getVerboseOptionValue(String name)
      Get the value of a verbose option. If the max verbose flag has been set to true, the result will be true. Otherwise, if the quiet verbose flag, the result will be false. Otherwise, if the value has been set with setVerboseOptionValue, the result will be the value that was set Otherwise the result will be false.
      Parameters:
      name - the name of the verbose option
      Returns:
      the value of the named option
      See Also:
    • getVerboseOptionValue

      public boolean getVerboseOptionValue(String name, boolean defaultValue)
      Get the value of a verbose option. If the max verbose flag has been set to true, the result will be true. Otherwise, if the quiet verbose flag, the result will be false. Otherwise, if the value has been set with setVerboseOptionValue, the result will be the value that was set Otherwise the result will be specified default value.
      Parameters:
      name - the name of the verbose option
      defaultValue - the default value to be used if necessary
      Returns:
      the value of the named option
      See Also:
    • isVerboseOptionSet

      public boolean isVerboseOptionSet(String name)
      Check if a verbose option has been set explicitly with setVerboseOptionValue.
      Parameters:
      name - the name of the option to be checked
      Returns:
      true if the option has a value that has been explicitly set, and false otherwise
    • isVerboseTimestampEnabled

      public boolean isVerboseTimestampEnabled()
      Check whether timestamps should be printed with verbose output.
      Returns:
      False for no timestamps.
      See Also:
    • setVerboseTimestampEnabled

      public void setVerboseTimestampEnabled(boolean on)
      Configure whether timestamps are printed with verbose output.
      Parameters:
      on - False for no timestamps.
    • getPreferredLookAndFeel

      public int getPreferredLookAndFeel()
      Returns:
      preferred LookAndFeel (nimbus by default)
      See Also:
    • setPreferredLookAndFeel

      public void setPreferredLookAndFeel(int lookAndFeel)
      Sets preferred LookAndFeel that is used on Desktop creation (should be set before creation)
      Parameters:
      lookAndFeel - LookAndFeel code to be set
      See Also:
    • getLogWriter

      public PrintWriter getLogWriter()
      Get the log stream associated with this object.
      Returns:
      the log stream associated with this object
      See Also:
    • setLogWriter

      public void setLogWriter(PrintWriter out)
      Set the log stream associated with this object.
      Parameters:
      out - the log stream to be associated with this object
      See Also:
    • printMessage

      public void printMessage(I18NResourceBundle i18n, String key)
      Write a message to the log stream associated with this object.
      Parameters:
      i18n - the resource bundle containing the localized text of the message
      key - the key for the required message in the bundle
      See Also:
    • printMessage

      public void printMessage(I18NResourceBundle i18n, String key, Object arg)
      Write a message to the log stream associated with this object.
      Parameters:
      i18n - the resource bundle containing the localized text of the message
      key - the key for the required message in the bundle
      arg - an argument to be formatted into the localized message
      See Also:
    • printMessage

      public void printMessage(I18NResourceBundle i18n, String key, Object... args)
      Write a message to the log stream associated with this object.
      Parameters:
      i18n - the resource bundle containing the localized text of the message
      key - the key for the required message in the bundle
      args - an array of arguments to be formatted into the localized message
      See Also:
    • printErrorMessage

      public void printErrorMessage(I18NResourceBundle i18n, String key)
      Write an error message to the log stream associated with this object.
      Parameters:
      i18n - the resource bundle containing the localized text of the message
      key - the key for the required message in the bundle
      See Also:
    • printErrorMessage

      public void printErrorMessage(I18NResourceBundle i18n, String key, Object arg)
      Write an error message to the log stream associated with this object.
      Parameters:
      i18n - the resource bundle containing the localized text of the message
      key - the key for the required message in the bundle
      arg - an argument to be formatted into the localized message
      See Also:
    • printErrorMessage

      public void printErrorMessage(I18NResourceBundle i18n, String key, Object... args)
      Write an error message to the log stream associated with this object.
      Parameters:
      i18n - the resource bundle containing the localized text of the message
      key - the key for the required message in the bundle
      args - an array of arguments to be formatted into the localized message
      See Also:
    • dispose

      public void dispose()