本文整理了Java中javax.script.ScriptEngine.createBindings()
方法的一些代码示例,展示了ScriptEngine.createBindings()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ScriptEngine.createBindings()
方法的具体详情如下:
包路径:javax.script.ScriptEngine
类名称:ScriptEngine
方法名:createBindings
[英]Retrieves an uninitialized Bindings which can be used as the scope of the ScriptEngine.
[中]检索未初始化的绑定,该绑定可用作脚本引擎的作用域。
代码示例来源:origin: looly/hutool
@Override
public Bindings createBindings() {
return engine.createBindings();
}
代码示例来源:origin: looly/hutool
@Override
public Bindings createBindings() {
return engine.createBindings();
}
代码示例来源:origin: looly/hutool
@Override
public Bindings createBindings() {
return engine.createBindings();
}
代码示例来源:origin: looly/hutool
@Override
public Bindings createBindings() {
return engine.createBindings();
}
代码示例来源:origin: apache/incubator-dubbo
/**
* create bindings for script engine
*/
private <T> Bindings createBindings(List<Invoker<T>> invokers, Invocation invocation) {
Bindings bindings = engine.createBindings();
// create a new List of invokers
bindings.put("invokers", new ArrayList<>(invokers));
bindings.put("invocation", invocation);
bindings.put("context", RpcContext.getContext());
return bindings;
}
代码示例来源:origin: apache/incubator-dubbo
/**
* create bindings for script engine
*/
private <T> Bindings createBindings(List<Invoker<T>> invokers, Invocation invocation) {
Bindings bindings = engine.createBindings();
// create a new List of invokers
bindings.put("invokers", new ArrayList<>(invokers));
bindings.put("invocation", invocation);
bindings.put("context", RpcContext.getContext());
return bindings;
}
代码示例来源:origin: Netflix/conductor
public static Object eval(String script, Object input) throws ScriptException {
Bindings bindings = engine.createBindings();
bindings.put("$", input);
return engine.eval(script, bindings);
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
/** override to build a spring aware ScriptingEngines
* @param engineBindin
* @param scriptEngine */
public Bindings createBindings(ScriptEngine scriptEngine, VariableScope variableScope) {
return scriptBindingsFactory.createBindings(variableScope, scriptEngine.createBindings());
}
代码示例来源:origin: camunda/camunda-bpm-platform
/** override to build a spring aware ScriptingEngines
* @param engineBindin
* @param scriptEngine */
public Bindings createBindings(ScriptEngine scriptEngine, VariableScope variableScope) {
return scriptBindingsFactory.createBindings(variableScope, scriptEngine.createBindings());
}
代码示例来源:origin: apache/tinkerpop
@Override
public void write(final NullWritable key, final VertexWritable vertex) throws IOException {
if (null != vertex) {
try {
final Bindings bindings = this.engine.createBindings();
bindings.put(VERTEX, vertex.get());
final String line = (String) engine.eval(WRITE_CALL, bindings);
if (line != null) {
this.out.write(line.getBytes(UTF8));
this.out.write(NEWLINE);
}
} catch (final ScriptException e) {
throw new IOException(e.getMessage(), e);
}
}
}
代码示例来源:origin: neuland/jade4j
@Override
public Object evaluateExpression(String expression, JadeModel model) throws ExpressionException {
try{
Bindings bindings = jsEngine.createBindings();
bindings.putAll(model);
Object eval;
if(expression.startsWith("{")){
eval = ((Map)jsEngine.eval("["+expression+"]", bindings)).get("0");
}else{
eval = jsEngine.eval(expression, bindings);
}
for (Map.Entry<String, Object> stringObjectEntry : bindings.entrySet()) {
model.put(stringObjectEntry.getKey(),convertToJadeModelValue(stringObjectEntry.getValue()));
}
return convertToJadeModelValue(eval);
}
catch (ScriptException ex){
// return expression;
throw new ExpressionException(expression, ex);
}
}
代码示例来源:origin: stackoverflow.com
Bindings bindings = scriptEngine.createBindings();
代码示例来源:origin: apache/tinkerpop
@Override
public boolean nextKeyValue() throws IOException {
while (true) {
if (!this.lineRecordReader.nextKeyValue()) return false;
try {
final Bindings bindings = this.engine.createBindings();
final StarGraph graph = StarGraph.open();
bindings.put(GRAPH, graph);
bindings.put(LINE, this.lineRecordReader.getCurrentValue().toString());
final StarGraph.StarVertex sv = (StarGraph.StarVertex) script.eval(bindings);
if (sv != null) {
final Optional<StarGraph.StarVertex> vertex = sv.applyGraphFilter(this.graphFilter);
if (vertex.isPresent()) {
this.vertexWritable.set(vertex.get());
return true;
}
}
} catch (final ScriptException e) {
throw new IOException(e.getMessage());
}
}
}
代码示例来源:origin: apache/tinkerpop
@Override
public void applyStrategies() throws IllegalStateException {
try {
assert 0 == this.getSteps().size();
final ScriptEngine engine = SingleGremlinScriptEngineManager.get(this.scriptEngine);
final Bindings engineBindings = engine.createBindings();
final List<TraversalStrategy<?>> strategyList = this.getStrategies().toList();
engineBindings.put(this.alias, this.factory.createTraversalSource(this.graph).withStrategies(strategyList.toArray(new TraversalStrategy[strategyList.size()])));
engineBindings.put("graph", this.graph); // TODO: we don't need this as the traversalSource.getGraph() exists, but its now here and people might be using it (remove in 3.3.0)
for (int i = 0; i < this.bindings.length; i = i + 2) {
engineBindings.put((String) this.bindings[i], this.bindings[i + 1]);
}
final Traversal.Admin<S, E> traversal = (Traversal.Admin<S, E>) engine.eval(this.script, engineBindings);
traversal.getSideEffects().mergeInto(this.sideEffects);
traversal.getSteps().forEach(this::addStep);
this.strategies = traversal.getStrategies();
super.applyStrategies();
} catch (final ScriptException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
}
代码示例来源:origin: hugegraph/hugegraph
SingleGremlinScriptEngineManager.get(this.language);
Bindings bindings = engine.createBindings();
bindings.putAll(this.bindings);
代码示例来源:origin: camunda/camunda-bpm-platform
protected Object evaluateScriptExpression(String expressionLanguage, VariableContext variableContext, String expressionText, CachedCompiledScriptSupport cachedCompiledScriptSupport) {
ScriptEngine scriptEngine = getScriptEngineForName(expressionLanguage);
// wrap script engine bindings + variable context and pass enhanced
// bindings to the script engine.
Bindings bindings = VariableContextScriptBindings.wrap(scriptEngine.createBindings(), variableContext);
bindings.put("variableContext", variableContext);
try {
if (scriptEngine instanceof Compilable) {
CompiledScript compiledScript = cachedCompiledScriptSupport.getCachedCompiledScript();
if (compiledScript == null) {
synchronized (cachedCompiledScriptSupport) {
compiledScript = cachedCompiledScriptSupport.getCachedCompiledScript();
if(compiledScript == null) {
Compilable compilableScriptEngine = (Compilable) scriptEngine;
compiledScript = compilableScriptEngine.compile(expressionText);
cachedCompiledScriptSupport.cacheCompiledScript(compiledScript);
}
}
}
return compiledScript.eval(bindings);
}
else {
return scriptEngine.eval(expressionText, bindings);
}
}
catch (ScriptException e) {
throw LOG.unableToEvaluateExpression(expressionText, scriptEngine.getFactory().getLanguageName(), e);
}
}
代码示例来源:origin: OpenNMS/opennms
@Override
public Bindings createBindings() {
return engine.createBindings();
}
@Override
代码示例来源:origin: 58code/Oceanus
@SuppressWarnings("unchecked")
@Override
public T execute(String script, Map<String, Object> parameters)
throws ScriptException {
ScriptEngine scriptEngine = manager.getEngineByName("js");
Bindings binding = scriptEngine.createBindings();
if (parameters != null) {
binding.putAll(parameters);
}
Object val = scriptEngine.eval(script, binding);
return ((T) val);
}
代码示例来源: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: 58code/Oceanus
@Override
public T execute(String script,Map<String, Object> parameters) throws ScriptException {
Bindings bindings = compiledScript.getEngine().createBindings();
if (parameters != null) {
bindings.putAll(parameters);
}
T result = (T) compiledScript.eval(bindings);
return result;
}
内容来源于网络,如有侵权,请联系作者删除!