static Bindings getBindings(Map<String, Object> bindings) { return (bindings instanceof Bindings ? (Bindings) bindings : new SimpleBindings(bindings)); }
static Bindings getBindings(Map<String, Object> bindings) { return (bindings instanceof Bindings ? (Bindings) bindings : new SimpleBindings(bindings)); }
public Bindings createBindings() { return new SimpleBindings(); }
public Bindings createBindings() { return new SimpleBindings(); }
@Override public Bindings createBindings() { return new SimpleBindings(); }
@Override public Bindings createBindings() { return new SimpleBindings(); }
@Override public boolean test(Map<String, Object> env) { try { return (Boolean) jsEngine.eval(script, new SimpleBindings(env)); } catch (Exception e) { return false; } } }
/** * Get the {@link Graph} and {@link TraversalSource} list as a set of bindings. */ @Override public Bindings getAsBindings() { final Bindings bindings = new SimpleBindings(); graphs.forEach(bindings::put); traversalSources.forEach(bindings::put); return bindings; }
import javax.script.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); Map<String, Object> vars = new HashMap<String, Object>(); vars.put("x", 2); vars.put("y", 1); vars.put("z", 3); System.out.println("result = "+engine.eval("x + y + z", new SimpleBindings(vars))); } }
public static void main(String[] args) throws ScriptException { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine nashorn = manager.getEngineByName("nashorn"); Bindings bindings = new SimpleBindings(Stream.of( new SimpleEntry<>("a", 10), new SimpleEntry<>("b", 20)) .collect(toMap(SimpleEntry::getKey, SimpleEntry::getValue))); Double eval = (Double) nashorn.eval("a + b", bindings); System.out.println(eval); } }
protected Map<String,String> parseJsonResponse(String json) throws ScriptException { synchronized (scriptEngineLock) { if (scriptEngine == null) { scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript"); if (scriptEngine == null) { throw new RuntimeException("Failed to load JavaScript script engine"); } } Bindings bindings = new SimpleBindings(); bindings.put("json", json); return (Map<String, String>)scriptEngine.eval(JSON_RESPONSE_PARSING_SCRIPT, bindings); } } }
@SuppressWarnings("unchecked") public static <T> T eval(String js, Map<String, ?> bindings) throws ScriptException { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("JavaScript"); if (bindings != null) { Map<String, Object> map = U.cast(bindings); return (T) engine.eval(js, new SimpleBindings(map)); } else { return (T) engine.eval(js); } }
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; }
@SuppressWarnings("unchecked") @Override public <T> T getElValue(String exp, Object target, Object[] arguments, Object retVal, boolean hasRetVal, Class<T> valueType) throws Exception { Bindings bindings = new SimpleBindings(); bindings.put(TARGET, target); bindings.put(ARGS, arguments); if (hasRetVal) { bindings.put(RET_VAL, retVal); } CompiledScript script = expCache.get(exp); if (null != script) { return (T) script.eval(bindings); } if (engine instanceof Compilable) { Compilable compEngine = (Compilable) engine; script = compEngine.compile(funcs + exp); expCache.put(exp, script); return (T) script.eval(bindings); } else { return (T) engine.eval(funcs + exp, bindings); } }
SimpleBindings bindings = new SimpleBindings(); bindings.putAll(model); model.put("renderingContext", context);
CompiledScript script = ((Compilable) scriptEngine).compile(reader); Bindings sb = new SimpleBindings(); script.eval(sb); // Put the Lua functions into the sb environment LuaValue luaDog = CoerceJavaToLua.coerce(dog); // Java to Lua LuaFunction onTalk = (LuaFunction) sb.get("onTalk"); // Get Lua function LuaValue b = onTalk.call(luaDog); // Call the function System.out.println("onTalk answered: " + b); LuaFunction onWalk = (LuaFunction) sb.get("onWalk"); LuaValue[] dogs = { luaDog }; Varargs dist = onWalk.invoke(LuaValue.varargsOf(dogs)); // Alternative System.out.println("onWalk returned: " + dist);
SimpleBindings bindings = new SimpleBindings(); bindings.putAll(model); model.put("renderingContext", context);
SimpleBindings bindings = new SimpleBindings(); bindings.putAll(model); model.put("renderingContext", context);
Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE); if (bindings == null) { bindings = new SimpleBindings();
final Bindings bindings = new SimpleBindings();