Search in sources :

Example 81 with SimpleBindings

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;
}
Also used : SimpleBindings(javax.script.SimpleBindings) SimpleBindings(javax.script.SimpleBindings) Bindings(javax.script.Bindings) Date(java.util.Date) ScriptingException(org.springframework.integration.scripting.ScriptingException) ScriptingException(org.springframework.integration.scripting.ScriptingException)

Example 82 with SimpleBindings

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;
}
Also used : SimpleBindings(javax.script.SimpleBindings) ScriptAccessor(org.junit.jupiter.engine.script.ScriptAccessor) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings)

Example 83 with SimpleBindings

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;
}
Also used : SimpleBindings(javax.script.SimpleBindings) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings)

Example 84 with SimpleBindings

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);
}
Also used : ScriptException(javax.script.ScriptException) SimpleScriptContext(javax.script.SimpleScriptContext) SimpleBindings(javax.script.SimpleBindings) SimpleScriptContext(javax.script.SimpleScriptContext) ScriptContext(javax.script.ScriptContext) ScriptEngine(javax.script.ScriptEngine)

Example 85 with SimpleBindings

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);
    }
}
Also used : ScriptException(javax.script.ScriptException) SimpleBindings(javax.script.SimpleBindings) ScriptEngineManager(javax.script.ScriptEngineManager) HashMap(java.util.HashMap) Map(java.util.Map) ScriptEngine(javax.script.ScriptEngine)

Aggregations

SimpleBindings (javax.script.SimpleBindings)102 Bindings (javax.script.Bindings)65 ScriptEngine (javax.script.ScriptEngine)23 Test (org.junit.Test)22 ScriptContext (javax.script.ScriptContext)17 ScriptException (javax.script.ScriptException)17 ScriptEngineManager (javax.script.ScriptEngineManager)16 SimpleScriptContext (javax.script.SimpleScriptContext)15 Test (org.testng.annotations.Test)11 CompiledScript (javax.script.CompiledScript)10 PrintWriter (java.io.PrintWriter)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 SlingBindings (org.apache.sling.api.scripting.SlingBindings)7 File (java.io.File)6 StringWriter (java.io.StringWriter)5 ArrayList (java.util.ArrayList)4 XMLEventReader (javax.xml.stream.XMLEventReader)4 XMLEventWriter (javax.xml.stream.XMLEventWriter)4 XMLInputFactory (javax.xml.stream.XMLInputFactory)4