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


Java ScriptContext.getBindings方法代碼示例

本文整理匯總了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"
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:MultiScopes.java

示例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"));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:ScopeTest.java

示例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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:RsrcLoader.java

示例4: RenderContextImpl

import javax.script.ScriptContext; //導入方法依賴的package包/類
private RenderContextImpl(ScriptContext scriptContext, SlingScriptHelper helper) {
    bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
    extensionRegistryService = helper.getService(ExtensionRegistryService.class);
}
 
開發者ID:deepthinkit,項目名稱:patternlab-for-sling,代碼行數:5,代碼來源:RenderContextImpl.java


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