Package javax.script

Examples of javax.script.Bindings


    }

    @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());
    }
View Full Code Here


        assertEquals(2, gremlinExecutor.eval("1+x", b).get());
    }

    @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());
    }
View Full Code Here

            new File(getClass().getResource("/org/jooq/example/test").toURI()).listFiles((dir, name) -> name.endsWith(".js"))
        ).forEach(file -> {
            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByName("nashorn");

            Bindings bindings = engine.getBindings(ENGINE_SCOPE);
            bindings.put("connection", connection);

            try {
                engine.eval(new FileReader(file));
            }
            catch (Exception e) {
View Full Code Here

                        throw new SerializationException(attribute.localName + " is not a valid"
                            + " attribute for the " + WTKX_PREFIX + ":" + SCRIPT_TAG + " tag.");
                    }
                }

                Bindings bindings;
                if (element.parent.value instanceof ListenerList<?>) {
                    // Don't pollute the engine namespace with the listener functions
                    bindings = new SimpleBindings();
                } else {
                    bindings = scriptEngineManager.getBindings();
View Full Code Here

        public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
            Object result = null;

            String methodName = method.getName();
            Bindings bindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
            if (bindings.containsKey(methodName)) {
                Invocable invocable;
                try {
                    invocable = (Invocable)scriptEngine;
                } catch (ClassCastException exception) {
                    throw new SerializationException(exception);
View Full Code Here

    final ScriptEngine scriptEngine = engines.get(language);

    if (scriptEngine == null)
      throw new OCommandScriptException("Cannot find script engine: " + language);

    final Bindings binding = scriptEngine.createBindings();

    // BIND FIXED VARIABLES
    binding.put("db", database);

    // BIND PARAMETERS INTO THE SCRIPT
    if (iArgs != null)
      for (int i = 0; i < iArgs.size(); ++i) {
        binding.put("$" + i, iArgs.get(i));
      }

    try {
      Object result = null;
      result = scriptEngine.eval(script, binding);
View Full Code Here

    final ScriptEngine scriptEngine = engines.get(language);

    if (scriptEngine == null)
      throw new OCommandScriptException("Cannot find script engine: " + language);

    final Bindings binding = scriptEngine.createBindings();

    // BIND FIXED VARIABLES
    binding.put("db", database);

    // BIND PARAMETERS INTO THE SCRIPT
    if (iArgs != null)
      for (int i = 0; i < iArgs.size(); ++i) {
        binding.put("$" + i, iArgs.get(i));
      }

    try {
      Object result = null;
      result = scriptEngine.eval(script, binding);
View Full Code Here

      return envVar;

    Object value = _scriptContext.getAttribute(name.toString());

    if (value == null) {
      Bindings bindings
        = _scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);

      if (bindings != null)
        value = bindings.get(name.toString());
    }

    if (value == null) {
      Bindings bindings
      = _scriptContext.getBindings(ScriptContext.GLOBAL_SCOPE);

      if (bindings != null)
        value = bindings.get(name.toString());
    }

    if (value != null) {
      envVar = new EnvVarImpl(new Var());
View Full Code Here

        try {
            new TestScriptEngine(null);
            fail("Should have thrown NPE");
        } catch (NullPointerException expected) {
        }
        Bindings b = new SimpleBindings();
        new TestScriptEngine(b); // should be OK
    }
View Full Code Here

            engine.setBindings(null, ScriptContext.ENGINE_SCOPE);
            fail("Should have generated NPE");
        } catch (NullPointerException e) {
        }
        engine.setBindings(null, ScriptContext.GLOBAL_SCOPE); // should be OK
        Bindings bindings = new SimpleBindings();
        engine.setBindings(bindings , ScriptContext.ENGINE_SCOPE);
        engine.setBindings(bindings , ScriptContext.GLOBAL_SCOPE);
    }
View Full Code Here

TOP

Related Classes of javax.script.Bindings

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.