当前位置: 首页>>代码示例>>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;未经允许,请勿转载。