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

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

java.lang.Object
  extended by com.tplan.robot.scripting.commands.AbstractCommandHandler
      extended by com.tplan.robot.scripting.commands.impl.AbstractFileResourceCommand
All Implemented Interfaces:
GUIConstants, Plugin, Configurable, AdvancedCommandHandler, CommandHandler, ScriptListener
Direct Known Subclasses:
ExcelCommand, FileCommand

public abstract class AbstractFileResourceCommand
extends AbstractCommandHandler
implements ScriptListener, AdvancedCommandHandler

Base handler for any command allowing to read from and save to a file. It provides the basic infrastructure of opening, creating and closing files. To extend it:


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


Field Summary
static String ARG_CLOSE
           
static String ARG_CREATE
           
static String ARG_OPEN
           
protected  String[] ARGUMENTS
           
protected static String CONTEXT_FILE_CREATE_CACHE
           
protected  String CONTEXT_FILE_MAP
           
protected static String CONTEXT_FILE_OPEN_CACHE
           
static String CONTEXT_FILE_RESOURCE_MAP
           
protected  Map contextAttributes
           
protected  KeyStroke contextShortcut
           
static int ERR_FAILED_TO_OPEN
           
static int ERR_FAILED_TO_SAVE
           
static int ERR_MAX
           
static String PARAM_ARGUMENT
           
protected static String PARAM_BEAN
           
static String PARAM_FILE
           
static String PARAM_ID
           
static String PARAM_OUTFILE
           
static String PARAM_SAVE
           
protected  String[][] PARAMS
           
 String VAR_FILE
           
 String VAR_FILENAME
           
 String VAR_OUTFILE
           
 String VAR_OUTFILENAME
           
 
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.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
AbstractFileResourceCommand()
           
 
Method Summary
protected  boolean addParamToArgumentArray(String param, String argument)
          Declare support of a parameter for an already existing argument.
protected  void addSupportedArgsAndParams(String[] arguments, String[][] parameters)
          Append an array of arguments and parameters to the default lists.
 boolean canRunWithoutConnection()
          This method should return true if it can be executed even when the tool is not connected to a desktop.
protected abstract  void cleanUpAllVars(ScriptingContext ctx)
          Clean up all variables created by the command.
protected  void cleanUpFileVars(ScriptingContext ctx)
           
protected  void closeFileBean(AbstractFileBean bean, boolean save)
           
protected abstract  void create(AbstractFileBean bean, OutputStream out)
           
protected abstract  AbstractFileBean createBean()
          Create a file bean.
protected  void defineFileVariables(AbstractFileBean bean, ScriptingContext context)
           
 int execute(List args, Map values, Map outputMap, ScriptingContext context)
           
 int execute(List args, Map values, Map outputMap, ScriptingContext context, String errorVar)
           
 List getArguments(String command, ScriptingContext context)
          Get the list of supported arguments.
abstract  String[] getCommandNames()
          Get command names.
 String getContextArgument()
          Get the dummy command argument.
 Map getContextAttributes()
          Get a map with context attributes.
 KeyStroke getContextShortcut()
          Get preferred hot key for the GUI command wizard.
protected abstract  JFileChooser getFileChooser(String argument, ScriptingContext context)
           
 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.
protected  String getScriptPath(TestScriptInterpret interpret)
           
protected  Map<String,AbstractFileBean> getUsedFiles(ScriptingContext context, Class beanClass)
           
 boolean isGlobalPrerequisity(String command)
          This method should return true if the command needs to be executed prior to running part of a test script.
protected abstract  void load(AbstractFileBean bean, InputStream in)
           
protected  void removeVariables(String[] varnames, ScriptingContext ctx)
           
protected abstract  void save(AbstractFileBean bean, OutputStream out)
           
 void scriptEvent(ScriptEvent event)
          Implementation of the ScriptListener interface.
protected  void updateRelativePath(String paramKey, String dummyParamKey, Map<String,Object> parameters, TestScriptInterpret interpret)
           
 void validate(List args, Map values, Map variableContainer, ScriptingContext context)
          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, getStablePopupMenuItems, getSupportContact, getUniqueId, getVendorHomePage, getVendorName, getVersion, 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, execute, getStablePopupMenuItems, removeCommandListener
 

Field Detail

contextShortcut

protected KeyStroke contextShortcut

ARG_OPEN

public static final String ARG_OPEN
See Also:
Constant Field Values

ARG_CREATE

public static final String ARG_CREATE
See Also:
Constant Field Values

ARG_CLOSE

public static final String ARG_CLOSE
See Also:
Constant Field Values

ARGUMENTS

protected String[] ARGUMENTS

PARAM_ARGUMENT

public static final String PARAM_ARGUMENT
See Also:
Constant Field Values

PARAM_ID

public static final String PARAM_ID
See Also:
Constant Field Values

PARAM_FILE

public static final String PARAM_FILE
See Also:
Constant Field Values

PARAM_OUTFILE

public static final String PARAM_OUTFILE
See Also:
Constant Field Values

PARAM_BEAN

protected static final String PARAM_BEAN
See Also:
Constant Field Values

PARAM_SAVE

public static final String PARAM_SAVE
See Also:
Constant Field Values

PARAMS

protected String[][] PARAMS

CONTEXT_FILE_MAP

protected final String CONTEXT_FILE_MAP

VAR_FILE

public final String VAR_FILE

VAR_FILENAME

public final String VAR_FILENAME

VAR_OUTFILE

public final String VAR_OUTFILE

VAR_OUTFILENAME

