Package javax.script

Examples of javax.script.Bindings


    @Override
    public AssertionResult getResult(SampleResult response) {
        AssertionResult result = new AssertionResult(getName());
        try {
            ScriptEngine scriptEngine = getScriptEngine();
            Bindings bindings = scriptEngine.createBindings();
            bindings.put("SampleResult", response);
            bindings.put("AssertionResult", result);
            processFileOrScript(scriptEngine, bindings);
            result.setError(false);
        } catch (IOException e) {
            log.error("Problem in JSR223 script ", e);
            result.setError(true);
View Full Code Here


        }
        result.setDataType(SampleResult.TEXT);
        result.sampleStart();
        try {
            ScriptEngine scriptEngine = getScriptEngine();
            Bindings bindings = scriptEngine.createBindings();
            bindings.put("SampleResult",result);
            Object ret = processFileOrScript(scriptEngine, bindings);
            if (ret != null && (result.getResponseData() == null || result.getResponseData()==SampleResult.EMPTY_BA)){
                result.setResponseData(ret.toString(), null);
            }
        } catch (IOException e) {
View Full Code Here

    public void testMethodIndirection() throws Exception {
        PythonScriptEngineInitializer initializer = new PythonScriptEngineInitializer();
        ScriptEngine engine = initializer.instantiate(Collections.<String> emptySet(), null);

        Bindings bindings = engine.createBindings();
        Tester tester = new Tester();
        bindings.put("tester", tester);

        engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE);

        engine.eval("tester.increment()");
View Full Code Here

        return history;
    }

    public boolean isDefined(String identifier) {
        Bindings engineBindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
        Bindings globalBindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);

        return engineBindings.containsKey(identifier) || globalBindings.containsKey(identifier);
    }
View Full Code Here

    private Subject getSubjectFromEngine() {
        return (Subject) findBinding(StandardBindings.SUBJECT);
    }
   
    private Object findBinding(String identifier) {
        Bindings engineBindings = scriptEngine.getBindings(ScriptContext.ENGINE_SCOPE);
        Bindings globalBindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);

        if (engineBindings.containsKey(identifier)) {
            return engineBindings.get(identifier);
        } else {
            return globalBindings.get(identifier);
        }
    }
View Full Code Here

            if (arg instanceof Wrapper) {
                arg = ((Wrapper)arg).unwrap();
            }
            if (arg instanceof ExternalScriptable) {
                ScriptContext ctx = ((ExternalScriptable)arg).getContext();
                Bindings bind = ctx.getBindings(ScriptContext.ENGINE_SCOPE);
                return Context.javaToJS(bind,
                           ScriptableObject.getTopLevelScope(thisObj));
            }
        }
        return Context.getUndefinedValue();
View Full Code Here

     */
    public static void injectStandardBindings(ScriptEngine engine, StandardBindings bindings,
        boolean deleteExistingBindings, ScriptSourceProvider... scriptSourceProviders) {
        bindings.preInject(engine);

        Bindings engineBindings = deleteExistingBindings ? engine.createBindings() : engine
            .getBindings(ScriptContext.ENGINE_SCOPE);

        for (Map.Entry<String, Object> entry : bindings.entrySet()) {
            engineBindings.put(entry.getKey(), entry.getValue());
        }

        if (scriptSourceProviders != null) {
            //first figure out which initializer to use with this script engine
            String language = (String) engine.getFactory().getParameter(ScriptEngine.NAME);
View Full Code Here

     * @param engine the engine
     * @param keySet the binding keys to be removed
     */
    public static void removeBindings(ScriptEngine engine, Set<RhqManager> keySet) {

        Bindings engineBindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);

        for (RhqManager key : keySet) {
            engineBindings.remove(key.name());
        }

        engine.setBindings(engineBindings, ScriptContext.ENGINE_SCOPE);
    }
View Full Code Here

    private Map<String, Object> getContextMatches(String start) {
        Map<String, Object> found = new HashMap<String, Object>();
        if (context != null) {
            for (Integer scope : context.getScopes()) {
                Bindings bindings = context.getBindings(scope);
                for (String var : bindings.keySet()) {
                    if (var.startsWith(start)) {
                        found.put(var, bindings.get(var));
                    }
                }
            }
        }
View Full Code Here

     */
    private Map<String, Object> getContextMatches(String start, Class<?> typeFilter) {
        Map<String, Object> found = new HashMap<String, Object>();
        if (context != null) {
            for (int scope : context.getScopes()) {
                Bindings bindings = context.getBindings(scope);
                for (String var : bindings.keySet()) {
                    if (var.startsWith(start)) {

                        if ((bindings.get(var) != null && typeFilter.isAssignableFrom(bindings.get(var).getClass()))
                            || recomplete == 3) {
                            found.put(var, bindings.get(var));
                        }
                    }
                }
            }

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.