public class JavaEngine extends Object implements IScriptEngine
Modifier and Type | Field and Description |
---|---|
static String |
ENGINE_ID |
TRACE_SCRIPT_ENGINE
Constructor and Description |
---|
JavaEngine() |
Modifier and Type | Method and Description |
---|---|
void |
addExecutionListener(IExecutionListener listener) |
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 |
isIdle()
Returns the execution state of the engine.
|
void |
registerJar(URL url)
Register a jar file and add it to the classpath.
|
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 |
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.
|
public static final String ENGINE_ID
public ScriptResult executeAsync(Object content)
IScriptEngine
Reader
object, or a File
special treatment is done, otherwise the toString() method is used to extract script code.executeAsync
in interface IScriptEngine
content
- content to be executed.public ScriptResult executeSync(Object content) throws InterruptedException
IScriptEngine
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.executeSync
in interface IScriptEngine
content
- content to be executed.InterruptedException
- when execution is interruptedpublic Object inject(Object content)
IScriptEngine
inject
in interface IScriptEngine
content
- content to be executed.public Object injectUI(Object content)
IScriptEngine
injectUI
in interface IScriptEngine
content
- content to be executed.public Object getExecutedFile()
IScriptEngine
getExecutedFile
in interface IScriptEngine
public void setTerminateOnIdle(boolean terminate)
IScriptEngine
setTerminateOnIdle
in interface IScriptEngine
terminate
- true
to request terminationpublic boolean getTerminateOnIdle()
IScriptEngine
getTerminateOnIdle
in interface IScriptEngine
true
when engine is terminated when idlepublic void schedule()
IScriptEngine
schedule
in interface IScriptEngine
public void terminate()
IScriptEngine
terminate
in interface IScriptEngine
public void terminateCurrent()
IScriptEngine
terminateCurrent
in interface IScriptEngine
public void addExecutionListener(IExecutionListener listener)
addExecutionListener
in interface IScriptEngine
public void removeExecutionListener(IExecutionListener listener)
removeExecutionListener
in interface IScriptEngine
public void reset()
IScriptEngine
reset
in interface IScriptEngine
public boolean isIdle()
IScriptEngine
false
. If the engine is
waiting for further scripts to execute this will return true
.isIdle
in interface IScriptEngine
public String getName()
IScriptEngine
getName
in interface IScriptEngine
public void setVariable(String name, Object content)
IScriptEngine
setVariable
in interface IScriptEngine
name
- variable namecontent
- variable contentpublic Object getVariable(String name)
IScriptEngine
getVariable
in interface IScriptEngine
name
- variable namenull
public boolean hasVariable(String name)
IScriptEngine
null
, IScriptEngine.getVariable(String)
might not be
sufficient to query.hasVariable
in interface IScriptEngine
name
- variable nametrue
when variable existspublic String getSaveVariableName(String name)
IScriptEngine
getSaveVariableName
in interface IScriptEngine
name
- variable name candidatepublic PrintStream getOutputStream()
getOutputStream
in interface IScriptEngine
public void setOutputStream(OutputStream outputStream)
IScriptEngine
setOutputStream
in interface IScriptEngine
outputStream
- default output streampublic InputStream getInputStream()
getInputStream
in interface IScriptEngine
public void setInputStream(InputStream inputStream)
IScriptEngine
setInputStream
in interface IScriptEngine
inputStream
- default input streampublic PrintStream getErrorStream()
getErrorStream
in interface IScriptEngine
public void setErrorStream(OutputStream errorStream)
IScriptEngine
setErrorStream
in interface IScriptEngine
errorStream
- default error streampublic IEnvironment getEnvironment()
public Object removeVariable(String name)
IScriptEngine
removeVariable
in interface IScriptEngine
name
- variable to be removed.public Map<String,Object> getVariables()
IScriptEngine
getVariables
in interface IScriptEngine
public void registerJar(URL url)
IScriptEngine
registerJar
in interface IScriptEngine
url
- url to load jar file frompublic void setCloseStreamsOnTerminate(boolean closeStreams)
IScriptEngine
setCloseStreamsOnTerminate
in interface IScriptEngine
closeStreams
- true
to close streamspublic void setEngineDescription(EngineDescription description)
IScriptEngine
setEngineDescription
in interface IScriptEngine
description
- engine descriptionpublic EngineDescription getDescription()
IScriptEngine
getDescription
in interface IScriptEngine