public class JavaEngine extends Object implements IScriptEngine
| 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 |
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)
IScriptEngineReader object, or a File special treatment is done, otherwise the toString() method is used to extract script code.executeAsync in interface IScriptEnginecontent - content to be executed.public ScriptResult executeSync(Object content) throws InterruptedException
IScriptEngineReader 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.executeSync in interface IScriptEnginecontent - content to be executed.InterruptedException - when execution is interruptedpublic Object inject(Object content)
IScriptEngineinject in interface IScriptEnginecontent - content to be executed.public Object injectUI(Object content)
IScriptEngineinjectUI in interface IScriptEnginecontent - content to be executed.public Object getExecutedFile()
IScriptEnginegetExecutedFile in interface IScriptEnginepublic void setTerminateOnIdle(boolean terminate)
IScriptEnginesetTerminateOnIdle in interface IScriptEngineterminate - true to request terminationpublic boolean getTerminateOnIdle()
IScriptEnginegetTerminateOnIdle in interface IScriptEnginetrue when engine is terminated when idlepublic void schedule()
IScriptEngineschedule in interface IScriptEnginepublic void terminate()
IScriptEngineterminate in interface IScriptEnginepublic void terminateCurrent()
IScriptEngineterminateCurrent in interface IScriptEnginepublic void addExecutionListener(IExecutionListener listener)
addExecutionListener in interface IScriptEnginepublic void removeExecutionListener(IExecutionListener listener)
removeExecutionListener in interface IScriptEnginepublic void reset()
IScriptEnginereset in interface IScriptEnginepublic boolean isIdle()
IScriptEnginefalse. If the engine is
waiting for further scripts to execute this will return true.isIdle in interface IScriptEnginepublic String getName()
IScriptEnginegetName in interface IScriptEnginepublic void setVariable(String name, Object content)
IScriptEnginesetVariable in interface IScriptEnginename - variable namecontent - variable contentpublic Object getVariable(String name)
IScriptEnginegetVariable in interface IScriptEnginename - variable namenullpublic boolean hasVariable(String name)
IScriptEnginenull, IScriptEngine.getVariable(String) might not be
sufficient to query.hasVariable in interface IScriptEnginename - variable nametrue when variable existspublic String getSaveVariableName(String name)
IScriptEnginegetSaveVariableName in interface IScriptEnginename - variable name candidatepublic PrintStream getOutputStream()
getOutputStream in interface IScriptEnginepublic void setOutputStream(OutputStream outputStream)
IScriptEnginesetOutputStream in interface IScriptEngineoutputStream - default output streampublic InputStream getInputStream()
getInputStream in interface IScriptEnginepublic void setInputStream(InputStream inputStream)
IScriptEnginesetInputStream in interface IScriptEngineinputStream - default input streampublic PrintStream getErrorStream()
getErrorStream in interface IScriptEnginepublic void setErrorStream(OutputStream errorStream)
IScriptEnginesetErrorStream in interface IScriptEngineerrorStream - default error streampublic IEnvironment getEnvironment()
public EngineDescription getDescription()
IScriptEnginegetDescription in interface IScriptEnginepublic Object removeVariable(String name)
IScriptEngineremoveVariable in interface IScriptEnginename - variable to be removed.public Map<String,Object> getVariables()
IScriptEnginegetVariables in interface IScriptEnginepublic void registerJar(URL url)
IScriptEngineregisterJar in interface IScriptEngineurl - url to load jar file frompublic void setCloseStreamsOnTerminate(boolean closeStreams)
IScriptEnginesetCloseStreamsOnTerminate in interface IScriptEnginecloseStreams - true to close streams