public class ScriptingEngines extends Object
Manager for JSR-223 ScriptEngine
handling.
Resolving a script engine:
This class supports resolving a script engine for a given 'language name' (eg. 'groovy').
If the configuration option enableScriptEngineCaching
is set to true,
the class will attempt to cache 'cachable' script engines. We assume a ScriptEngine
is
'cachable' if it declares to be threadsafe (see isCachable(ScriptEngine)
)
Custom Bindings: this class supports custom Bindings
implementations through the scriptBindingsFactory
. See ScriptBindingsFactory
.
Modifier and Type | Field and Description |
---|---|
protected Map<String,ScriptEngine> |
cachedEngines |
static String |
DEFAULT_SCRIPTING_LANGUAGE |
protected boolean |
enableScriptEngineCaching |
static String |
GROOVY_SCRIPTING_LANGUAGE |
protected ScriptBindingsFactory |
scriptBindingsFactory |
Constructor and Description |
---|
ScriptingEngines(ScriptBindingsFactory scriptBindingsFactory) |
ScriptingEngines(ScriptEngineManager scriptEngineManager) |
Modifier and Type | Method and Description |
---|---|
ScriptingEngines |
addScriptEngineFactory(ScriptEngineFactory scriptEngineFactory) |
CompiledScript |
compile(ScriptEngine scriptEngine,
String language,
String src) |
CompiledScript |
compile(String language,
String src)
Used to compile a script provided as String into an engine-specific
CompiledScript . |
protected void |
configureGroovyScriptEngine(ScriptEngine scriptEngine)
Allows providing custom configuration for the groovy script engine.
|
Bindings |
createBindings(ScriptEngine scriptEngine,
VariableScope variableScope)
override to build a spring aware ScriptingEngines
|
Set<String> |
getAllSupportedLanguages() |
protected ScriptEngine |
getCachedScriptEngine(String language)
Returns a cached script engine or creates a new script engine if no such engine is currently cached.
|
protected ScriptEngine |
getGlobalScriptEngine(String language) |
protected ScriptEngine |
getPaScriptEngine(String language,
ProcessApplicationReference pa) |
ScriptBindingsFactory |
getScriptBindingsFactory() |
ScriptEngine |
getScriptEngineForLanguage(String language)
Loads the given script engine by language name.
|
protected boolean |
isCachable(ScriptEngine scriptEngine)
Allows checking whether the script engine can be cached.
|
boolean |
isEnableScriptEngineCaching() |
void |
setEnableScriptEngineCaching(boolean cacheScriptEngines) |
void |
setScriptBindingsFactory(ScriptBindingsFactory scriptBindingsFactory) |
void |
setScriptEngineFactories(List<ScriptEngineFactory> scriptEngineFactories) |
public static final String DEFAULT_SCRIPTING_LANGUAGE
public static final String GROOVY_SCRIPTING_LANGUAGE
protected ScriptBindingsFactory scriptBindingsFactory
protected Map<String,ScriptEngine> cachedEngines
protected boolean enableScriptEngineCaching
public ScriptingEngines(ScriptBindingsFactory scriptBindingsFactory)
public ScriptingEngines(ScriptEngineManager scriptEngineManager)
public void setEnableScriptEngineCaching(boolean cacheScriptEngines)
public boolean isEnableScriptEngineCaching()
public ScriptingEngines addScriptEngineFactory(ScriptEngineFactory scriptEngineFactory)
public void setScriptEngineFactories(List<ScriptEngineFactory> scriptEngineFactories)
public CompiledScript compile(String language, String src)
Used to compile a script provided as String into an engine-specific CompiledScript
.
Note on caching of compiled scripts: only cache the returned script if
enableScriptEngineCaching
is set to 'true'. Depending on the implementation, the compiled
script will keep references to the script engine which created it.
language
- the script language in which the script is writtensrc
- a string of the source of the scriptCompiledScript
or null if script engine can be found but does not support compilation.ProcessEngineException
- if no ScriptEngine
can be resolved for the provided language or
if the script cannot be compiled (syntax error ...).public CompiledScript compile(ScriptEngine scriptEngine, String language, String src)
compile(String, String)
public ScriptEngine getScriptEngineForLanguage(String language)
language
- the name of the script language to lookup an implementation forProcessEngineException
- if no such engine can be found.protected ScriptEngine getPaScriptEngine(String language, ProcessApplicationReference pa)
protected ScriptEngine getGlobalScriptEngine(String language)
protected ScriptEngine getCachedScriptEngine(String language)
language
- the language (such as 'groovy' for the script engine)protected boolean isCachable(ScriptEngine scriptEngine)
scriptEngine
- the script engine to check.protected void configureGroovyScriptEngine(ScriptEngine scriptEngine)
scriptEngine
- the groovy script engine to configure.public Bindings createBindings(ScriptEngine scriptEngine, VariableScope variableScope)
engineBindings
- scriptEngine
- public ScriptBindingsFactory getScriptBindingsFactory()
public void setScriptBindingsFactory(ScriptBindingsFactory scriptBindingsFactory)
Copyright © 2018. All rights reserved.