當前位置: 首頁>>代碼示例>>Java>>正文


Java ScriptEngine.getBindings方法代碼示例

本文整理匯總了Java中javax.script.ScriptEngine.getBindings方法的典型用法代碼示例。如果您正苦於以下問題:Java ScriptEngine.getBindings方法的具體用法?Java ScriptEngine.getBindings怎麽用?Java ScriptEngine.getBindings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.script.ScriptEngine的用法示例。


在下文中一共展示了ScriptEngine.getBindings方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: executeJsExpress

import javax.script.ScriptEngine; //導入方法依賴的package包/類
/**
 * 執行js表達式並返回執行後的結果
 * @param express
 * 表達式
 * @param value
 * 原值
 * @return
 * 返回新值或返回原值(執行失敗時)
 */
public static Object executeJsExpress(String express, Object value){
    Object newValue = value;
    if(!StringUtils.isEmpty(express)){
        try {
            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByName("nashorn");
            engine.put("value", value);
            engine.put("newValue", "");
            engine.getBindings(ScriptContext.ENGINE_SCOPE);
            engine.eval(express);
            newValue = engine.get("newValue");
        } catch (ScriptException e) {
            log.error("執行js表達式錯誤",e);
        }
    }

    return newValue;
}
 
開發者ID:DevopsJK,項目名稱:SuitAgent,代碼行數:28,代碼來源:MetricsCommon.java

示例2: megamorphicPropertyReadTest

import javax.script.ScriptEngine; //導入方法依賴的package包/類
@Test
public void megamorphicPropertyReadTest() throws ScriptException {
    final NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
    final ScriptEngine engine = factory.getScriptEngine();
    final Bindings scope = engine.getBindings(ScriptContext.ENGINE_SCOPE);
    boolean ret;

    // Why 16 is the upper limit of this loop? The default nashorn dynalink megamorphic threshold is 16.
    // See jdk.nashorn.internal.runtime.linker.Bootstrap.NASHORN_DEFAULT_UNSTABLE_RELINK_THRESHOLD
    // We do, 'eval' of the same in this loop twice. So, 16*2 = 32 times that callsite in the script
    // is exercised - much beyond the default megamorphic threshold.

    for (int i = 0; i < 16; i++) {
        scope.remove(VAR_NAME);
        ret = lookupVar(engine, VAR_NAME);
        assertFalse(ret, "Expected false in iteration " + i);
        scope.put(VAR_NAME, "foo");
        ret = lookupVar(engine, VAR_NAME);
        assertTrue(ret, "Expected true in iteration " + i);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:ScopeTest.java

示例3: syncBindings

import javax.script.ScriptEngine; //導入方法依賴的package包/類
private void syncBindings(ScriptEngine scriptEngine, ScriptLanguage scriptLanguage) {

	Bindings currentBindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
	this.scriptEngines.forEach((String name, ScriptEngine engine) -> {
	    Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
	    currentBindings.keySet().forEach((String key) -> {
		bindings.put(key, scriptLanguage.decode(currentBindings.get(key)));
	    });
	});

    }
 
開發者ID:scijava,項目名稱:scijava-jupyter-kernel,代碼行數:12,代碼來源:Worker.java

示例4: initBindings

import javax.script.ScriptEngine; //導入方法依賴的package包/類
private void initBindings(Bindings bindings, ScriptEngine scriptEngine, ScriptLanguage scriptLanguage) {

        Bindings currentBindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
        bindings.keySet().forEach((String key) -> {
            currentBindings.put(key, scriptLanguage.decode(bindings.get(key)));
        });

    }
 
開發者ID:scijava,項目名稱:scijava-jupyter-kernel,代碼行數:9,代碼來源:ScijavaEvaluator.java


注:本文中的javax.script.ScriptEngine.getBindings方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。