org.eclipse.ease.engine

## Class JavaEngine

- java.lang.Object
- - org.eclipse.ease.engine.JavaEngine

All Implemented Interfaces:
  IScriptEngine

    public class JavaEngine
    extends Object
    implements IScriptEngine

### Field Summary

Fields
`static String` `ENGINE_ID`

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

`TRACE_SCRIPT_ENGINE`

### Constructor Summary

Constructors
Constructor and Description
`JavaEngine()`

### Method Summary

All 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(Object content)` Execute script code asynchronously.
`ScriptResult` `executeSync(Object content)` Execute script code synchronously.
`EngineDescription` `getDescription()` Get engine description for current engine.
`IEnvironment` `getEnvironment()`
`PrintStream` `getErrorStream()`
`Object` `getExecutedFile()` Get the currently executed file instance.
`InputStream` `getInputStream()`
`String` `getName()` Get the engine name.
`PrintStream` `getOutputStream()`
`String` `getSaveVariableName(String name)` Return a save name to be used for a variable.
`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` `isFinished()` Verify that engine was started and terminated.
`boolean` `isIdle()` Returns the execution state of the engine.
`void` `join(long timeout)` Join engine execution thread.
`void` `registerJar(URL url)` Register a jar file and add it to the classpath.
`void` `removeExecutionListener(IExecutionListener listener)`
`void` `removeSecurityCheck(ISecurityCheck check)` Remove registered security check for all actions.
`Object` `removeVariable(String name)` Remove a variable from the scope.
`void` `schedule()` Schedule script execution.
`void` `setCloseStreamsOnTerminate(boolean closeStreams)` Set marker to automatically close I/O streams when engine is terminated.
`void` `setEngineDescription(EngineDescription description)` Set engine description for current engine.
`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.
`void` `terminateCurrent()` Stops the currently executed piece of code.

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

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

### Field Detail

#### ENGINE_ID

    public static final String ENGINE_ID

See Also:
  Constant Field Values

### Constructor Detail

#### JavaEngine

    public JavaEngine()

### Method Detail

#### executeAsync

    public 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 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. 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:
  `InterruptedException` - when execution is interrupted

#### inject

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

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

#### setTerminateOnIdle

    public 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

#### schedule

    public void schedule()

Description copied from interface: `IScriptEngine`
Schedule script execution. This will start the script engine that either waits for input or immediate starts execution of previously scheduled input.

Specified by:
  `schedule` 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`

#### terminateCurrent

    public void terminateCurrent()

Description copied from interface: `IScriptEngine`
Stops the currently executed piece of code. Will continue to execute the next scheduled piece of code.

Specified by:
  `terminateCurrent` in interface `IScriptEngine`

#### addExecutionListener

    public void addExecutionListener(IExecutionListener listener)

Specified by:
  `addExecutionListener` in interface `IScriptEngine`

#### removeExecutionListener

    public void removeExecutionListener(IExecutionListener listener)

Specified by:
  `removeExecutionListener` in interface `IScriptEngine`

#### isIdle

    public boolean isIdle()

Description copied from interface: `IScriptEngine`
Returns the execution state of the engine. If the engine is processing code or is terminated this will return `false`. If the engine is waiting for further scripts to execute this will return `true`.

Specified by:
  `isIdle` in interface `IScriptEngine`
Returns:
  execution state.

#### getName

    public String getName()

Description copied from interface: `IScriptEngine`
Get the engine name.

Specified by:
  `getName` in interface `IScriptEngine`
Returns:
  engine name

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

#### getSaveVariableName

    public String getSaveVariableName(String name)

Description copied from interface: `IScriptEngine`
Return a save name to be used for a variable. The returned value denotes a valid name to be used for a variable within this engine. The returned name might already be in use.

Specified by:
  `getSaveVariableName` in interface `IScriptEngine`
Parameters:
  `name` - variable name candidate
Returns:
  converted variable name

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

#### getEnvironment

    public IEnvironment getEnvironment()

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

#### registerJar

    public void registerJar(URL url)

Description copied from interface: `IScriptEngine`
Register a jar file and add it to the classpath. After registering, classes within the jar file shall be usable within the script.

Specified by:
  `registerJar` in interface `IScriptEngine`
Parameters:
  `url` - url to load jar file from

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

#### setEngineDescription

    public void setEngineDescription(EngineDescription description)

Description copied from interface: `IScriptEngine`
Set engine description for current engine. This method gets called by the script service right after the engine constructor is called.

Specified by:
  `setEngineDescription` in interface `IScriptEngine`
Parameters:
  `description` - engine description

#### getDescription

    public EngineDescription getDescription()

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

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

#### join

    public void join(long timeout)

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

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

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