当前位置: 首页>>代码示例>>Java>>正文


Java CompiledScript.getEngine方法代码示例

本文整理汇总了Java中javax.script.CompiledScript.getEngine方法的典型用法代码示例。如果您正苦于以下问题:Java CompiledScript.getEngine方法的具体用法?Java CompiledScript.getEngine怎么用?Java CompiledScript.getEngine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.script.CompiledScript的用法示例。


在下文中一共展示了CompiledScript.getEngine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeScript

import javax.script.CompiledScript; //导入方法依赖的package包/类
/**
 * Executes a compiled script and returns the result.
 * 
 * @param script Compiled script.
 * @param functionName Optional function or method to invoke.
 * @param scriptContext Script execution context.
 * @return The script result.
 * @throws IllegalArgumentException
 */
public static Object executeScript(CompiledScript script, String functionName, ScriptContext scriptContext, Object[] args) throws ScriptException, NoSuchMethodException {
    Assert.notNull("script", script, "scriptContext", scriptContext);
    Object result = script.eval(scriptContext);
    if (UtilValidate.isNotEmpty(functionName)) {
        if (Debug.verboseOn()) {
            Debug.logVerbose("Invoking function/method " + functionName, module);
        }
        ScriptEngine engine = script.getEngine();
        try {
            Invocable invocableEngine = (Invocable) engine;
            result = invocableEngine.invokeFunction(functionName, args == null ? EMPTY_ARGS : args);
        } catch (ClassCastException e) {
            throw new ScriptException("Script engine " + engine.getClass().getName() + " does not support function/method invocations");
        }
    }
    return result;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:27,代码来源:ScriptUtil.java

示例2: main

import javax.script.CompiledScript; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName("JavaScript");

    engine.eval(new FileReader("src/main/javascript/Example.js"));

    Compilable compilingEngine = (Compilable) engine;
    CompiledScript script = compilingEngine.compile(new FileReader(
            "src/main/javascript/Function.js"));

    Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
    bindings.put("date", new Date());
    bindings.put("out", System.out);
    for (Map.Entry me : bindings.entrySet()) {
        System.out.printf("%s: %s\n", me.getKey(),
                String.valueOf(me.getValue()));
    }
    script.eval(bindings);

    Invocable invocable = (Invocable) script.getEngine();
    invocable.invokeFunction("sayhello", "Jose");
}
 
开发者ID:RockManJoe64,项目名称:fixprotocol-test-suite,代码行数:23,代码来源:ScriptRunner.java


注:本文中的javax.script.CompiledScript.getEngine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。