Package com.sun.javatest.tool
Class CommandContext
- java.lang.Object
-
- com.sun.javatest.tool.CommandContext
-
public class CommandContext extends java.lang.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
CommandContext.Fault
This exception is used to report problems while executing a command.
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_LAF
Code for setting JavaTest default LookAndFeel.static int
METAL_LAF
Code for setting Metal LookAndFeel.static int
NIMBUS_LAF
Code for setting Nimbus LookAndFeel.static int
SYSTEM_LAF
Code for setting default system LookAndFeel.
-
Constructor Summary
Constructors Constructor Description CommandContext()
Create a new context object.CommandContext(java.io.PrintWriter out)
Create a new context object, using a specified PrintWriter for the output stream, used by the printXXX methods.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addCommand(Command cmd)
Add a new command to the set of commands to be executed by this object.void
addHarnessObserver(Harness.Observer o)
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()
Command
getAutoRunCommand()
Get the "auto run" command registered with this object.java.io.File
getAutoRunReportDir()
Get the "auto run report directory" registered with this object.Command[]
getCommands()
Get the set of commands to be executed by this object.InterviewParameters
getConfig()
Get the configuration associated with this object.Desktop
getDesktop()
Get the desktop associated with this object.Harness.Observer[]
getHarnessObservers()
Get the set of observers that have been registered with this object.InterviewParameters
getInterviewParameters()
Deprecated.Use getConfig().java.io.PrintWriter
getLogWriter()
Get the log stream associated with this object.int
getPreferredLookAndFeel()
int[]
getTestStats()
Get the cumulative test run statistics.TestSuite
getTestSuite()
Get the test suite associated with this object.boolean
getVerboseOptionValue(java.lang.String name)
Get the value of a verbose option.boolean
getVerboseOptionValue(java.lang.String name, boolean defaultValue)
Get the value of a verbose option.WorkDirectory
getWorkDirectory()
Get the work directory associated with this object.boolean
hasConfig()
Check whether a configuration has been set yet.boolean
isCloseDesktopWhenDoneEnabled()
Check whether this object indicates that the desktop should be closed when all commands are done.boolean
isDesktopRequired()
Check if a desktop is required by the commands registered with this object.boolean
isTestSuiteSet()
Check whether the test suite has been set yet.boolean
isVerboseOptionSet(java.lang.String name)
Check if a verbose option has been set explicitly with setVerboseOptionValue.boolean
isVerboseQuiet()
Should all verbose output be quieted.boolean
isVerboseTimestampEnabled()
Check whether timestamps should be printed with verbose output.boolean
isWorkDirectorySet()
Check whether the work directory has been set yet.void
printErrorMessage(I18NResourceBundle i18n, java.lang.String key)
Write an error message to the log stream associated with this object.void
printErrorMessage(I18NResourceBundle i18n, java.lang.String key, java.lang.Object arg)
Write an error message to the log stream associated with this object.void
printErrorMessage(I18NResourceBundle i18n, java.lang.String key, java.lang.Object[] args)
Write an error message to the log stream associated with this object.void
printMessage(I18NResourceBundle i18n, java.lang.String key)
Write a message to the log stream associated with this object.void
printMessage(I18NResourceBundle i18n, java.lang.String key, java.lang.Object arg)
Write a message to the log stream associated with this object.void
printMessage(I18NResourceBundle i18n, java.lang.String key, java.lang.Object[] args)
Write a message to the log stream associated with this object.void
runCommands()
Run the set of commands that have been registered with this object.void
setAutoRunCommand(Command c)
Set the "auto run" command registered with this object.void
setAutoRunReportDir(java.io.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
setConfig(java.io.File path)
Set the path for the configuration information to be associated with this object.void
setDesktop(Desktop d)
Set the desktop associated with this object.void
setInterviewParameters(InterviewParameters p)
Deprecated.Use setConfig().void
setLogWriter(java.io.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
setTestSuite(TestSuite ts)
Set the test suite to be associated with this object.void
setTestSuite(java.io.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(java.lang.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
setWorkDirectory(WorkDirectory wd)
Set the work directory to be associated with this object.void
setWorkDirectory(java.io.File path)
Set the path for the work directory to be associated with this object.void
setWorkDirectory(java.io.File path, boolean create)
Set the path for the work directory to be associated with this object.
-
-
-
Field Detail
-
SYSTEM_LAF
public static final int SYSTEM_LAF
Code for setting default system LookAndFeel. Should be set before Desktop is created.
-
NIMBUS_LAF
public static final int NIMBUS_LAF
Code for setting Nimbus LookAndFeel. Should be set before Desktop is created.
-
METAL_LAF
public static final int METAL_LAF
Code for setting Metal LookAndFeel. Should be set before Desktop is created.
-
DEFAULT_LAF
public static final int DEFAULT_LAF
Code for setting JavaTest default LookAndFeel. Currently - Nimbus LookAndFeel is default. Should be set before Desktop is created.
-
-
Constructor Detail
-
CommandContext
public CommandContext()
Create a new context object. The output stream, used by the printXXX methods, is set to System.err.
-
CommandContext
public CommandContext(java.io.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 Detail
-
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:
runCommands()
-
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:
addCommand(com.sun.javatest.tool.Command)
,runCommands()
-
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()
-
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:
addHarnessObserver(com.sun.javatest.Harness.Observer)
-
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(com.sun.javatest.tool.Command)
,runCommands()
-
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:
getAutoRunCommand()
,runCommands()
-
getAutoRunReportDir
public java.io.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(java.io.File)
-
setAutoRunReportDir
public void setAutoRunReportDir(java.io.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:
getAutoRunReportDir()
-
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(boolean)
-
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:
isCloseDesktopWhenDoneEnabled()
-
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(java.io.File)
-
setTestSuite
public void setTestSuite(java.io.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:
getTestSuite()
-
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:
getTestSuite()
-
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(java.io.File)
-
setWorkDirectory
public void setWorkDirectory(java.io.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:
getWorkDirectory()
-
setWorkDirectory
public void setWorkDirectory(java.io.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 objectcreate
- create the work directory if it does not already exist- Throws:
CommandContext.Fault
- if the work directory has already been set- See Also:
getWorkDirectory()
-
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:
getWorkDirectory()
-
getInterviewParameters
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:
getConfig()
,setInterviewParameters(com.sun.javatest.InterviewParameters)
-
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(java.io.File)
-
hasConfig
public boolean hasConfig()
Check whether a configuration has been set yet.- Returns:
- true if a configuration has been set, and false otherwise
-
setConfig
public void setConfig(java.io.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:
getConfig()
-
setInterviewParameters
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:
setConfig(java.io.File)
,getInterviewParameters()
-
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
-
setDesktop
public void setDesktop(Desktop d)
Set the desktop associated with this object.- Parameters:
d
- the desktop to be associated with this object- Throws:
java.lang.NullPointerException
- if the argument is null- See Also:
getDesktop()
-
getDesktop
public Desktop getDesktop()
Get the desktop associated with this object.- Returns:
- the desktop associated with this object
- See Also:
setDesktop(com.sun.javatest.tool.Desktop)
-
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.
-
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.
-
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.
-
setVerboseTimestampEnabled
public void setVerboseTimestampEnabled(boolean on)
Configure whether timestamps are printed with verbose output.- Parameters:
on
- False for no timestamps.
-
setVerboseOptionValue
public void setVerboseOptionValue(java.lang.String name, boolean on)
Specify the value of a verbose option.- Parameters:
name
- the name of the verbose optionon
- the value of the verbose option- See Also:
getVerboseOptionValue(java.lang.String)
-
getVerboseOptionValue
public boolean getVerboseOptionValue(java.lang.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:
setVerboseOptionValue(java.lang.String, boolean)
-
getVerboseOptionValue
public boolean getVerboseOptionValue(java.lang.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 optiondefaultValue
- the default value to be used if necessary- Returns:
- the value of the named option
- See Also:
setVerboseOptionValue(java.lang.String, boolean)
-
isVerboseOptionSet
public boolean isVerboseOptionSet(java.lang.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(boolean)
-
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:
getPreferredLookAndFeel()
,DEFAULT_LAF
,METAL_LAF
,NIMBUS_LAF
,SYSTEM_LAF
-
getPreferredLookAndFeel
public int getPreferredLookAndFeel()
- Returns:
- preferred LookAndFeel (nimbus by default)
- See Also:
setPreferredLookAndFeel(int)
,DEFAULT_LAF
,METAL_LAF
,NIMBUS_LAF
,SYSTEM_LAF
-
setLogWriter
public void setLogWriter(java.io.PrintWriter out)
Set the log stream associated with this object.- Parameters:
out
- the log stream to be associated with this object- See Also:
getLogWriter()
-
getLogWriter
public java.io.PrintWriter getLogWriter()
Get the log stream associated with this object.- Returns:
- the log stream associated with this object
- See Also:
setLogWriter(java.io.PrintWriter)
-
printMessage
public void printMessage(I18NResourceBundle i18n, java.lang.String key)
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:
setLogWriter(java.io.PrintWriter)
-
printMessage
public void printMessage(I18NResourceBundle i18n, java.lang.String key, java.lang.Object arg)
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:
setLogWriter(java.io.PrintWriter)
-
printMessage
public void printMessage(I18NResourceBundle i18n, java.lang.String key, java.lang.Object[] args)
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:
setLogWriter(java.io.PrintWriter)
-
printErrorMessage
public void printErrorMessage(I18NResourceBundle i18n, java.lang.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 messagekey
- the key for the required message in the bundle- See Also:
setLogWriter(java.io.PrintWriter)
-
printErrorMessage
public void printErrorMessage(I18NResourceBundle i18n, java.lang.String key, java.lang.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 messagekey
- the key for the required message in the bundlearg
- an argument to be formatted into the localized message- See Also:
setLogWriter(java.io.PrintWriter)
-
printErrorMessage
public void printErrorMessage(I18NResourceBundle i18n, java.lang.String key, java.lang.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 messagekey
- the key for the required message in the bundleargs
- an array of arguments to be formatted into the localized message- See Also:
setLogWriter(java.io.PrintWriter)
-
dispose
public void dispose()
-
-