T-Plan Robot Enterprise 4.0.1
Build No. 4.0.1-20141118.1

com.tplan.robot.scripting.interpret
Class PlainTextInterpret

java.lang.Object
  extended by com.tplan.robot.scripting.interpret.AbstractTestScriptInterpret
      extended by com.tplan.robot.scripting.interpret.PlainTextInterpret
All Implemented Interfaces:
Plugin, ScriptTypeProvider, TestScriptInterpret, ScriptedExecutable, java.util.EventListener, javax.swing.event.DocumentListener

public class PlainTextInterpret
extends AbstractTestScriptInterpret

Fall back interpret ensuring that files that are not recognized as test scripts can be displayed and edited in the script editor.


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


Field Summary
 
Fields inherited from class com.tplan.robot.scripting.interpret.AbstractTestScriptInterpret
compilationContext, DEFAULT_VARS, destroyed, doNotFireEvents, executing, executionContext, lastModified, manualStop, manualStopJustification, partiallyExecuting, PFLAG, scriptManager, scriptOwner, SFLAG, sourceURI, uri
 
Fields inherited from interface com.tplan.robot.scripting.interpret.TestScriptInterpret
TYPE_JAVA, TYPE_PROPRIETARY, TYPE_UNKNOWN
 
Constructor Summary
PlainTextInterpret()
           
 
Method Summary
 boolean compile(ScriptingContext customContext)
          Compile source code of the test script.
 int execute(ScriptingContext customContext)
          Execute the test script.
 java.lang.String getDescription()
          Get plugin description to be displayed in the GUI.
 java.lang.String getDisplayName()
          Get short plugin name to be displayed in the GUI.
 javax.swing.text.StyledDocument getDocument()
          Get the styled document holding source code of the test script.
 java.lang.String[] getSupportedFileExtensions()
          Get typical file extensions that should be handled by a particular implementation of a test script.
 int getType()
          Get the test script type.
 java.lang.String getTypeDescription()
          Get the test script interpret type description.
 java.lang.String getUniqueId()
          Get unique ID associated with the plugin.
 boolean isPartialExecutionAllowed()
          Indicate whether it is possible to execute just a part of the test script.
 boolean isPartialExecutionAllowed(int start, int end, int[] range)
          Indicate whether it is possible to execute the specified part of the test script.
 boolean isSupportedTestScript()
           
 void resetSelection()
          Reset selection for partial execution purposes.
 void setSelection(int startOffset, int endOffset)
          Set the start and end offset for partial execution of a test script.
 
Methods inherited from class com.tplan.robot.scripting.interpret.AbstractTestScriptInterpret
addChangeListener, applyVariablesToCommand, changedUpdate, checkDependencies, destroy, getApplicableValue, getCode, getCompilationContext, getDate, getDisplayValue, getExecutionContext, getFileLastModified, getImplementedInterface, getLowestSupportedVersion, getMessageAfterInstall, getMessageBeforeInstall, getScriptManager, getSourceURI, getSupportContact, getURI, getVendorHomePage, getVendorName, getVersion, hasSource, insertUpdate, isEditable, isExecuting, isManualStop, isModified, isPartiallyExecuting, isPause, isStop, readFile, reload, removeChangeListener, removeUpdate, replace, requiresRestart, save, save, save, setFileLastModified, setModified, setPause, setScriptManager, setScriptOwner, setSourceURI, setStop, setURI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PlainTextInterpret

public PlainTextInterpret()
Method Detail

getType

public int getType()
Description copied from interface: TestScriptInterpret
Get the test script type. Reserved values are 0 (unknown language), 1 (test script in the T-Plan Robot Enterprise proprietary scripting language) and 2 (Java test scripts).

Returns:
test script type.

getTypeDescription

public java.lang.String getTypeDescription()
Description copied from interface: TestScriptInterpret
Get the test script interpret type description. This string is typically displayed to the user when a new script is being created through the GUI and the user has to select which test script type is to be created.

Returns:
test script type description such as "TPR test script", "Java test script" etc.

getSupportedFileExtensions

public java.lang.String[] getSupportedFileExtensions()
Description copied from interface: TestScriptInterpret
Get typical file extensions that should be handled by a particular implementation of a test script. Test script interpret factory (TestScriptInterpretFactory) takes advantage of this method to create interpret instances for particular test script files.

Returns:
list of specific file extensions which should be handled by this interpret. For example, a Java interpret would return new String[] { "java" }. If the method returns null, it means that there is no specific extension for the script type handled by this class. The latter case applies for example for the proprietary test script format which may be saved with any extension.

compile

public boolean compile(ScriptingContext customContext)
                throws InterpretErrorException
Description copied from interface: TestScriptInterpret
Compile source code of the test script. If the script is in a scripting language, the method should check the code syntax. If the script is in a compilable language (for example Java test scripts), the method should compile the code and make it ready for execution.

