本文整理匯總了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;
}
示例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);
}
}
示例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)));
});
});
}
示例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)));
});
}