Package javax.script

Examples of javax.script.Bindings


        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


        }

        @Override
        public Object evaluate(final Object value) {
            Object result = value;
            Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);
            if (bindings.containsKey(functionName)) {
                Invocable invocable;
                try {
                    invocable = (Invocable)scriptEngine;
                } catch (ClassCastException exception) {
                    throw new RuntimeException(exception);
View Full Code Here

  @Override
  public void execute(StringBuffer out, Map<String, Object> attributes) {
        ScriptEngine engine = manager.getEngineByName ("js");
        try {
          if (attributes != null) {
            Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
            for (Map.Entry<String, Object> entry : attributes.entrySet())
              bindings.put(entry.getKey(), entry.getValue());
          }
      Object ret = engine.eval(part);
      if (ret != null) {
        out.append(ret);
      }
View Full Code Here

    // get script engine
    ScriptEngine scriptEngine = scriptingEngines.getScriptEngineForLanguage(scriptLanguage);

    // get bindings
    Bindings bindings = scriptingEngines.createBindings(scriptEngine, scope);

    // first, evaluate the env scripts (if any)
    List<ExecutableScript> envScripts = getEnvScripts(scriptLanguage);
    for (ExecutableScript envScript : envScripts) {
      envScript.execute(scriptEngine, scope, bindings);
View Full Code Here

  private void executeScript() {
    if (scriptEngine != null) {
      try {
        String environment = SpinScriptEnv.get(scriptEngine.getFactory().getLanguageName());

        Bindings bindings = new SimpleBindings(variables);
        LOG.executeScriptWithScriptEngine(scriptPath, scriptEngine.getFactory().getEngineName());
        scriptEngine.eval(environment, bindings);
        scriptEngine.eval(script, bindings);
      } catch (ScriptException e) {
        throw LOG.scriptExecutionError(scriptPath, e);
View Full Code Here

        CompiledScript script = calloutCache_.get(callout);
        if ( script != null )
        {
            try
            {
                Bindings binding = new SimpleBindings();
                binding.put("args", args);
                result = script.eval(binding);
            }
            catch(ScriptException ex)
            {
                logger_.warn(LogUtil.throwableToString(ex));
View Full Code Here

        // select the gremlin threadpool to execute the script evaluation in
        final AtomicBoolean abort = new AtomicBoolean(false);
        final CompletableFuture<Object> future = CompletableFuture.supplyAsync(() -> {

            final Bindings bindings = new SimpleBindings();
            bindings.putAll(this.globalBindings);
            bindings.putAll(boundVars);

            try {
                logger.debug("Evaluating script - {} - in thread [{}]", script, Thread.currentThread().getName());

                beforeEval.accept(bindings);
View Full Code Here

                        hasErrors.set(true);
                        return Pair.with(f, Optional.<FileReader>empty());
                    }
                }).filter(p -> p.getValue1().isPresent()).map(p -> Pair.with(p.getValue0(), p.getValue1().get())).forEachOrdered(p -> {
                    try {
                        final Bindings bindings = new SimpleBindings();
                        bindings.putAll(this.globalBindings);

                        // evaluate init scripts with hard reference so as to ensure it doesn't get garbage collected
                        bindings.put(GremlinGroovyScriptEngine.KEY_REFERENCE_TYPE, GremlinGroovyScriptEngine.REFERENCE_TYPE_HARD);

                        se.eval(p.getValue1(), bindings, language);

                        // re-assign graph bindings back to global bindings.  prevent assignment of non-graph
                        // implementations just in case someone tries to overwrite them in the init
                        bindings.entrySet().stream()
                                .filter(kv -> kv.getValue() instanceof Graph)
                                .forEach(kv -> this.globalBindings.put(kv.getKey(), kv.getValue()));

                        logger.info("Initialized {} ScriptEngine with {}", language, p.getValue0());
                    } catch (ScriptException sx) {
View Full Code Here

    public void shouldProperlyHandleBindings() throws Exception {
        final ScriptEngine engine = new GremlinGroovyScriptEngine();
        engine.put("g", g);
        Assert.assertEquals(g.v(1), engine.eval("g.v(1)"));

        final Bindings bindings = engine.createBindings();
        bindings.put("g", g);
        bindings.put("s", "marko");
        bindings.put("f", 0.5f);
        bindings.put("i", 1);
        bindings.put("b", true);
        bindings.put("l", 100l);
        bindings.put("d", 1.55555d);

        Assert.assertEquals(engine.eval("g.E().has('weight',f).next()", bindings), g.e(7));
        Assert.assertEquals(engine.eval("g.V().has('name',s).next()", bindings), g.v(1));
        Assert.assertEquals(engine.eval("g.V().sideEffect{it.get().property('bbb',it.get().value('name')=='marko')}.iterate();g.V().has('bbb',b).next()", bindings), g.v(1));
        Assert.assertEquals(engine.eval("g.V().sideEffect{it.get().property('iii',it.get().value('name')=='marko'?1:0)}.iterate();g.V().has('iii',i).next()", bindings), g.v(1));
View Full Code Here

        for (int i = 0; i < runs; i++) {
            new Thread() {
                public void run() {
                    String name = names.get(random.nextInt(names.size() - 1));
                    try {
                        final Bindings bindings = engine.createBindings();
                        bindings.put("g", g);
                        bindings.put("name", name);
                        final Object result = engine.eval("t = g.V().has('name',name); if(t.hasNext()) { t } else { null }", bindings);
                        if (name.equals("stephen") || name.equals("pavel") || name.equals("matthias"))
                            assertNull(result);
                        else
                            assertNotNull(result);
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.