Package javax.script

Examples of javax.script.ScriptContext


        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


            }
        }
    }

    private void setEngineScopeAttributes() {
        final ScriptContext scriptContext = this.engine.getContext();
        scriptContext.setAttribute("jobContext", stepContext.getJobContext(), ScriptContext.ENGINE_SCOPE);
        scriptContext.setAttribute("stepContext", stepContext, ScriptContext.ENGINE_SCOPE);
        scriptContext.setAttribute("batchProperties", Properties.toJavaUtilProperties(artifactProperties), ScriptContext.ENGINE_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);
        }
    }
View Full Code Here

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

    protected Object evaluateScript(Exchange exchange) {
        try {
            // get a new engine which we must for each exchange
            ScriptEngine engine = scriptEngineFactory.getScriptEngine();
            ScriptContext context = populateBindings(engine, exchange, attributes);
            addScriptEngineArguments(engine, exchange);
            Object result = runScript(engine, exchange, context);
            LOG.debug("The script evaluation result is: {}", result);
            return result;
        } catch (ScriptException e) {
View Full Code Here

        }
        return result;
    }

    protected ScriptContext populateBindings(ScriptEngine engine, Exchange exchange, Map<String, Object> attributes) {
        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);
        // any additional attributes
        if (attributes != null) {
            for (Map.Entry<String, Object> entry : attributes.entrySet()) {
                context.setAttribute(entry.getKey(), entry.getValue(), scope);
            }
        }
        return context;
    }
View Full Code Here

            }
        }
    }

    public Object eval(String script, Bindings bindings) throws ScriptException {
        ScriptContext context = getScriptContext(bindings);
        return eval(script, context);
    }
View Full Code Here

        ScriptContext context = getScriptContext(bindings);
        return eval(script, context);
    }

    public Object eval(Reader reader, Bindings bindings) throws ScriptException {
        ScriptContext context = getScriptContext(bindings);
        return eval(reader, context);
    }
View Full Code Here

    protected ScriptContext getScriptContext(Bindings bindings) {
        if (bindings == null) {
            throw new NullPointerException("null bindings in engine scope");
        }

        ScriptContext newContext = new SimpleScriptContext();
        newContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
        Bindings global = getBindings(ScriptContext.GLOBAL_SCOPE);
        if (global != null) {
            newContext.setBindings(global, ScriptContext.GLOBAL_SCOPE);
        }
        newContext.setReader(context.getReader());
        newContext.setWriter(context.getWriter());
        newContext.setErrorWriter(context.getErrorWriter());

        return newContext;
    }
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.