use of javax.script.SimpleBindings in project spring-integration by spring-projects.
the class AbstractScriptExecutor method executeScript.
@Override
public Object executeScript(ScriptSource scriptSource, Map<String, Object> variables) {
Object result;
try {
String script = scriptSource.getScriptAsString();
Date start = new Date();
if (this.logger.isDebugEnabled()) {
this.logger.debug("executing script: " + script);
}
Bindings bindings = null;
if (variables != null && variables.size() > 0) {
bindings = new SimpleBindings(variables);
result = this.scriptEngine.eval(script, bindings);
} else {
result = this.scriptEngine.eval(script);
}
result = postProcess(result, this.scriptEngine, script, bindings);
if (this.logger.isDebugEnabled()) {
this.logger.debug("script executed in " + (new Date().getTime() - start.getTime()) + " ms");
}
} catch (Exception e) {
throw new ScriptingException(e.getMessage(), e);
}
return result;
}
use of javax.script.SimpleBindings in project junit5 by junit-team.
the class ScriptExecutionEvaluator method createBindings.
private Bindings createBindings(ExtensionContext context) {
ScriptAccessor configurationParameterAccessor = new ScriptAccessor.ConfigurationParameterAccessor(context);
Bindings bindings = new SimpleBindings();
bindings.put(Script.BIND_JUNIT_TAGS, context.getTags());
bindings.put(Script.BIND_JUNIT_UNIQUE_ID, context.getUniqueId());
bindings.put(Script.BIND_JUNIT_DISPLAY_NAME, context.getDisplayName());
bindings.put(Script.BIND_JUNIT_CONFIGURATION_PARAMETER, configurationParameterAccessor);
return bindings;
}
use of javax.script.SimpleBindings in project junit5 by junit-team.
the class ScriptExecutionManagerTests method createDefaultContextBindings.
private Bindings createDefaultContextBindings() {
Bindings bindings = new SimpleBindings();
bindings.put(Script.BIND_JUNIT_TAGS, Collections.emptySet());
bindings.put(Script.BIND_JUNIT_UNIQUE_ID, "Mock for UniqueId");
bindings.put(Script.BIND_JUNIT_DISPLAY_NAME, "Mock for DisplayName");
bindings.put(Script.BIND_JUNIT_CONFIGURATION_PARAMETER, Collections.emptyMap());
return bindings;
}
use of javax.script.SimpleBindings in project CitizensAPI by CitizensDev.
the class ScriptCompiler method run.
public void run(String code, String extension, Map<String, Object> vars) throws ScriptException {
ScriptEngine engine = loadEngine(extension);
if (engine == null)
throw new ScriptException("Couldn't load engine with extension " + extension);
ScriptContext context = new SimpleScriptContext();
if (vars != null) {
context.setBindings(new SimpleBindings(vars), ScriptContext.ENGINE_SCOPE);
}
engine.eval(extension, context);
}
use of javax.script.SimpleBindings in project iep by Netflix.
the class ConfigFile method checkScope.
public static boolean checkScope(Map<String, String> vars, String str) {
ScriptEngineManager mgr = new ScriptEngineManager(null);
ScriptEngine engine = mgr.getEngineByName("javascript");
if (engine == null)
throw new IllegalStateException("no javascipt engine found");
SimpleBindings bindings = new SimpleBindings();
for (Map.Entry<String, String> t : vars.entrySet()) {
bindings.put(t.getKey(), t.getValue());
}
try {
return (Boolean) engine.eval(str, bindings);
} catch (ScriptException e) {
throw new RuntimeException(e);
}
}
Aggregations