public final String VAR_OUTFILENAME

contextAttributes

protected Map contextAttributes

ERR_FAILED_TO_OPEN

public static final int ERR_FAILED_TO_OPEN
See Also:
Constant Field Values

ERR_FAILED_TO_SAVE

public static final int ERR_FAILED_TO_SAVE
See Also:
Constant Field Values

ERR_MAX

public static final int ERR_MAX
See Also:
Constant Field Values

CONTEXT_FILE_RESOURCE_MAP

public static final String CONTEXT_FILE_RESOURCE_MAP
See Also:
Constant Field Values

CONTEXT_FILE_OPEN_CACHE

protected static final String CONTEXT_FILE_OPEN_CACHE
See Also:
Constant Field Values

CONTEXT_FILE_CREATE_CACHE

protected static final String CONTEXT_FILE_CREATE_CACHE
See Also:
Constant Field Values
Constructor Detail

AbstractFileResourceCommand

public AbstractFileResourceCommand()
Method Detail

createBean

protected abstract AbstractFileBean createBean()
Create a file bean. The implementing class is supposed to subclass the AbstractFileBean one and return its instance. This mechanism allows to define custom fields and methods in the bean managed by this base class.

Returns:
a new instance of the file bean.

cleanUpAllVars

protected abstract void cleanUpAllVars(ScriptingContext ctx)
Clean up all variables created by the command. This method is called to clean up the variable map in the context when the file is closed. The subclass should take advantage of the removeVariables() method to remove any variables it produces from the context.

Parameters:
ctx - a script context.

save

protected abstract void save(AbstractFileBean bean,
                             OutputStream out)
                      throws FileNotFoundException,
                             IOException
Throws:
FileNotFoundException
IOException

create

protected abstract void create(AbstractFileBean bean,
                               OutputStream out)
                        throws FileNotFoundException,
                               IOException
Throws:
FileNotFoundException
IOException

load

protected abstract void load(AbstractFileBean bean,
                             InputStream in)
                      throws FileNotFoundException,
                             IOException
Throws:
FileNotFoundException
IOException

getFileChooser

protected abstract JFileChooser getFileChooser(String argument,
                                               ScriptingContext context)

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()
Description copied from interface: CommandHandler
Get the dummy command argument. It is inserted as argument value to commands generated through the command wizard in GUI. It is usually a short description of the expected argument value and the user is expected to rewrite it with a real value. If the command has no argument (just parameters in form of param=value), the method should return null.

Specified by:
getContextArgument in interface CommandHandler
Overrides:
getContextArgument in class AbstractCommandHandler
Returns:
dummy context argument value.

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..

isGlobalPrerequisity

public boolean isGlobalPrerequisity(String command)
Description copied from interface: CommandHandler

This method should return true if the command needs to be executed prior to running part of a test script.

Imagine a following situation. User creates a script:
Var PATH=/usr/java Type {PATH}/bin/java Press Enter

User then selects just the last two commands to be executed. It would of course fail because the PATH variable is not defined. If this method returns true, the command will be executed before running selected commands are executed.

Specified by:
isGlobalPrerequisity in interface CommandHandler
Overrides:
isGlobalPrerequisity in class AbstractCommandHandler
Parameters:
command - a command with parameters to be processed.
Returns:
true if the command needs to be executed prior to running of part of the script, false othewise.

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 this command.

getCommandNames

public abstract 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 context)
              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.
context - execution context.
Throws:
SyntaxErrorException - when the command doesn't meet the required syntax.

getUsedFiles

protected Map<String,AbstractFileBean> getUsedFiles(ScriptingContext context,
                                                    Class beanClass)

execute

public int execute(List args,
                   Map values,
                   Map outputMap,
                   ScriptingContext context)
            throws SyntaxErrorException
Throws:
SyntaxErrorException

execute

public int execute(List args,
                   Map values,
                   Map outputMap,
                   ScriptingContext context,
                   String errorVar)
            throws SyntaxErrorException
Throws:
SyntaxErrorException

defineFileVariables

protected void defineFileVariables(AbstractFileBean bean,
                                   ScriptingContext context)

cleanUpFileVars

protected void cleanUpFileVars(ScriptingContext ctx)

addSupportedArgsAndParams

protected void addSupportedArgsAndParams(String[] arguments,
                                         String[][] parameters)
Append an array of arguments and parameters to the default lists. This is necessary for all subclasses to make sure the validating method recognizes them.

Parameters:
arguments -
parameters -

addParamToArgumentArray

protected boolean addParamToArgumentArray(String param,
                                          String argument)
Declare support of a parameter for an already existing argument. The method inserts the parameter name into the list of params supported by the command and makes the validator recognize it.

Parameters:
param - a parameter name.
argument - already existing argument.
Returns:
true if the parameter was added, false if not.

removeVariables

protected void removeVariables(String[] varnames,
                               ScriptingContext ctx)

closeFileBean

protected void closeFileBean(AbstractFileBean bean,
                             boolean save)
                      throws FileNotFoundException,
                             IOException
Throws:
FileNotFoundException
IOException

scriptEvent

public void scriptEvent(ScriptEvent event)
Implementation of the ScriptListener interface.

Specified by:
scriptEvent in interface ScriptListener
Parameters:
event -

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.

getScriptPath

protected String getScriptPath(TestScriptInterpret interpret)

updateRelativePath

protected void updateRelativePath(String paramKey,
                                  String dummyParamKey,
                                  Map<String,Object> parameters,
                                  TestScriptInterpret interpret)

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