本文整理汇总了Java中javax.script.ScriptContext.getBindings方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptContext.getBindings方法的具体用法?Java ScriptContext.getBindings怎么用?Java ScriptContext.getBindings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.script.ScriptContext
的用法示例。
在下文中一共展示了ScriptContext.getBindings方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.script.ScriptContext; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
final ScriptEngineManager manager = new ScriptEngineManager();
final ScriptEngine engine = manager.getEngineByName("nashorn");
engine.put("x", "hello");
// print global variable "x"
engine.eval("print(x);");
// the above line prints "hello"
// Now, pass a different script context
final ScriptContext newContext = new SimpleScriptContext();
newContext.setBindings(engine.createBindings(), ScriptContext.ENGINE_SCOPE);
final Bindings engineScope = newContext.getBindings(ScriptContext.ENGINE_SCOPE);
// add new variable "x" to the new engineScope
engineScope.put("x", "world");
// execute the same script - but this time pass a different script context
engine.eval("print(x);", newContext);
// the above line prints "world"
}
示例2: userEngineScopeBindingsRetentionTest
import javax.script.ScriptContext; //导入方法依赖的package包/类
@Test
public void userEngineScopeBindingsRetentionTest() throws ScriptException {
final ScriptEngineManager m = new ScriptEngineManager();
final ScriptEngine e = m.getEngineByName("nashorn");
final ScriptContext newContext = new SimpleScriptContext();
newContext.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);
e.eval("function foo() {}", newContext);
// definition retained with user's ENGINE_SCOPE Binding
assertTrue(e.eval("typeof foo", newContext).equals("function"));
final Bindings oldBindings = newContext.getBindings(ScriptContext.ENGINE_SCOPE);
// but not in another ENGINE_SCOPE binding
newContext.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);
assertTrue(e.eval("typeof foo", newContext).equals("undefined"));
// restore ENGINE_SCOPE and check again
newContext.setBindings(oldBindings, ScriptContext.ENGINE_SCOPE);
assertTrue(e.eval("typeof foo", newContext).equals("function"));
}
示例3: RsrcLoader
import javax.script.ScriptContext; //导入方法依赖的package包/类
RsrcLoader(FileObject fo, ScriptContext map) {
this.fo = fo;
this.map = map;
this.engineScope = map.getBindings(ScriptContext.ENGINE_SCOPE);
setTemplateLoader(this);
setTemplateExceptionHandler(this);
Logger.getLogger("freemarker.runtime").setLevel(Level.OFF);
}
示例4: RenderContextImpl
import javax.script.ScriptContext; //导入方法依赖的package包/类
private RenderContextImpl(ScriptContext scriptContext, SlingScriptHelper helper) {
bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
extensionRegistryService = helper.getService(ExtensionRegistryService.class);
}