javax.script.ScriptEngine.setBindings()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(238)

本文整理了Java中javax.script.ScriptEngine.setBindings()方法的一些代码示例,展示了ScriptEngine.setBindings()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ScriptEngine.setBindings()方法的具体详情如下:
包路径:javax.script.ScriptEngine
类名称:ScriptEngine
方法名:setBindings

ScriptEngine.setBindings介绍

[英]Associates the specified bindings with the specified scope.
[中]将指定的绑定与指定的作用域相关联。

代码示例

代码示例来源:origin: looly/hutool

@Override
public void setBindings(Bindings bindings, int scope) {
  engine.setBindings(bindings, scope);
}

代码示例来源:origin: looly/hutool

@Override
public void setBindings(Bindings bindings, int scope) {
  engine.setBindings(bindings, scope);
}

代码示例来源:origin: looly/hutool

@Override
public void setBindings(Bindings bindings, int scope) {
  engine.setBindings(bindings, scope);
}

代码示例来源:origin: looly/hutool

@Override
public void setBindings(Bindings bindings, int scope) {
  engine.setBindings(bindings, scope);
}

代码示例来源:origin: spring-projects/spring-framework

engine.setBindings(scriptEngineManager.getBindings(), ScriptContext.GLOBAL_SCOPE);

代码示例来源:origin: org.springframework/spring-context

engine.setBindings(scriptEngineManager.getBindings(), ScriptContext.GLOBAL_SCOPE);

代码示例来源:origin: apache/nifi

scriptEngine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);

代码示例来源:origin: apache/nifi

scriptEngine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);

代码示例来源:origin: OpenNMS/opennms

@Override
public void setBindings(Bindings bindings, int scope) {
  engine.setBindings(bindings, scope);
}
@Override

代码示例来源:origin: org.opennms.features/org.opennms.features.osgi-jsr223

@Override
public void setBindings(Bindings bindings, int scope) {
  engine.setBindings(bindings, scope);
}
@Override

代码示例来源:origin: stackoverflow.com

import javax.script.*;

public class ScriptRunner {
  public static void main(String[] args) throws ScriptException {
    ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    ScriptEngine nashorn = scriptEngineManager.getEngineByName("nashorn");
    String scriptName = args[0];
    Bindings bindings = nashorn.createBindings();
    bindings.put("scriptFileName", scriptName);
    nashorn.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
    nashorn.eval("load('src/main/resources/javascript/' + scriptFileName)");
  }

代码示例来源:origin: org.livetribe/livetribe-jsr223

public ScriptEngine getEngineByName(String shortName)
{
  ScriptEngineFactory factory = registeredByName.get(shortName);
  if (factory == null) factory = byName.get(shortName);
  if (factory == null) return null;
  ScriptEngine engine = factory.getScriptEngine();
  engine.setBindings(globalScope, ScriptContext.GLOBAL_SCOPE);
  return engine;
}

代码示例来源:origin: org.apache.myfaces.extensions.cdi.bundles/myfaces-extcdi-bundle-jsf20

/**
 * {@inheritDoc}
 */
public void setBindings(Bindings bindings, int scope)
{
  getScriptEngine().setBindings(bindings, scope);
}

代码示例来源:origin: org.apache.pivot/pivot-core

private static Bindings substituteGlobals(ScriptEngine scriptEngine, final Bindings bindings) {
  Bindings newBindings = bindings;
  Object nashornGlobals = newBindings.get(NASHORN_GLOBAL);
  if (nashornGlobals != null && nashornGlobals instanceof Bindings) {
    newBindings = (Bindings)nashornGlobals;
    scriptEngine.setBindings(newBindings, ScriptContext.ENGINE_SCOPE);
  }
  return newBindings;
}

代码示例来源:origin: org.livetribe/livetribe-jsr223

public ScriptEngine getEngineByExtension(String extension)
{
  ScriptEngineFactory factory = registeredByExtension.get(extension);
  if (factory == null) factory = byExtension.get(extension);
  if (factory == null) return null;
  ScriptEngine engine = factory.getScriptEngine();
  engine.setBindings(globalScope, ScriptContext.GLOBAL_SCOPE);
  return engine;
}

代码示例来源:origin: org.apache.myfaces.extensions.cdi.bundles/myfaces-extcdi-bundle-jsf12

/**
 * {@inheritDoc}
 */
public void setBindings(Bindings bindings, int scope)
{
  getScriptEngine().setBindings(bindings, scope);
}

代码示例来源:origin: vmware/admiral

private void setBindings(Closure closureRequest, ScriptEngine engine) throws ScriptException {
  final Bindings inBindings = engine.createBindings();
  inBindings.put("result", null);
  Map<String, JsonElement> inputs = closureRequest.inputs;
  JsonObject element = new JsonObject();
  if (inputs != null) {
    inputs.forEach(element::add);
    inBindings.put("inputs", convertValue(engine, element));
  }
  engine.setBindings(inBindings, ScriptContext.ENGINE_SCOPE);
}

代码示例来源:origin: purplejs/purplejs

public void init()
{
  this.mocks = Maps.newHashMap();
  this.disposers = Maps.newHashMap();
  this.exportsCache = new ScriptExportsCache();
  this.scriptValueFactory = new ScriptValueFactoryImpl( this.nashornRuntime );
  this.engine = this.nashornRuntime.getEngine();
  this.engine.setBindings( this.global, ScriptContext.GLOBAL_SCOPE );
}

代码示例来源:origin: javadelight/delight-nashorn-sandbox

private void resetEngineBindings() {
  final Bindings bindings = createBindings();
  sanitizeBindings(bindings);
  bindings.putAll(cached);
  scriptEngine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
}

代码示例来源:origin: systems.manifold/manifold-js

public static ScriptEngine init( String programName )
{
 ScriptEngine nashorn = new ScriptEngineManager().getEngineByName( "nashorn" );
 nashorn.setBindings( new ThreadSafeBindings(), ScriptContext.ENGINE_SCOPE );
 Parser parser = new Parser( new Tokenizer( loadSrcForName( programName, JavascriptTypeManifold.JS ) ) );
 Node programNode = parser.parse();
 safe( () -> nashorn.eval( programNode.genCode() ) );
 return nashorn;
}

相关文章