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