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:
  Comparable, IAdaptable, IScriptEngine

Direct Known Subclasses:
  RhinoScriptEngine

    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`

### Constructor Summary

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

### Method Summary

Methods
`void` `addExecutionListener(IExecutionListener listener)`
`ScriptResult` `executeAsync(Object content)` Execute script code asynchronously.
`ScriptResult` `executeSync(Object content)` Execute script code synchronously.
`static String[]` `extractArguments(String arguments)`
`EngineDescription` `getDescription()` Get engine description for current engine.
`PrintStream` `getErrorStream()`
`Object` `getExecutedFile()` Get the currently executed file instance.
`InputStream` `getInputStream()`
`PrintStream` `getOutputStream()`
`List<IScriptDebugFrame>` `getStackTrace()`
`boolean` `getTerminateOnIdle()` Get termination condition when engine is idle.
`Object` `getVariable(String name)` Get a script variable.
`Map<String,Object>` `getVariables()` Get all variables from the scope.
`boolean` `hasVariable(String name)` Check if a variable exists within the scope of the engine.
`Object` `inject(Object content)` Inject script code and execute synchronously.
`Object` `injectUI(Object content)` Inject script code and execute synchronously within the UI thread.
`boolean` `isIdle()` Get idle status of the interpreter.
`void` `removeExecutionListener(IExecutionListener listener)`
`Object` `removeVariable(String name)` Remove a variable from the scope.
`void` `reset()` Resets the script engine to a fresh state (removes all variables and code history).
`void` `setCloseStreamsOnTerminate(boolean closeStreams)` Set marker to automatically close I/O streams when engine is terminated.
`void` `setEngineDescription(EngineDescription description)`
`void` `setErrorStream(OutputStream errorStream)` Set the default error stream for the interpreter.
`void` `setInputStream(InputStream inputStream)` Set the default input stream for the interpreter.
`void` `setOutputStream(OutputStream outputStream)` Set the default output stream for the interpreter.
`void` `setTerminateOnIdle(boolean terminate)` Set a marker that the interpreter should terminate instead entering IDLE mode.
`void` `setVariable(String name, 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, done, getJobManager, getName, getPriority, getProperty, getResult, getRule, getState, getThread, isBlocking, isSystem, isUser, join, removeJobChangeListener, schedule, schedule, 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, getSaveVariableName, registerJar, schedule, terminateCurrent`

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

`getAdapter`

### Constructor Detail

#### AbstractScriptEngine

    public AbstractScriptEngine(String name)

Constructor. Sets the name for the underlying job.

Parameters:
  `name` - name of script engine job

### Method Detail

#### 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(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(Object content)
                                   throws 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. The calling thread is stalled until the script code is processed.

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

#### inject

    public final Object inject(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 Object injectUI(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

#### 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 PrintStream getOutputStream()

Specified by:
  `getOutputStream` in interface `IScriptEngine`

#### setOutputStream

    public void setOutputStream(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 InputStream getInputStream()

Specified by:
  `getInputStream` in interface `IScriptEngine`

#### setInputStream

    public void setInputStream(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 PrintStream getErrorStream()

Specified by:
  `getErrorStream` in interface `IScriptEngine`

#### setErrorStream

    public void setErrorStream(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

#### setTerminateOnIdle

    public final void setTerminateOnIdle(boolean terminate)

Description copied from interface: `IScriptEngine`
Set a marker that the interpreter should terminate instead entering IDLE mode. If set, the interpreter will execute all pending requests and terminate afterwards.

Specified by:
  `setTerminateOnIdle` in interface `IScriptEngine`
Parameters:
  `terminate` - `true` to request termination

#### getTerminateOnIdle

    public boolean getTerminateOnIdle()

Description copied from interface: `IScriptEngine`
Get termination condition when engine is idle.

Specified by:
  `getTerminateOnIdle` in interface `IScriptEngine`
Returns:
  `true` when engine is terminated when idle

#### isIdle

    public boolean isIdle()

Get idle status of the interpreter. The interpreter is IDLE if there are no pending execution requests and the interpreter is not terminated.

Specified by:
  `isIdle` in interface `IScriptEngine`
Returns:
  true if interpreter is IDLE

#### 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`

#### reset

    public void reset()

Description copied from interface: `IScriptEngine`
Resets the script engine to a fresh state (removes all variables and code history).

Specified by:
  `reset` in interface `IScriptEngine`

#### getStackTrace

    public List<IScriptDebugFrame> getStackTrace()

#### getExecutedFile

    public Object getExecutedFile()

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

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

#### setEngineDescription

    public void setEngineDescription(EngineDescription description)

#### setVariable

    public void setVariable(String name,
                   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 Object getVariable(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(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

#### removeVariable

    public Object removeVariable(String name)

Description copied from interface: `IScriptEngine`
Remove a variable from the scope.

Specified by:
  `removeVariable` in interface `IScriptEngine`
Parameters:
  `name` - variable to be removed.
Returns:

#### getVariables

    public Map<String,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 String[] extractArguments(String arguments)