org.eclipse.ease

## Class AbstractScriptEngine

- java.lang.Object
- - org.eclipse.core.runtime.PlatformObject
  - - org.eclipse.core.internal.jobs.InternalJob
    - - org.eclipse.core.runtime.jobs.Job
      - - org.eclipse.ease.AbstractScriptEngine

All Implemented Interfaces:
  java.lang.Comparable, IAdaptable, IScriptEngine

Direct Known Subclasses:
  AbstractReplScriptEngine, ArchiveEngine, JVMCompiledScriptEngine, TestSuiteScriptEngine

    public abstract class AbstractScriptEngine
    extends Job
    implements IScriptEngine

Base implementation for a script engine. Handles Job implementation of script engine, adding script code for execution, module loading support and a basic online help system.

### Field Summary

### Fields inherited from class org.eclipse.core.runtime.jobs.Job

`ASYNC_FINISH, BUILD, DECORATE, INTERACTIVE, LONG, NONE, RUNNING, SHORT, SLEEPING, WAITING`

### Fields inherited from interface org.eclipse.ease.IScriptEngine

`TRACE_SCRIPT_ENGINE`

### Constructor Summary

Constructors
Constructor and Description
`AbstractScriptEngine(java.lang.String name)` Constructor.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `addExecutionListener(IExecutionListener listener)`
`void` `addSecurityCheck(ISecurityCheck.ActionType type, ISecurityCheck check)` Add a dedicated security check for a certain script action.
`ScriptResult` `executeAsync(java.lang.Object content)` Execute script code asynchronously.
`ScriptResult` `executeSync(java.lang.Object content)` Execute script code synchronously.
`static java.lang.String[]` `extractArguments(java.lang.String arguments)` Split a string with comma separated arguments.
`static IScriptEngine` `getCurrentScriptEngine()` Get the current script engine.
`EngineDescription` `getDescription()` Get engine description for current engine.
`java.io.PrintStream` `getErrorStream()`
`java.lang.Object` `getExecutedFile()` Get the currently executed file instance.
`java.io.InputStream` `getInputStream()`
`ILaunch` `getLaunch()` Get the launch that was used to create this engine.
`IProgressMonitor` `getMonitor()` Get the monitor of the current running engine.
`java.io.PrintStream` `getOutputStream()`
`ScriptStackTrace` `getStackTrace()`
`java.lang.Object` `getVariable(java.lang.String name)` Get a script variable.
`java.util.Map<java.lang.String,java.lang.Object>` `getVariables()` Get all variables from the scope.
`boolean` `hasVariable(java.lang.String name)` Check if a variable exists within the scope of the engine.
`java.lang.Object` `inject(java.lang.Object content)` Inject script code and execute synchronously.
`java.lang.Object` `injectUI(java.lang.Object content)` Inject script code and execute synchronously within the UI thread.
`boolean` `isFinished()` Verify that engine was started and terminated.
`void` `join(long timeout)` Join engine execution thread.
`void` `removeExecutionListener(IExecutionListener listener)`
`void` `removeSecurityCheck(ISecurityCheck check)` Remove registered security check for all actions.
`void` `setCloseStreamsOnTerminate(boolean closeStreams)` Set marker to automatically close I/O streams when engine is terminated.
`void` `setEngineDescription(EngineDescription description)`
`void` `setErrorStream(java.io.OutputStream errorStream)` Set the default error stream for the interpreter.
`void` `setExecutionRootFile(java.lang.Object executionRootFile)`
`void` `setInputStream(java.io.InputStream inputStream)` Set the default input stream for the interpreter.
`void` `setLaunch(ILaunch launch)`
`void` `setOutputStream(java.io.OutputStream outputStream)` Set the default output stream for the interpreter.
`void` `setVariable(java.lang.String name, java.lang.Object content)` Set a variable in the script engine.
`void` `terminate()` Terminate this interpreter.

### Methods inherited from class org.eclipse.core.runtime.jobs.Job

`addJobChangeListener, belongsTo, cancel, create, create, createSystem, createSystem, createSystem, done, getJobGroup, getJobManager, getName, getPriority, getProperty, getResult, getRule, getState, getThread, isBlocking, isSystem, isUser, join, join, removeJobChangeListener, schedule, schedule, setJobGroup, setName, setPriority, setProgressGroup, setProperty, setRule, setSystem, setThread, setUser, shouldRun, shouldSchedule, sleep, toString, wakeUp, wakeUp, yieldRule`

### Methods inherited from class org.eclipse.core.internal.jobs.InternalJob

