當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。