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