T-Plan Robot Enterprise 3.5.1
Build No. 3.5.1-20140411.1

com.tplan.robot.scripting.commands.impl
Class ExecCommand

java.lang.Object
  extended by com.tplan.robot.scripting.commands.AbstractCommandHandler
      extended by com.tplan.robot.scripting.commands.impl.ExecCommand
All Implemented Interfaces:
GUIConstants, Plugin, Configurable, AdvancedCommandHandler, CommandHandler, EditorFriendlyCommandHandler

public class ExecCommand
extends AbstractCommandHandler
implements AdvancedCommandHandler, EditorFriendlyCommandHandler

Handler implementing functionality of the Exec command.


T-Plan Robot Enterprise, (C) 2009-2014 T-Plan Limited. All rights reserved.


Field Summary
static String PARAM_COMMAND
           
static String PARAM_NOWAIT
           
static String PARAM_OUTPUT_STREAM
           
 
Fields inherited from class com.tplan.robot.scripting.commands.AbstractCommandHandler
ALT, CONTEXT_COMMAND_CALL_COMPILED_PARAMETER_MAP, CONTEXT_COMMAND_CALL_SOURCE_PARAMETER_MAP, CONTEXT_COMPILE_SINGLE_COMMAND_MODE, CONTEXT_LAST_WAIT_FACTOR, CONTEXT_WAIT_FACTOR_ERR_MSG_SHOWN, CTRL, PARAM_COUNT, PARAM_ONFAIL, PARAM_ONPASS, PARAM_WAIT, SHIFT, WINDOWS
 
Fields inherited from interface com.tplan.robot.scripting.commands.EditorFriendlyCommandHandler
CATEGORY_ADMIN, CATEGORY_DESKTOP, CATEGORY_IMAGE_OPS, CATEGORY_IO, CATEGORY_REPORTING, CATEGORY_UNKNOWN
 
Fields inherited from interface com.tplan.robot.gui.GUIConstants
DEFAULT_TPLAN_ROBOT_FILE_EXTENSION, EVENT_ADD_CUSTOM_ACTION_MSG, EVENT_ADD_STABLE_ACTION_MSG, EVENT_DISPLAY_HASHTABLE, EVENT_DISPLAY_PREFERENCES, EVENT_DOCUMENT_CHANGED, EVENT_MOUSE_MOVED, EVENT_REMOVE_CUSTOM_ACTION_MSG, EVENT_REMOVE_STABLE_ACTION_MSG, EVENT_SELECTION_CHANGED, EVENT_STATUSBAR_MSG, HELP_URL_JAPI, HELP_URL_SPEC, HELP_URLS
 
Constructor Summary
ExecCommand()
           
 
Method Summary
 boolean canRunWithoutConnection()
          This method should return true if it can be executed even when the tool is not connected to a desktop.
 void checkVisualParameters(Map<String,CharSequence> parameters, TestScriptInterpret interpret)
          Check (compile) the map of parameters retrieved through the command editor window before they are used to build and/or update the command or Java method call.
 int execute(List args, Map values, ScriptingContext context)
          Execute the command.
 List getArguments(String command, ScriptingContext context)
          Get the list of supported arguments.
 int getCategory(StringBuilder customCategoryDescription)
          Get the category the command falls to.
 String[] getCommandNames()
          Get command names.
 String getContextArgument()
          Implementation of the getContextArgument() method.
 Map getContextAttributes()
          Get a map with context attributes.
 KeyStroke getContextShortcut()
          Get preferred hot key for the GUI command wizard.
 List getParameters(String command, ScriptingContext context)
          Get the list of supported parameters.
 List getParameterValues(String paramName, String command, ScriptingContext context)
          Get values of a particular parameter.
 String getShortDescription(Map<String,String> parameters, TestScriptInterpret interpret)
          Get short description (up to 50 chars) of what the command does.
 List getStablePopupMenuItems()
          Get a list of stable actions.
 List<Preference> getVisualParameters(LinkedHashMap<String,Object> parameters, TestScriptInterpret interpret)
          Get the list of visual parameters for construction of a dynamic command editor window.
 boolean hasCustomParameterComponent(LinkedHashMap<String,Object> parameters, TestScriptInterpret interpret, PreferencePanel[] panel)
          Specify whether the command provides a custom preference panel.
 boolean hasCustomPropertyDialog(LinkedHashMap<String,Object> parameters, TestScriptInterpret interpret, int offset, Action[] action)
          Specify whether the command provides a custom editor.
 boolean hasFixedArgument(List<String> arguments)
          Defines whether the command uses a fixed argument (one-of-a-list).
 void validate(List args, Map values, Map variableContainer, ScriptingContext repository)
          Validate if the command complies with the command syntax.The command is already pre-parsed to a list of parameter names and a map of [name, value] pairs.
 