`compareTo`

### Methods inherited from class org.eclipse.core.runtime.PlatformObject

`getAdapter`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.eclipse.ease.IScriptEngine

`getName, registerJar, schedule, terminateCurrent`

### Methods inherited from interface org.eclipse.core.runtime.IAdaptable

`getAdapter`

### Constructor Detail

#### AbstractScriptEngine

    public AbstractScriptEngine(java.lang.String name)

Constructor. Sets the name for the underlying job.

Parameters:
  `name` - name of script engine job

### Method Detail

#### getCurrentScriptEngine

    public static IScriptEngine getCurrentScriptEngine()

Get the current script engine. Works only if executed from the script engine thread.

Returns:
  script engine or `null`

#### getDescription

    public EngineDescription getDescription()

Description copied from interface: `IScriptEngine`
Get engine description for current engine.

Specified by:
  `getDescription` in interface `IScriptEngine`
Returns:
  engine description

#### executeAsync

    public final ScriptResult executeAsync(java.lang.Object content)

Description copied from interface: `IScriptEngine`
Execute script code asynchronously. The code provided will be scheduled and executed as soon as all previously scheduled code is executed. If content is a `Reader` object, or a `File` special treatment is done, otherwise the toString() method is used to extract script code.

Specified by:
  `executeAsync` in interface `IScriptEngine`
Parameters:
  `content` - content to be executed.
Returns:
  execution result

#### executeSync

    public final ScriptResult executeSync(java.lang.Object content)
                                   throws java.lang.InterruptedException

Description copied from interface: `IScriptEngine`
Execute script code synchronously. The code provided will be scheduled and executed as soon as all previously scheduled code is executed.If content is a `Reader` object, or a `File` special treatment is done, otherwise the toString() method is used to extract script code. In case the engine was not started yet, it will be automatically started by this call. This is a blocking call.

Specified by:
  `executeSync` in interface `IScriptEngine`
Parameters:
  `content` - content to be executed.
Returns:
  execution result
Throws:
  `java.lang.InterruptedException` - when execution is interrupted

#### inject

    public final java.lang.Object inject(java.lang.Object content)

Description copied from interface: `IScriptEngine`
Inject script code and execute synchronously. Code passed to this method will be invoked immediately. It might interrupt a currently running execution requested asynchronously.

Specified by:
  `inject` in interface `IScriptEngine`
Parameters:
  `content` - content to be executed.
Returns:
  execution result

#### injectUI

    public final java.lang.Object injectUI(java.lang.Object content)

Description copied from interface: `IScriptEngine`
Inject script code and execute synchronously within the UI thread. Code passed to this method will be invoked immediately. It might interrupt a currently running execution requested asynchronously.

Specified by:
  `injectUI` in interface `IScriptEngine`
Parameters:
  `content` - content to be executed.
Returns:
  execution result

#### getMonitor

    public IProgressMonitor getMonitor()

Description copied from interface: `IScriptEngine`
Get the monitor of the current running engine. The monitor is only valid while the script engine is running.

Specified by:
  `getMonitor` in interface `IScriptEngine`
Returns:
  current monitor or `null`

#### setCloseStreamsOnTerminate

    public void setCloseStreamsOnTerminate(boolean closeStreams)

Description copied from interface: `IScriptEngine`
Set marker to automatically close I/O streams when engine is terminated.

Specified by:
  `setCloseStreamsOnTerminate` in interface `IScriptEngine`
Parameters:
  `closeStreams` - `true` to close streams

#### getOutputStream

    public java.io.PrintStream getOutputStream()

Specified by:
  `getOutputStream` in interface `IScriptEngine`

#### setOutputStream

    public void setOutputStream(java.io.OutputStream outputStream)

Description copied from interface: `IScriptEngine`
Set the default output stream for the interpreter.

Specified by:
  `setOutputStream` in interface `IScriptEngine`
Parameters:
  `outputStream` - default output stream

#### getInputStream

    public java.io.InputStream getInputStream()

Specified by:
  `getInputStream` in interface `IScriptEngine`

#### setInputStream

    public void setInputStream(java.io.InputStream inputStream)

Description copied from interface: `IScriptEngine`
Set the default input stream for the interpreter.

Specified by:
  `setInputStream` in interface `IScriptEngine`
Parameters:
  `inputStream` - default input stream

#### getErrorStream

    public java.io.PrintStream getErrorStream()

Specified by:
  `getErrorStream` in interface `IScriptEngine`

