org.camunda.bpm.engine.impl.scripting.engine
Class ScriptingEngines

java.lang.Object
  extended by org.camunda.bpm.engine.impl.scripting.engine.ScriptingEngines

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.

Author:
Tom Baeyens, Daniel Meyer

Field Summary
protected  Map<String,ScriptEngine> cachedEngines
           
static String DEFAULT_SCRIPTING_LANGUAGE
           
protected  boolean enableScriptEngineCaching
           
static String GROOVY_SCRIPTING_LANGUAGE
           
protected  ScriptBindingsFactory scriptBindingsFactory
           
 
Constructor Summary
ScriptingEngines(ScriptBindingsFactory scriptBindingsFactory)
           
ScriptingEngines(ScriptEngineManager scriptEngineManager)
           
 
Method Summary
 ScriptingEngines addScriptEngineFactory(ScriptEngineFactory scriptEngineFactory)
           
 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.
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SCRIPTING_LANGUAGE

public static final String DEFAULT_SCRIPTING_LANGUAGE
See Also:
Constant Field Values

GROOVY_SCRIPTING_LANGUAGE

public static final String GROOVY_SCRIPTING_LANGUAGE
See Also:
Constant Field Values

scriptBindingsFactory

protected ScriptBindingsFactory scriptBindingsFactory

cachedEngines

protected Map<String,ScriptEngine> cachedEngines

enableScriptEngineCaching

protected boolean enableScriptEngineCaching
Constructor Detail

ScriptingEngines

public ScriptingEngines(ScriptBindingsFactory scriptBindingsFactory)

ScriptingEngines

public ScriptingEngines(ScriptEngineManager scriptEngineManager)
Method Detail

setEnableScriptEngineCaching

public void setEnableScriptEngineCaching(boolean cacheScriptEngines)

isEnableScriptEngineCaching

public boolean isEnableScriptEngineCaching()

addScriptEngineFactory

public ScriptingEngines addScriptEngineFactory(ScriptEngineFactory scriptEngineFactory)

setScriptEngineFactories

public void setScriptEngineFactories(List<ScriptEngineFactory> scriptEngineFactories)

compile

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.

Parameters:
language - the script language in which the script is written
src - a string of the source of the script
Returns:
a CompiledScript or null if script engine can be found but does not support compilation.
Throws:
ProcessEngineException - if no ScriptEngine can be resolved for the provided language or if the script cannot be compiled (syntax error ...).

getScriptEngineForLanguage

public ScriptEngine getScriptEngineForLanguage(String language)
Loads the given script engine by language name. Will throw an exception if no script engine can be loaded for the given language name.

Parameters:
language - the name of the script language to lookup an implementation for
Returns:
the script engine
Throws:
ProcessEngineException - if no such engine can be found.

getAllSupportedLanguages

public Set<String> getAllSupportedLanguages()

getCachedScriptEngine

protected ScriptEngine getCachedScriptEngine(String language)
Returns a cached script engine or creates a new script engine if no such engine is currently cached.

Parameters:
language - the language (such as 'groovy' for the script engine)
Returns:
the cached engine or null if no script engine can be created for the given language

isCachable

protected boolean isCachable(ScriptEngine scriptEngine)
Allows checking whether the script engine can be cached.

Parameters:
scriptEngine - the script engine to check.
Returns:
true if the script engine may be cached.

configureGroovyScriptEngine

protected void configureGroovyScriptEngine(ScriptEngine scriptEngine)
Allows providing custom configuration for the groovy script engine.

Parameters:
scriptEngine - the groovy script engine to configure.

createBindings

public Bindings createBindings(ScriptEngine scriptEngine,
                               VariableScope variableScope)
override to build a spring aware ScriptingEngines

Parameters:
engineBindings -
scriptEngine -

getScriptBindingsFactory

public ScriptBindingsFactory getScriptBindingsFactory()

setScriptBindingsFactory

public void setScriptBindingsFactory(ScriptBindingsFactory scriptBindingsFactory)


Copyright © 2015 camunda services GmbH. All rights reserved.