Methods inherited from class com.tplan.robot.scripting.commands.AbstractCommandHandler
addCommandListener, checkDependencies, checkPauseAndStop, compileParameters, createConfigureAction, executeFallBackCodeOrProcedure, fireCommandEvent, getBooleanSafely, getCode, getDate, getDescription, getDisplayName, getImplementedInterface, getIntegerSafely, getLowestSupportedVersion, getMessageAfterInstall, getMessageBeforeInstall, getPreferences, getSupportContact, getUniqueId, getVendorHomePage, getVendorName, getVersion, isGlobalPrerequisity, multiplyWaitTime, reloadCommand, removeCommandListener, requiresOriginalValues, requiresRestart, setConfiguration, toLinkedMap, validateOnPassAndOnFail, wait
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.tplan.robot.scripting.commands.CommandHandler
addCommandListener, isGlobalPrerequisity, removeCommandListener
 

Field Detail

PARAM_COMMAND

public static final String PARAM_COMMAND
See Also:
Constant Field Values

PARAM_OUTPUT_STREAM

public static final String PARAM_OUTPUT_STREAM
See Also:
Constant Field Values

PARAM_NOWAIT

public static final String PARAM_NOWAIT
See Also:
Constant Field Values
Constructor Detail

ExecCommand

public ExecCommand()
Method Detail

getContextShortcut

public KeyStroke getContextShortcut()
Description copied from interface: CommandHandler
Get preferred hot key for the GUI command wizard. When such a key is pressed in the editor, the GUI inserts the command template into the editor document. The key returned by this method is just a recommendation and the GUI may decide to assign another one to the command, for example when there is a conflict with another existing one.

Specified by:
getContextShortcut in interface CommandHandler
Overrides:
getContextShortcut in class AbstractCommandHandler
Returns:
hot key invoking insertion of a command template into the GUI editor..

getContextAttributes

public Map getContextAttributes()
Get a map with context attributes.

Specified by:
getContextAttributes in interface CommandHandler
Overrides:
getContextAttributes in class AbstractCommandHandler
Returns:
A hash table containing complete list of supported parameters and their descriptions or list of values.

getContextArgument

public String getContextArgument()
Implementation of the getContextArgument() method. It is necessary as this command has a mandatory argument, which is a numeric exit code.

Specified by:
getContextArgument in interface CommandHandler
Overrides:
getContextArgument in class AbstractCommandHandler
Returns:
description of the mandatory argument.

getCommandNames

public String[] getCommandNames()
Description copied from interface: CommandHandler

Get command names. A command name is the first word in a script line, e.g. "Type" or "Press". Though most commands have just one name, you may use this method to define any number of command aliases. You may even use one class to implement more commands if you want. In such a case you need to define more command names and implement a different behavior for each command.

Please note that command name parsing is NOT case sensitive. You don't have to define the names as e.g. { "MyCommand", "mycommand" }. Script parser will always parse the command name in a script and convert it to upper case using the String.toUpperCase(). Such a command name will be then used to look for a command implementation in the command table.

Specified by:
getCommandNames in interface CommandHandler
Returns:
array of command names.

validate

public void validate(List args,
                     Map values,
                     Map variableContainer,
                     ScriptingContext repository)
              throws SyntaxErrorException
Description copied from interface: CommandHandler
Validate if the command complies with the command syntax.The command is already pre-parsed to a list of parameter names and a map of [name, value] pairs.

Specified by:
validate in interface CommandHandler
Parameters:
args - a list of parameters.
values - a map of [param, value] pairs resulted from parsing of the command.
variableContainer - output map for values.
repository - execution context.
Throws:
SyntaxErrorException - when the command doesn't meet the required syntax.

execute

public int execute(List args,
                   Map values,
                   ScriptingContext context)
            throws SyntaxErrorException
Description copied from interface: CommandHandler

Execute the command.

Argument context will contain all necessary objects that the command may possibly use, for example the com.tplan.robot.gui.FrameBufferPanel and com.tplan.robot.api.rfb.RfbModule instances etc. If the command e.g. needs to send some key events to the RFB server, you should save the reference to the RfbModuleImpl instance and use its methods to fire the required key events.

Specified by:
execute in interface CommandHandler
Parameters:
args - a list of parameters.
values - a map of [param, value] pairs resulted from parsing of the command.
context - execution context.
Returns:
command exit code.
Throws:
SyntaxErrorException - when the command doesn't meet the required syntax.

