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) |
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.
|
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.
In case the engine was not started yet, it will be automatically started by this call. This is a blocking call.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 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 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 streamspublic void setEngineDescription(EngineDescription description)
IScriptEnginesetEngineDescription in interface IScriptEnginedescription - engine descriptionpublic EngineDescription getDescription()
IScriptEnginegetDescription in interface IScriptEnginepublic void join(long timeout)
IScriptEnginejoin in interface IScriptEnginetimeout - command timeout in millisecondspublic boolean isFinished()
IScriptEngineisFinished in interface IScriptEnginetrue when engine ran and terminatedpublic void addSecurityCheck(ISecurityCheck.ActionType type, ISecurityCheck check)
IScriptEngineaddSecurityCheck in interface IScriptEnginetype - action type to add check forcheck - check to registerpublic void removeSecurityCheck(ISecurityCheck check)
IScriptEngineremoveSecurityCheck in interface IScriptEnginecheck - check to be removed