#### setErrorStream

    public void setErrorStream(java.io.OutputStream errorStream)

Description copied from interface: `IScriptEngine`
Set the default error stream for the interpreter.

Specified by:
  `setErrorStream` in interface `IScriptEngine`
Parameters:
  `errorStream` - default error stream

#### addExecutionListener

    public void addExecutionListener(IExecutionListener listener)

Specified by:
  `addExecutionListener` in interface `IScriptEngine`

#### removeExecutionListener

    public void removeExecutionListener(IExecutionListener listener)

Specified by:
  `removeExecutionListener` in interface `IScriptEngine`

#### terminate

    public void terminate()

Description copied from interface: `IScriptEngine`
Terminate this interpreter. Addresses a request to terminate current script execution. When the request will be handled is implementation specific.

Specified by:
  `terminate` in interface `IScriptEngine`

#### getStackTrace

    public ScriptStackTrace getStackTrace()

#### getExecutedFile

    public java.lang.Object getExecutedFile()

Description copied from interface: `IScriptEngine`
Get the currently executed file instance.

Specified by:
  `getExecutedFile` in interface `IScriptEngine`
Returns:
  currently executed file

#### setExecutionRootFile

    public void setExecutionRootFile(java.lang.Object executionRootFile)

#### setEngineDescription

    public void setEngineDescription(EngineDescription description)

#### setVariable

    public void setVariable(java.lang.String name,
                            java.lang.Object content)

Description copied from interface: `IScriptEngine`
Set a variable in the script engine. This variable will be stored in the global script scope

Specified by:
  `setVariable` in interface `IScriptEngine`
Parameters:
  `name` - variable name
  `content` - variable content

#### getVariable

    public java.lang.Object getVariable(java.lang.String name)

Description copied from interface: `IScriptEngine`
Get a script variable. Retrieve a variable from the global script scope.

Specified by:
  `getVariable` in interface `IScriptEngine`
Parameters:
  `name` - variable name
Returns:
  variable content or `null`

#### hasVariable

    public boolean hasVariable(java.lang.String name)

Description copied from interface: `IScriptEngine`
Check if a variable exists within the scope of the engine. As a variable content may be `null`, `IScriptEngine.getVariable(String)` might not be sufficient to query.

Specified by:
  `hasVariable` in interface `IScriptEngine`
Parameters:
  `name` - variable name
Returns:
  `true` when variable exists

#### getVariables

    public java.util.Map<java.lang.String,java.lang.Object> getVariables()

Description copied from interface: `IScriptEngine`
Get all variables from the scope.

Specified by:
  `getVariables` in interface `IScriptEngine`
Returns:
  map of variables

#### extractArguments

    public static final java.lang.String[] extractArguments(java.lang.String arguments)

Split a string with comma separated arguments.

Parameters:
  `arguments` - comma separated arguments
Returns:
  trimmed list of arguments

#### isFinished

    public boolean isFinished()

Description copied from interface: `IScriptEngine`
Verify that engine was started and terminated.

Specified by:
  `isFinished` in interface `IScriptEngine`
Returns:
  `true` when engine ran and terminated

#### join

    public void join(long timeout)
              throws java.lang.InterruptedException

Description copied from interface: `IScriptEngine`
Join engine execution thread. Waits for engine execution up to timeout

Specified by:
  `join` in interface `IScriptEngine`
Parameters:
  `timeout` - command timeout in milliseconds
Throws:
  `java.lang.InterruptedException` - when join command got interrupted

#### addSecurityCheck

    public void addSecurityCheck(ISecurityCheck.ActionType type,
                                 ISecurityCheck check)

Description copied from interface: `IScriptEngine`
Add a dedicated security check for a certain script action. If the check was already registered for this action, no further check will be added.

Specified by:
  `addSecurityCheck` in interface `IScriptEngine`
Parameters:
  `type` - action type to add check for
  `check` - check to register

#### removeSecurityCheck

    public void removeSecurityCheck(ISecurityCheck check)

Description copied from interface: `IScriptEngine`
Remove registered security check for all actions. If the check was not registered at all nothing will happen.

Specified by:
  `removeSecurityCheck` in interface `IScriptEngine`
Parameters:
  `check` - check to be removed

#### setLaunch

    public void setLaunch(ILaunch launch)

#### getLaunch

    public ILaunch getLaunch()

Description copied from interface: `IScriptEngine`
Get the launch that was used to create this engine.

Specified by:
  `getLaunch` in interface `IScriptEngine`
Returns:
  launch or `null` in case this engine was created without launch configuration