List of usage examples for javax.script Bindings put
public Object put(String name, Object value);
From source file:org.apache.sling.scripting.javascript.internal.RhinoJavaScriptEngine.java
private void getBoundProperties(Scriptable scope, Bindings bindings) { Object[] ids = scope.getIds(); for (Object id : ids) { if (id instanceof String) { String key = (String) id; Object value = scope.get(key, scope); if (value != Scriptable.NOT_FOUND) { if (value instanceof Wrapper) { bindings.put(key, ((Wrapper) value).unwrap()); } else { bindings.put(key, value); }//from w w w . ja va 2 s . c o m } } } }
From source file:org.ow2.parserve.PARServeEngine.java
/** * Retrieve another binding from the engine, such as selection, control flow, etc *///from w w w. j av a 2 s . c o m private void retrieveOtherVariable(String variableName, ScriptContext ctx, Bindings bindings) { if (!serverEval) { // in case the SelectionScript result is assigned in the engine, retrieve it REXP ssResultRexp = engine.engineGet(variableName, ctx); if (ssResultRexp != null) { bindings.put(variableName, engine.engineCast(ssResultRexp, null, ctx)); } } }
From source file:org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutorTest.java
@Test public void shouldEvalScriptWithBindings() throws Exception { final GremlinExecutor gremlinExecutor = GremlinExecutor.build().create(); final Bindings b = new SimpleBindings(); b.put("x", 1); assertEquals(2, gremlinExecutor.eval("1+x", b).get()); gremlinExecutor.close();/*from w w w . j av a2 s .c o m*/ }
From source file:org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutorTest.java
@Test public void shouldEvalScriptWithGlobalBindings() throws Exception { final Bindings b = new SimpleBindings(); b.put("x", 1); final GremlinExecutor gremlinExecutor = GremlinExecutor.build().globalBindings(b).create(); assertEquals(2, gremlinExecutor.eval("1+x").get()); gremlinExecutor.close();//from w ww . j ava 2s. co m }
From source file:org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutorTest.java
@Test public void shouldEvalScriptWithGlobalAndLocalBindings() throws Exception { final Bindings g = new SimpleBindings(); g.put("x", 1); final GremlinExecutor gremlinExecutor = GremlinExecutor.build().globalBindings(g).create(); final Bindings b = new SimpleBindings(); b.put("y", 1); assertEquals(2, gremlinExecutor.eval("y+x", b).get()); gremlinExecutor.close();//from w w w . jav a 2 s . c om }
From source file:org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutorTest.java
@Test public void shouldEvalScriptWithLocalOverridingGlobalBindings() throws Exception { final Bindings g = new SimpleBindings(); g.put("x", 1); final GremlinExecutor gremlinExecutor = GremlinExecutor.build().globalBindings(g).create(); final Bindings b = new SimpleBindings(); b.put("x", 10); assertEquals(11, gremlinExecutor.eval("x+1", b).get()); gremlinExecutor.close();/* w w w . ja va 2 s. c o m*/ }
From source file:org.nuxeo.ecm.webengine.DefaultWebContext.java
protected void initDefaultBindings(Bindings bindings) { bindings.put("Context", this); bindings.put("Request", request); bindings.put("Response", response); bindings.put("This", getTargetObject()); bindings.put("Root", getFirstObject()); bindings.put("Document", getTargetDocument()); bindings.put("Engine", engine); bindings.put("basePath", getBasePath()); bindings.put("appPath", getApplicationPath()); try {//from w w w . j a v a2 s. c om bindings.put("Session", getCoreSession()); } catch (Exception e) { e.printStackTrace(); // TODO } }
From source file:de.xwic.appkit.webbase.editors.EditorContext.java
/** * @param input//from w w w.ja v a 2 s . c o m * @throws ConfigurationException * @throws EntityModelException */ public EditorContext(GenericEditorInput input, String langId) throws ConfigurationException, EntityModelException { this.input = input; this.config = input.getConfig(); this.bundle = config.getEntityType().getDomain().getBundle(langId); this.model = EntityModelFactory.createModel(input.getEntity()); this.dirty = input.getEntity().getId() == 0; // is a new entity. DAO<?> dao = DAOSystem.findDAOforEntity(config.getEntityType().getClassname()); this.editable = dao.hasRight(input.getEntity(), "UPDATE") && !input.getEntity().isDeleted() && !(input.getEntity() instanceof IHistory); scriptEngine = ScriptEngineProvider.instance() .createEngine("Editor(" + config.getEntityType().getId() + ":" + config.getId() + ")"); Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE); bindings.put("entity", model); bindings.put("bundle", bundle); bindings.put("ctx", this); try { if (config.getGlobalScript() != null && !config.getGlobalScript().trim().isEmpty()) { scriptEngine.eval(config.getGlobalScript()); } } catch (ScriptException se) { initErrors.add("ScriptException in GlobalScript for editor configuration (" + se + ")"); log.error("Error evaluating global script in Editor(" + config.getEntityType() + ":" + config.getId() + ")", se); } final String entityType = getEntityDescriptor().getClassname(); final List<IEditorListenerFactory> listenerExtensions = EditorExtensionUtils .getExtensions(EP_EDITOR_LISTENER, entityType); for (IEditorListenerFactory listenerExtension : listenerExtensions) { EditorListener editorListener = listenerExtension.createListener(); addEditorListener(editorListener); } }
From source file:org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutorTest.java
@Test public void shouldAllowVariableReuseAcrossThreads() throws Exception { final ExecutorService service = Executors.newFixedThreadPool(8, testingThreadFactory); final GremlinExecutor gremlinExecutor = GremlinExecutor.build().create(); final AtomicBoolean failed = new AtomicBoolean(false); final int max = 512; final List<Pair<Integer, List<Integer>>> futures = Collections.synchronizedList(new ArrayList<>(max)); IntStream.range(0, max).forEach(i -> { final int yValue = i * 2; final Bindings b = new SimpleBindings(); b.put("x", i); b.put("y", yValue); final int zValue = i * -1; final String script = "z=" + zValue + ";[x,y,z]"; try {//from w w w.ja v a2s . c o m service.submit(() -> { try { final List<Integer> result = (List<Integer>) gremlinExecutor.eval(script, b).get(); futures.add(Pair.with(i, result)); } catch (Exception ex) { failed.set(true); } }); } catch (Exception ex) { throw new RuntimeException(ex); } }); service.shutdown(); assertThat(service.awaitTermination(60000, TimeUnit.MILLISECONDS), is(true)); // likely a concurrency exception if it occurs - and if it does then we've messed up because that's what this // test is partially designed to protected against. assertThat(failed.get(), is(false)); assertEquals(max, futures.size()); futures.forEach(t -> { assertEquals(t.getValue0(), t.getValue1().get(0)); assertEquals(t.getValue0() * 2, t.getValue1().get(1).intValue()); assertEquals(t.getValue0() * -1, t.getValue1().get(2).intValue()); }); }
From source file:org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutorTest.java
@Test public void shouldGetGlobalBindings() throws Exception { final Bindings b = new SimpleBindings(); final Object bound = new Object(); b.put("x", bound); final GremlinExecutor gremlinExecutor = GremlinExecutor.build().globalBindings(b).create(); assertEquals(bound, gremlinExecutor.getGlobalBindings().get("x")); gremlinExecutor.close();//from w ww. j a va 2 s . c o m }