flowable 6.4.2 - 脚本引擎

.
org.flowable.common.engine.impl.scripting.ScriptingEngines

public class ScriptingEngines {

    public static final String DEFAULT_SCRIPTING_LANGUAGE = "juel";
    public static final String GROOVY_SCRIPTING_LANGUAGE = "groovy";

    private final ScriptEngineManager scriptEngineManager;
    protected ScriptBindingsFactory scriptBindingsFactory;

    protected boolean cacheScriptingEngines = true;
    protected Map cachedEngines;

    public ScriptingEngines(ScriptBindingsFactory scriptBindingsFactory) {
        this(
                /**
                 * 
                 *     @see javax.script.ScriptEngineManager
                 *          @see javax.script.ScriptEngineManager#init(java.lang.ClassLoader)
                 *              @see javax.script.ScriptEngineManager#initEngines(java.lang.ClassLoader)
                 *                  1、加载类路径下实现 javax.script.ScriptEngineFactory 接口的spi类
                 *                      @see org.activiti.engine.impl.scripting.JuelScriptEngineFactory
                 *                      @see org.codehaus.groovy.jsr223.GroovyScriptEngineFactory
                 *                      @see jdk.nashorn.api.scripting.NashornScriptEngineFactory
                 *                      @see org.flowable.engine.impl.scripting.GroovyStaticScriptEngineFactory
                 * 
*/ new ScriptEngineManager() ); this.scriptBindingsFactory = scriptBindingsFactory; } // ... public Object evaluate(String script, String language, VariableScope variableScope, boolean storeScriptVariables) { return evaluate( script, language, /** * 调用 scriptBindingsFactory.createBindings(。。。) */ createBindings(variableScope, storeScriptVariables) ); // !!! } // ... protected Object evaluate(String script, String language, Bindings bindings) { /** * 根据《语言类型》获取脚本引擎 */ ScriptEngine scriptEngine = getEngineByName(language); try { /** *
             *     当为 {@link org.activiti.engine.impl.scripting.JuelScriptEngineFactory#getScriptEngine}
             *          @see org.activiti.engine.impl.scripting.JuelScriptEngine#eval
             *     当为 {@link org.codehaus.groovy.jsr223.GroovyScriptEngineFactory#getScriptEngine}
             *           @see org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
             *     当为 {@link jdk.nashorn.api.scripting.NashornScriptEngineFactory#getScriptEngine}
             *           @see jdk.nashorn.api.scripting.NashornScriptEngine
             *     当为 {@link org.flowable.engine.impl.scripting.GroovyStaticScriptEngineFactory#getScriptEngine}
             *           @see ...
             * 
*/ return scriptEngine.eval(script, bindings); } catch (ScriptException e) { throw new FlowableException("problem evaluating script: " + e.getMessage(), e); } } protected ScriptEngine getEngineByName(String language) { ScriptEngine scriptEngine = null; if (cacheScriptingEngines) { // ... } else { /** * @see javax.script.ScriptEngineManager#getEngineByName(java.lang.String) *
             *     @see org.activiti.engine.impl.scripting.JuelScriptEngineFactory#getScriptEngine
             *     @see org.codehaus.groovy.jsr223.GroovyScriptEngineFactory#getScriptEngine
             *     @see jdk.nashorn.api.scripting.NashornScriptEngineFactory#getScriptEngine
             *     @see org.flowable.engine.impl.scripting.GroovyStaticScriptEngineFactory#getScriptEngine
             * 
*/ scriptEngine = scriptEngineManager.getEngineByName(language); } if (scriptEngine == null) { throw new FlowableException("Can't find scripting engine for '" + language + "'"); } return scriptEngine; } // ... }

使用

// org.flowable.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior#execute
/**
 * 执行脚本
 */
Object result = scriptingEngines.evaluate(script, language, execution, storeScriptVariables);

.

你可能感兴趣的:(bpm&流程引擎,activiti,flowable)