本文整理了Java中javax.script.ScriptEngine.getBindings()
方法的一些代码示例,展示了ScriptEngine.getBindings()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ScriptEngine.getBindings()
方法的具体详情如下:
包路径:javax.script.ScriptEngine
类名称:ScriptEngine
方法名:getBindings
[英]Retrieves a reference to the associated bindings for the specified scope. Possible scopes are: GLOBAL_SCOPE : if the ScriptEngine was created by ScriptingEngineManager then GLOBAL_SCOPE of it is returned (or null if there is no GLOBAL_SCOPE stored in the ScriptEngine). ENGINE_SCOPE : the set of key-value pairs stored in the ScriptEngine is returned.
[中]检索对指定范围的关联绑定的引用。可能的作用域包括:全局作用域:如果ScriptEngineManager创建了ScriptEngine,则返回其全局作用域(如果ScriptEngine中没有存储全局作用域,则返回null)。ENGINE_SCOPE:返回存储在ScriptEngine中的键值对集。
代码示例来源:origin: looly/hutool
@Override
public Bindings getBindings(int scope) {
return engine.getBindings(scope);
}
代码示例来源:origin: looly/hutool
@Override
public Bindings getBindings(int scope) {
return engine.getBindings(scope);
}
代码示例来源:origin: looly/hutool
@Override
public Bindings getBindings(int scope) {
return engine.getBindings(scope);
}
代码示例来源:origin: looly/hutool
@Override
public Bindings getBindings(int scope) {
return engine.getBindings(scope);
}
代码示例来源:origin: apache/groovy
private static void retrieveBindingVars(ScriptEngine self, Binding binding) {
Set<Map.Entry<String, Object>> returnVars = self.getBindings(ScriptContext.ENGINE_SCOPE).entrySet();
for (Map.Entry<String, Object> me : returnVars) {
binding.setVariable(me.getKey(), me.getValue());
}
}
代码示例来源:origin: org.junit.jupiter/junit-jupiter-engine
ScriptEngine createScriptEngine(String engine) {
ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(engine);
if (scriptEngine == null) {
scriptEngine = scriptEngineManager.getEngineByExtension(engine);
}
if (scriptEngine == null) {
scriptEngine = scriptEngineManager.getEngineByMimeType(engine);
}
Preconditions.notNull(scriptEngine, () -> "Script engine not found: " + engine);
Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);
bindings.put(Script.BIND_SYSTEM_PROPERTY, systemPropertyAccessor);
bindings.put(Script.BIND_SYSTEM_ENVIRONMENT, environmentVariableAccessor);
return scriptEngine;
}
代码示例来源:origin: apache/nifi
Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
if (bindings == null) {
bindings = new SimpleBindings();
代码示例来源:origin: apache/nifi
Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
if (bindings == null) {
bindings = new SimpleBindings();
代码示例来源:origin: pentaho/pentaho-kettle
jsscope = jscx.getBindings( ScriptContext.ENGINE_SCOPE );
代码示例来源:origin: stackoverflow.com
public class JS {
public static void main(String args[]) throws Exception {
ScriptEngine js = new ScriptEngineManager().getEngineByName("javascript");
Bindings bindings = js.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("stdout", System.out);
js.eval("stdout.println(Math.cos(Math.PI));");
// Prints "-1.0" to the standard output stream.
}
}
代码示例来源:origin: pentaho/pentaho-kettle
data.scope = data.cx.getBindings( ScriptContext.ENGINE_SCOPE );
代码示例来源:origin: schemaspy/schemaspy
protected String toSvg(final String dotSource, int jsEngineMemorySize) {
String fixed = fixPathsAndUrls(dotSource);
try {
scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE).put("dotSource", fixed);
return (String) scriptEngine.eval("Viz(dotSource,options = { totalMemory: "+jsEngineMemorySize
+" , images: [" +
"{ path: \"../../images/foreignKeys.png\"" + ICON_SIZE + " }," +
"{ path: \"../../images/primaryKeys.png\"" + ICON_SIZE + " }]})");
} catch (ScriptException e) {
throw new IllegalArgumentException(e);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy-jsr223
private static void retrieveBindingVars(ScriptEngine self, Binding binding) {
Set<Map.Entry<String, Object>> returnVars = self.getBindings(ScriptContext.ENGINE_SCOPE).entrySet();
for (Map.Entry<String, Object> me : returnVars) {
binding.setVariable(me.getKey(), me.getValue());
}
}
代码示例来源:origin: stackoverflow.com
import java.util.*;
import javax.script.*;
public class TestBindings {
public static void main(String args[]) throws Exception {
String script = "function doSomething() {var d = date}";
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
Compilable compilingEngine = (Compilable) engine;
CompiledScript cscript = compilingEngine.compile(script);
//Bindings bindings = cscript.getEngine().createBindings();
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
for(Map.Entry me : bindings.entrySet()) {
System.out.printf("%s: %s\n",me.getKey(),String.valueOf(me.getValue()));
}
bindings.put("date", new Date());
//cscript.eval();
cscript.eval(bindings);
Invocable invocable = (Invocable) cscript.getEngine();
invocable.invokeFunction("doSomething");
}
}
代码示例来源:origin: apache/accumulo
Bindings b = engine.getBindings(ScriptContext.ENGINE_SCOPE);
putConnector(b, shellState.getAccumuloClient());
b.put("client", shellState.getAccumuloClient());
代码示例来源:origin: rakam-io/rakam
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
代码示例来源:origin: org.scijava/scijava-common
private List<String> engineVariablesCompleter(final String code,
@SuppressWarnings("unused") final int index, final ScriptEngine engine)
{
final List<String> matches = new ArrayList<>();
final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
for (final String key : bindings.keySet()) {
if (key.toLowerCase().startsWith(code.toLowerCase())) {
matches.add(key);
}
}
return matches;
}
代码示例来源:origin: org.apache.myfaces.extensions.cdi.bundles/myfaces-extcdi-bundle-jsf12
/**
* {@inheritDoc}
*/
public Bindings getBindings(int scope)
{
return getScriptEngine().getBindings(scope);
}
代码示例来源:origin: purplejs/purplejs
NashornRuntimeImpl( final ScriptEngine engine )
{
this.engine = engine;
final Bindings bindings = this.engine.getBindings( ScriptContext.ENGINE_SCOPE );
this.arrayProto = (ScriptObjectMirror) bindings.get( "Array" );
this.objectProto = (ScriptObjectMirror) bindings.get( "Object" );
this.jsonProto = (ScriptObjectMirror) bindings.get( "JSON" );
}
代码示例来源:origin: net.sf.jga/jga
public Object eval(Bindings bindings) throws ScriptException {
Bindings oldBindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
try {
return eval(engine.getContext());
}
finally {
engine.setBindings(oldBindings, ScriptContext.ENGINE_SCOPE);
}
}
内容来源于网络,如有侵权,请联系作者删除!