Package javax.script

Examples of javax.script.ScriptContext


        }
        if (engine == null) {
            throw new IllegalArgumentException("No script engine could be created for: " + getScriptEngineName());
        }
        if (isPython()) {
            ScriptContext context = engine.getContext();
            context.setAttribute("com.sun.script.jython.comp.mode", "eval", ScriptContext.ENGINE_SCOPE);
        }
        return engine;
    }
View Full Code Here


        }
        return result;
    }

    protected void populateBindings(ScriptEngine engine, Exchange exchange) {
        ScriptContext context = engine.getContext();
        int scope = ScriptContext.ENGINE_SCOPE;
        context.setAttribute("context", exchange.getContext(), scope);
        context.setAttribute("exchange", exchange, scope);
        context.setAttribute("request", exchange.getIn(), scope);
        context.setAttribute("response", exchange.getOut(false), scope);
    }
View Full Code Here

          return 1;
        }
        invoke = true;
      }
     
      ScriptContext ctx = new SimpleScriptContext();
     
      // Put the following objects into the context so that they
      // are available to the scripts
      // TODO: What else should go in here?
      Bindings b = engine.getBindings(ScriptContext.ENGINE_SCOPE);
      b.put("connection", shellState.getConnector());
     
      List<Object> argValues = new ArrayList<Object>();
      if (cl.hasOption(args.getOpt())) {
        String[] argList = cl.getOptionValue(args.getOpt()).split(",");
        for (String arg : argList) {
          String[] parts = arg.split("=");
          if (parts.length == 0) {
            continue;
          } else if (parts.length == 1) {
            b.put(parts[0], null);
            argValues.add(null);
          } else if (parts.length == 2) {
            b.put(parts[0], parts[1]);
            argValues.add(parts[1]);
          }
        }
      }
      ctx.setBindings(b, ScriptContext.ENGINE_SCOPE);
      Object[] argArray = argValues.toArray(new Object[argValues.size()]);
     
      Writer writer = null;
      if (cl.hasOption(out.getOpt())) {
        File f = new File(cl.getOptionValue(out.getOpt()));
        writer = new FileWriter(f);
        ctx.setWriter(writer);
      }
     
      if (cl.hasOption(file.getOpt())) {
        File f = new File(cl.getOptionValue(file.getOpt()));
        if (!f.exists()) {
View Full Code Here

    public Object evaluate(final String language, final String script, final ScriptContext context) throws ScriptException {
        if (!ENGINE_FACTORIES.containsKey(language)) {
            throw new IllegalArgumentException("can't find factory for language " + language + ". You probably need to add the jar to openejb libs.");
        }

        ScriptContext executionContext = context;
        if (executionContext == null) {
            executionContext = new SimpleScriptContext();
        }

        //we bind local variables (per execution) every time we execute a script
View Full Code Here

            }
        }
    }

    protected void populateBindings(ScriptEngine engine, Exchange exchange) {
        ScriptContext context = engine.getContext();
        int scope = ScriptContext.ENGINE_SCOPE;
        context.setAttribute("context", exchange.getContext(), scope);
        context.setAttribute("exchange", exchange, scope);
        context.setAttribute("request", exchange.getIn(), scope);
        context.setAttribute("response", exchange.getOut(), scope);
    }
View Full Code Here

        final ScriptEngineManager manager = new ScriptEngineManager();
        final ScriptEngine engine = manager.getEngineByName((String) this.options.get("engineName"));

        //new context for the execution of this script
        final ScriptContext newContext = new SimpleScriptContext();

        //creating the bidings object for the current execution
        final Bindings bindings = newContext.getBindings(ScriptContext.ENGINE_SCOPE);

        bindings.put("user", this.userData.user);
        bindings.put("password", this.userData.pass);

        final List<String> myGroups;
View Full Code Here

    protected ScriptEngine createScriptEngine() {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName(scriptEngineName);
        if (isPython()) {
            ScriptContext context = engine.getContext();
            context.setAttribute("com.sun.script.jython.comp.mode", "eval", ScriptContext.ENGINE_SCOPE);
        }
        return engine;
    }
View Full Code Here

        }
        return result;
    }

    protected void populateBindings(ScriptEngine engine, Exchange exchange) {
        ScriptContext context = engine.getContext();
        int scope = ScriptContext.ENGINE_SCOPE;
        context.setAttribute("context", exchange.getContext(), scope);
        context.setAttribute("exchange", exchange, scope);
        context.setAttribute("request", exchange.getIn(), scope);
        context.setAttribute("response", exchange.getOut(), scope);
    }
View Full Code Here

  protected Filter filter;
 
  @BeforeClass
  public static void setUpClass() throws Exception {
    SimpleBindings bindings = new SimpleBindings();
    ScriptContext context = new JangodContext(bindings);
    compiler = new JangodInterpreter((Context) context);
  }
View Full Code Here

  }

  @Override
  public Object eval(String script, Bindings n) throws ScriptException {
    TokenParser parser = new TokenParser(script);
    ScriptContext ctx = new JangodContext(factory.globalBindings);
    ctx.setBindings(n, ScriptContext.ENGINE_SCOPE);
    JangodInterpreter interpreter = new JangodInterpreter((Context) ctx);
    try {
      return interpreter.render(parser);
    } catch (InterpretException e) {
      throw new ScriptException(e.getMessage());
View Full Code Here

TOP

Related Classes of javax.script.ScriptContext

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.