Examples of ScriptContext


Examples of javax.script.ScriptContext

public class AbstractScriptEngineTest extends TestCase {

    private final TestScriptEngine engine  = new TestScriptEngine();

    public void testCtor1(){
        ScriptContext b = engine.getContext();
        assertNotNull(b);
    }
View Full Code Here

Examples of javax.script.ScriptContext

        engine.setBindings(new SimpleBindings(), ScriptContext.GLOBAL_SCOPE);
        assertNotNull(engine.getBindings(ScriptContext.GLOBAL_SCOPE));
    }

    public void testContext(){
        final ScriptContext initial = engine.getContext();
        assertNotNull(initial);
        final SimpleScriptContext newContext = new SimpleScriptContext();
        assertNotSame(initial, newContext);
        engine.setContext(newContext);
        ScriptContext updated = engine.getContext();
        assertNotNull(updated);
        assertSame(updated, newContext);
    }
View Full Code Here

Examples of javax.script.ScriptContext

            engine.getScriptContext(null);
            fail("Should have caused NPE");
        } catch (NullPointerException e) {
        }
        final SimpleBindings bindings = new SimpleBindings();
        ScriptContext sc = engine.getScriptContext(bindings);
        assertEquals(bindings, sc.getBindings(ScriptContext.ENGINE_SCOPE));
        assertNull(sc.getBindings(ScriptContext.GLOBAL_SCOPE));
    }
View Full Code Here

Examples of javax.script.ScriptContext

            Map<String,String> parameterMap = new HashMap<String, String>();
            for (String key: alertParameters.getSimpleProperties().keySet())
                parameterMap.put(key,alertParameters.getSimple(key).getStringValue());

            ScriptContext sc = engine.getContext();
            sc.setAttribute("alertPreferences",preferencesMap,ScriptContext.ENGINE_SCOPE);
            sc.setAttribute("alertParameters",parameterMap,ScriptContext.ENGINE_SCOPE);
            engine.eval(br);

            AlertManagerLocal alertManager = LookupUtil.getAlertManager();

            Object[] args = new Object[3];
View Full Code Here

Examples of javax.script.ScriptContext

            Object arg = args[0];
            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

Examples of javax.script.ScriptContext

            Object arg = args[0];
            if (arg instanceof Wrapper) {
                arg = ((Wrapper)arg).unwrap();
            }
            if (arg instanceof Bindings) {
                ScriptContext ctx = new SimpleScriptContext();
                ctx.setBindings((Bindings)arg, ScriptContext.ENGINE_SCOPE);
                Scriptable res = new ExternalScriptable(ctx);
                res.setPrototype(ScriptableObject.getObjectPrototype(thisObj));
                res.setParentScope(ScriptableObject.getTopLevelScope(thisObj));
                return res;
            }
View Full Code Here

Examples of javax.script.ScriptContext

        }
        return engine;
    }

    private ScriptContext getContext(Map<String, Object> bindings) {
        final ScriptContext result = new SimpleScriptContext();
        final Bindings engineScope = result.getBindings(ScriptContext.ENGINE_SCOPE);
        engineScope.putAll(bindings);
        return result;
    }
View Full Code Here

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

Examples of javax.script.ScriptContext

        }
        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

Examples of javax.script.ScriptContext

            }
        }
    }

    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
TOP
Copyright © 2018 www.massapi.com. 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.