getStablePopupMenuItems

public List getStablePopupMenuItems()
Description copied from interface: CommandHandler
Get a list of stable actions. They will be used to build up a pop up menu displayed on a right mouse click onto the commend in the editor. Though it is not explicitly declared, the list must contain javax.swing.Action instances.

Specified by:
getStablePopupMenuItems in interface CommandHandler
Overrides:
getStablePopupMenuItems in class AbstractCommandHandler
Returns:
list of stable context pop up menu actions.

canRunWithoutConnection

public boolean canRunWithoutConnection()
This method should return true if it can be executed even when the tool is not connected to a desktop.

Specified by:
canRunWithoutConnection in interface CommandHandler
Overrides:
canRunWithoutConnection in class AbstractCommandHandler
Returns:
this implementation always returns true as no desktop connection is needed for the exec command.

getArguments

public List getArguments(String command,
                         ScriptingContext context)
Description copied from interface: AdvancedCommandHandler
Get the list of supported arguments. For example, the Mouse command should return a list containing "click", "move" etc. Commands which have no argument and rely just on parameters (param=value) should return null.

Specified by:
getArguments in interface AdvancedCommandHandler
Parameters:
command - the current command.
context - a context.
Returns:
list of supported argument values.

getParameters

public List getParameters(String command,
                          ScriptingContext context)
Description copied from interface: AdvancedCommandHandler
Get the list of supported parameters. Command handlers are free to parse the current command and return a filtered list depending on what is already specified. Parameters in the list should be String instances. If they are other objects than String, they may or may not be handled well depending on what the GUI supports.

Specified by:
getParameters in interface AdvancedCommandHandler
Parameters:
command - the current conmmand text (complete).
context - a context.
Returns:
list of supported parameter names.

getParameterValues

public List getParameterValues(String paramName,
                               String command,
                               ScriptingContext context)
Description copied from interface: AdvancedCommandHandler
Get values of a particular parameter. This is to be used for parameters which have a fixed set of acceptable values. The command wizard typically displays the values as a list.

Specified by:
getParameterValues in interface AdvancedCommandHandler
Parameters:
paramName - parameter name.
command - the current conmmand text (complete).
context - a context.
Returns:
list of supported parameter values.

getVisualParameters

public List<Preference> getVisualParameters(LinkedHashMap<String,Object> parameters,
                                            TestScriptInterpret interpret)
Description copied from interface: EditorFriendlyCommandHandler

Get the list of visual parameters for construction of a dynamic command editor window.

This method will be called only after the EditorFriendlyCommandHandler.hasCustomPropertyDialog(java.util.LinkedHashMap, com.tplan.robot.scripting.interpret.TestScriptInterpret, int, javax.swing.Action[]) and EditorFriendlyCommandHandler.hasCustomParameterComponent(java.util.LinkedHashMap, com.tplan.robot.scripting.interpret.TestScriptInterpret, com.tplan.robot.gui.preferences.PreferencePanel[]) methods return false.

Specified by:
getVisualParameters in interface EditorFriendlyCommandHandler
Parameters:
parameters - input parameters parsed from the already existing command or preselected through the Command Wizard menu.
interpret - test script interpret owning the edited script.
Returns:
list of visual parameters. If the list is null and the command does not provide a custom component through the EditorFriendlyCommandHandler.hasCustomPropertyDialog(java.util.LinkedHashMap, com.tplan.robot.scripting.interpret.TestScriptInterpret, int, javax.swing.Action[]) and EditorFriendlyCommandHandler.hasCustomParameterComponent(java.util.LinkedHashMap, com.tplan.robot.scripting.interpret.TestScriptInterpret, com.tplan.robot.gui.preferences.PreferencePanel[]) methods, it will be considered as not editable through the GUI.

checkVisualParameters

public void checkVisualParameters(Map<String,CharSequence> parameters,
                                  TestScriptInterpret interpret)
                           throws IllegalArgumentException
Description copied from interface: EditorFriendlyCommandHandler

Check (compile) the map of parameters retrieved through the command editor window before they are used to build and/or update the command or Java method call. This method may be also used to remove or filter the parameters. This is especially useful if the command editor uses auxiliary settings which are not recognized by the command or method at runtime.

If the command handler extends the AbstractCommandHandler class, it may take advantage of the AbstractCommandHandler.compileParameters(java.util.Map, com.tplan.robot.scripting.interpret.TestScriptInterpret) method which converts a copy of the input map to the legacy parameter format and passes it to the CommandHandler.validate(java.util.List, java.util.Map, java.util.Map, com.tplan.robot.scripting.ScriptingContext) method to verify whether the parameters are recognized and their values are acceptable. This allows to avoid duplication of parameter parsing and compilation code.