Parameters:
customContext - customized context for this validation. If the argument is null, the interpret is supposed to obtain a preinitialized context instance from the script manager through ScriptManager.createDefaultContext().
Returns:
true if the script compiled fine, false if there were errors. Compilation errors are to be saved as a list of SyntaxErrorException instances to the compilation context. The interpret is also supposed to fire appropriate compilation script events through the associated script manager. The context should be made available after compilation through the TestScriptInterpret.getCompilationContext() method.
Throws:
InterpretErrorException - should be thrown on an internal error or illegal interpret state. The exception message gets typically displayed or otherwise reported to the user.

execute

public int execute(ScriptingContext customContext)
            throws InterpretErrorException
Description copied from interface: TestScriptInterpret
Execute the test script. // TODO: document particular events

Parameters:
customContext - customized context for this execution. If the argument is null, the interpret is supposed to obtain a preinitialized context instance from the script manager through ScriptManager.createDefaultContext(). The context should be made available after execution through the TestScriptInterpret.getExecutionContext() method.
Returns:
execution result (exit code).
Throws:
InterpretErrorException - should be thrown on an internal error or illegal interpret state. The exception message gets typically displayed or otherwise reported to the user.

isPartialExecutionAllowed

public boolean isPartialExecutionAllowed()
Description copied from interface: TestScriptInterpret

Indicate whether it is possible to execute just a part of the test script. This is typically possible with scripting languages, such as the proprietary T-Plan Robot Enterprise one, where user can select part of the code in the editor and execute it. It is on the other hand not possible with test scripts written in Java.

Interprets returning true should expect the calls of the TestScriptInterpret.setSelection(int, int) method. Interprets which do not support this feature and return false should throw an exception when the method is called.

Returns:
true if partial execution is supported or false otherwise.

setSelection

public void setSelection(int startOffset,
                         int endOffset)
                  throws java.lang.IllegalStateException
Description copied from interface: TestScriptInterpret
Set the start and end offset for partial execution of a test script. The offsets refer to positions in the document returned by the TestScriptInterpret.getDocument() method. Interprets which do not support partial executions (i.e. their TestScriptInterpret.isPartialExecutionAllowed() method returns false) should throw an IllegalStateException exception if this method gets called.

Parameters:
startOffset - start offset indicating position in the test script document to start the execution from.
endOffset - end offset in the test script where execution should be finished.
Throws:
java.lang.IllegalStateException - if the method gets called even though the TestScriptInterpret.isPartialExecutionAllowed() method returns false to indicate that this mode is not supported.

resetSelection

public void resetSelection()
                    throws java.lang.IllegalStateException
Description copied from interface: TestScriptInterpret
Reset selection for partial execution purposes. Interprets which do not support partial executions (i.e. their TestScriptInterpret.isPartialExecutionAllowed() method returns false) should throw an IllegalStateException exception if this method gets called.

Throws:
java.lang.IllegalStateException - if the method gets called even though the TestScriptInterpret.isPartialExecutionAllowed() method returns false to indicate that this mode is not supported.

getDocument

public javax.swing.text.StyledDocument getDocument()
Description copied from interface: TestScriptInterpret
Get the styled document holding source code of the test script. The reason we hold it in a document instance is easy access to document elements. The method should never return null.

Returns:
document holding source code of the test script or ready to be used as a container for test code.

getDisplayName

public java.lang.String getDisplayName()
Description copied from interface: Plugin
Get short plugin name to be displayed in the GUI.

Returns:
short plugin name.

getDescription

public java.lang.String getDescription()
Description copied from interface: Plugin
Get plugin description to be displayed in the GUI.

Returns:
plugin description. May be null.

getUniqueId

public java.lang.String getUniqueId()
Description copied from interface: Plugin

Get unique ID associated with the plugin. The plugin manager uses the ID together with the version string to identify whether a plugin is already installed and whether a newer version of the same plugin is available.

The unique ID in fact identifies a particular plugin delivered by a particular vendor. Plugin developers are recommended to choose an ID and keep it constant for all versions of one particular plugin. The ID is never displayed in the GUI so it doesn't have to be a readable text. To avoid conflicts with other vendors it is recommended to elaborate vendor or author name and feature description into the ID, for example "custom RFB client implemented by John Doe".

Returns:
unique plugin ID.

isSupportedTestScript

public boolean isSupportedTestScript()
Specified by:
isSupportedTestScript in interface TestScriptInterpret
Overrides:
isSupportedTestScript in class AbstractTestScriptInterpret

isPartialExecutionAllowed

public boolean isPartialExecutionAllowed(int start,
                                         int end,
                                         int[] range)
Description copied from interface: TestScriptInterpret
Indicate whether it is possible to execute the specified part of the test script.

Parameters:
start - selection start offset
end - selection end offset
range - this is an optional output array (length >= 2) where the interpret may specify the start and end elements that will be executed for the given selection specified by [start, end]. These
Returns:
true if partial execution is supported or false otherwise.

T-Plan Robot Enterprise 4.0.1
Build No. 4.0.1-20141118.1