Package javax.script

Examples of javax.script.ScriptContext


    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


        }
        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);
        if (exchange.hasOut()) {
            context.setAttribute("response", exchange.getOut(), scope);
        }
    }
View Full Code Here

        }
        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("camelContext", exchange.getContext(), scope);
        context.setAttribute("exchange", exchange, scope);
        Message in = exchange.getIn();
        context.setAttribute("request", in, scope);
        context.setAttribute("headers", in.getHeaders(), scope);
        context.setAttribute("body", in.getBody(), scope);
        if (exchange.hasOut()) {
            Message out = exchange.getOut();
            context.setAttribute("out", out , scope);
            context.setAttribute("response", out, scope);
        }
        // to make using properties component easier
        context.setAttribute("properties", new ScriptPropertiesFunction(exchange.getContext()), scope);
    }
View Full Code Here

        }
        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);
        if (exchange.hasOut()) {
            context.setAttribute("response", exchange.getOut(), scope);
        }
        // to make using properties component easier
        context.setAttribute("properties", new ScriptPropertiesFunction(exchange.getContext()), scope);
    }
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

      Object obj = null;

      /* Initialize the script engine */
      ScriptEngineManager m = new ScriptEngineManager();
      ScriptEngine rubyEngine = m.getEngineByName("jruby");
      ScriptContext scriptContext = rubyEngine.getContext();
      Invocable rubyInvocableEngine = (Invocable) rubyEngine;

      /*
       * Sample 1 : Pass a parameter to the JRuby script that display the
       * value of the parameter passed
       */

      System.out.println("###SAMPLE 1");
      scriptContext.setAttribute("param_from_java", "MyParamValue",
          ScriptContext.ENGINE_SCOPE);
      scriptReader = new FileReader(
          "JRubyScripts/test_param_java_ruby.rb");
      rubyEngine.eval(scriptReader, scriptContext);
      scriptReader.close();

      /*
       * Sample 2 : Pass a parameter to the JRuby script that modify the
       * parameter and return it
       */

      System.out.println("###SAMPLE 2");
      scriptContext.setAttribute("param_from_java", "MyParamValue",
          ScriptContext.ENGINE_SCOPE);
      scriptReader = new FileReader(
          "JRubyScripts/test_param_java_ruby_with_return.rb");
      obj = rubyEngine.eval(scriptReader, scriptContext);
      scriptReader.close();
      System.out
          .printf(
              "Parameter before script call '%s' and after script call '%s'\n",
              "MyParamValue", obj);

      /*
       * Sample 3 : Call a JRuby script to obtain a object (thread
       * subclass defined in JRuby script)
       */

      System.out.println("###SAMPLE 3");
      scriptContext.removeAttribute("param_from_java",
          ScriptContext.ENGINE_SCOPE);
      scriptReader = new FileReader(
          "JRubyScripts/test_param_ruby_java_with_return.rb");
      obj = rubyEngine.eval(scriptReader, scriptContext);
      Thread thread = (Thread) obj;
View Full Code Here

      ScriptEngineManager mgr = new ScriptEngineManager();
      return mgr.getEngineByName(ENGINE_NAME);
   }

   private ScriptContext createScope() {
      ScriptContext scriptContext = context.getContext();
      scriptContext.setBindings(context.createBindings(), ScriptContext.ENGINE_SCOPE);
      return scriptContext;
   }
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.