Specified by:
checkVisualParameters in interface EditorFriendlyCommandHandler
Parameters:
parameters - map of parameters and their values. All values are in the format recognized by token parser (TokenParserImpl.getParser()) which may be used to convert them to native Java objects such as Number, Point, Rectangle etc.
interpret - test script interpret owning the edited script.
Throws:
IllegalArgumentException - when one or more parameters is not recognized or its value is invalid. The exception should contain a descriptive message because it will be displayed by the GUI.

hasFixedArgument

public boolean hasFixedArgument(List<String> arguments)
Description copied from interface: EditorFriendlyCommandHandler
Defines whether the command uses a fixed argument (one-of-a-list). Examples of such commands are Mouse with the arguments of "click", "press" etc. or WaitFor ("match", "mismatch",...). If the command does use a fixed argument it is supposed to return true and populate the argument list with the argument values (if the list is not null).

Specified by:
hasFixedArgument in interface EditorFriendlyCommandHandler
Parameters:
arguments - optional output list for the argument values.
Returns:
true if the command uses fixed argument values, false if not.

hasCustomParameterComponent

public boolean hasCustomParameterComponent(LinkedHashMap<String,Object> parameters,
                                           TestScriptInterpret interpret,
                                           PreferencePanel[] panel)
Description copied from interface: EditorFriendlyCommandHandler
Specify whether the command provides a custom preference panel. If it does it is expected to return true and populate the first field of the panel array with an instance of the panel.

Specified by:
hasCustomParameterComponent in interface EditorFriendlyCommandHandler
Parameters:
parameters - map of parameters and their values. All values are in the format recognized by token parser (TokenParserImpl.getParser()) which may be used to convert them to native Java objects such as Number, Point, Rectangle etc.
interpret - test script interpret owning the edited script.
panel - output array of length=1 which should be populated inside the method with the custom panel instance if the method returns true.
Returns:
true if the command creates its own custom preference panel or false otherwise.

hasCustomPropertyDialog

public boolean hasCustomPropertyDialog(LinkedHashMap<String,Object> parameters,
                                       TestScriptInterpret interpret,
                                       int offset,
                                       Action[] action)
Description copied from interface: EditorFriendlyCommandHandler

Specify whether the command provides a custom editor. If it does it is expected to return true and populate the first field of the action array with an instance of an Action which opens up the dialog.

Even though the method is implemented to return false, it may be also used to preprocess parameters parsed from an existing command call before they reach the command editor window. The method may for example change the parameters or their values in the input map. As the argument map the real one rather than a copy, any data change will hold in there and it will be reflected in the GUI.

Specified by:
hasCustomPropertyDialog in interface EditorFriendlyCommandHandler
Parameters:
parameters - map of parameters and their values. All values are in the format recognized by token parser (TokenParserImpl.getParser()) which may be used to convert them to native Java objects such as Number, Point, Rectangle etc.
interpret - test script interpret owning the edited script.
offset - position in the edited script.
action - output array of length=1 which should be populated inside the method with an Action instance if the method returns true.
Returns:
true if the command creates its own dialog or false otherwise.

getCategory

public int getCategory(StringBuilder customCategoryDescription)
Description copied from interface: EditorFriendlyCommandHandler
Get the category the command falls to. The method may return one of the predefined CATEGORY_XXX constants defined by this class. Commands which do not fall into any specified category may return EditorFriendlyCommandHandler.CATEGORY_UNKNOWN or a code outside of the recognized constants and pass the desired category name through the argument string builder instance.

Specified by:
getCategory in interface EditorFriendlyCommandHandler
Parameters:
customCategoryDescription - string buffer for category name. It is only used if the returned value is other than the standard ones.
Returns:
category code.

getShortDescription

public String getShortDescription(Map<String,String> parameters,
                                  TestScriptInterpret interpret)
Description copied from interface: EditorFriendlyCommandHandler
Get short description (up to 50 chars) of what the command does. This will be used for the list (menu) of available actions in the GUI.

Specified by:
getShortDescription in interface EditorFriendlyCommandHandler
Parameters:
parameters - map of parameters and their values. All values are in the format recognized by token parser (TokenParserImpl.getParser()) which may be used to convert them to native Java objects such as Number, Point, Rectangle etc.
interpret - test script interpret owning the edited script.
Returns:
short command description.

T-Plan Robot Enterprise 3.5.1
Build No. 3.5.1-20140411.1