Package com.sun.javatest.tool
Class CommandContext
java.lang.Object
com.sun.javatest.tool.CommandContext
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
This exception is used to report problems while executing a command. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Code for setting JavaTest default LookAndFeel.static final int
Code for setting Metal LookAndFeel.static final int
Code for setting Nimbus LookAndFeel.static final int
Code for setting default system LookAndFeel. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new context object.Create a new context object, using a specified PrintWriter for the output stream, used by the printXXX methods. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCommand
(Command cmd) Add a new command to the set of commands to be executed by this object.void
Add an observer to the set of observers maintained by this object.void
addTestStats
(int... stats) Add test run statistics into the cumulative counts.void
dispose()
Get the "auto run" command registered with this object.Get the "auto run report directory" registered with this object.Command[]
Get the set of commands to be executed by this object.Get the configuration associated with this object.Get the desktop associated with this object.Get the set of observers that have been registered with this object.Deprecated.Use getConfig().Get the log stream associated with this object.int
int[]
Get the cumulative test run statistics.Get the test suite associated with this object.boolean
getVerboseOptionValue
(String name) Get the value of a verbose option.boolean
getVerboseOptionValue
(String name, boolean defaultValue) Get the value of a verbose option.Get the work directory associated with this object.boolean
Check whether a configuration has been set yet.boolean
Check whether this object indicates that the desktop should be closed when all commands are done.boolean
Check if a desktop is required by the commands registered with this object.boolean
Check whether the test suite has been set yet.boolean
isVerboseOptionSet
(String name) Check if a verbose option has been set explicitly with setVerboseOptionValue.boolean
Should all verbose output be quieted.boolean
Check whether timestamps should be printed with verbose output.boolean
Check whether the work directory has been set yet.void
printErrorMessage
(I18NResourceBundle i18n, String key) Write an error message to the log stream associated with this object.void
printErrorMessage
(I18NResourceBundle i18n, String key, Object arg) Write an error message to the log stream associated with this object.void
printErrorMessage
(I18NResourceBundle i18n, String key, Object... args) Write an error message to the log stream associated with this object.void
printMessage
(I18NResourceBundle i18n, String key) Write a message to the log stream associated with this object.void
printMessage
(I18NResourceBundle i18n, String key, Object arg) Write a message to the log stream associated with this object.void
printMessage
(I18NResourceBundle i18n, String key, Object... args) Write a message to the log stream associated with this object.void
Run the set of commands that have been registered with this object.void
Set the "auto run" command registered with this object.void
setAutoRunReportDir
(File dir) Set the "auto run report directory" registered with this object.void
setCloseDesktopWhenDoneEnabled
(boolean b) Specify whether this object should remember that the desktop should be closed when all commands are done.void
Set the path for the configuration information to be associated with this object.void
Set the desktop associated with this object.void
Deprecated.Use setConfig().void
setLogWriter
(PrintWriter out) Set the log stream associated with this object.void
setPreferredLookAndFeel
(int lookAndFeel) Sets preferred LookAndFeel that is used on Desktop creation (should be set before creation)void
Set the test suite to be associated with this object.void
setTestSuite
(File path) Set the path for the test suite to be associated with this object.void
setVerboseMax
(boolean on) Specify whether or not to override the setting of all other verbose options to true.void
setVerboseOptionValue
(String name, boolean on) Specify the value of a verbose option.void
setVerboseQuiet
(boolean on) Specify whether or not to override the setting of all other verbose options to false.void
setVerboseTimestampEnabled
(boolean on) Configure whether timestamps are printed with verbose output.void
Set the work directory to be associated with this object.void
setWorkDirectory
(File path) Set the path for the work directory to be associated with this object.void
setWorkDirectory
(File path, boolean create) Set the path for the work directory to be associated with this object.
-
Field Details
-
SYSTEM_LAF
public static final int SYSTEM_LAFCode for setting default system LookAndFeel. Should be set before Desktop is created.- See Also:
-
NIMBUS_LAF
public static final int NIMBUS_LAFCode for setting Nimbus LookAndFeel. Should be set before Desktop is created.- See Also:
-
METAL_LAF
public static final int METAL_LAFCode for setting Metal LookAndFeel. Should be set before Desktop is created.- See Also:
-
DEFAULT_LAF
public static final int DEFAULT_LAFCode for setting JavaTest default LookAndFeel. Currently - Nimbus LookAndFeel is default. Should be set before Desktop is created.- See Also:
-
-
Constructor Details
-
CommandContext
public CommandContext()Create a new context object. The output stream, used by the printXXX methods, is set to System.err. -
CommandContext
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
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
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
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
Add an observer to the set of observers maintained by this object.- Parameters:
o
- the observer to be added- See Also:
-
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
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
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
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
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
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
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
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
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
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
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
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 objectcreate
- 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.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.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
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
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
Get the desktop associated with this object.- Returns:
- the desktop associated with this object
- See Also:
-
setDesktop
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
Specify the value of a verbose option.- Parameters:
name
- the name of the verbose optionon
- the value of the verbose option- See Also:
-
getVerboseOptionValue
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
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 optiondefaultValue
- the default value to be used if necessary- Returns:
- the value of the named option
- See Also:
-
isVerboseOptionSet
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
Get the log stream associated with this object.- Returns:
- the log stream associated with this object
- See Also:
-
setLogWriter
Set the log stream associated with this object.- Parameters:
out
- the log stream to be associated with this object- See Also:
-
printMessage
Write a message to the log stream associated with this object.- Parameters:
i18n
- the resource bundle containing the localized text of the messagekey
- the key for the required message in the bundle- See Also:
-
printMessage
Write a message to the log stream associated with this object.- Parameters:
i18n
- the resource bundle containing the localized text of the messagekey
- the key for the required message in the bundlearg
- an argument to be formatted into the localized message- See Also:
-
printMessage
Write a message to the log stream associated with this object.- Parameters:
i18n
- the resource bundle containing the localized text of the messagekey
- the key for the required message in the bundleargs
- an array of arguments to be formatted into the localized message- See Also:
-
printErrorMessage
Write an error message to the log stream associated with this object.- Parameters:
i18n
- the resource bundle containing the localized text of the messagekey
- the key for the required message in the bundle- See Also:
-
printErrorMessage
Write an error message to the log stream associated with this object.- Parameters:
i18n
- the resource bundle containing the localized text of the messagekey
- the key for the required message in the bundlearg
- an argument to be formatted into the localized message- See Also:
-
printErrorMessage
Write an error message to the log stream associated with this object.- Parameters:
i18n
- the resource bundle containing the localized text of the messagekey
- the key for the required message in the bundleargs
- an array of arguments to be formatted into the localized message- See Also:
-
dispose
public void dispose()
-