Java 8 SimpleScriptContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SimpleScriptContext class.

This code example shows how to use the following methods:setAttribute
 
        new ScriptMockSetup(mockery, componentManager);
 
        // Script Context Mock 
        final ScriptContextManager scm = componentManager.registerMockComponent(mockery, ScriptContextManager.class);
        final SimpleScriptContext scriptContext = new SimpleScriptContext();
        scriptContext.setAttribute("var", "value", ScriptContext.ENGINE_SCOPE);
        scriptContext.setAttribute("services", componentManager.getInstance(ScriptServiceManager.class),
            ScriptContext.ENGINE_SCOPE);
 
        mockery.checking(new Expectations()
        { 
            { 
                allowing(scm).getScriptContext();
                will(returnValue(scriptContext));
            } 
        }); 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:setAttribute
 
        new ScriptMockSetup(mockery, cm);
 
        // Script Context Mock 
        final ScriptContextManager scm = cm.registerMockComponent(mockery, ScriptContextManager.class);
        final SimpleScriptContext scriptContext = new SimpleScriptContext();
        scriptContext.setAttribute("var", "value", ScriptContext.ENGINE_SCOPE);
        mockery.checking(new Expectations() {{
            allowing(scm).getScriptContext(); will(returnValue(scriptContext));
        }}); 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getAttribute, setAttribute
     */ 
    private List<Block> highlight(String syntaxId, String code) throws ScriptException, ParseException
    { 
        BlocksGeneratorPygmentsListener listener = new BlocksGeneratorPygmentsListener(this.plainTextParser);
 
        ScriptContext scriptContext = new SimpleScriptContext();
 
        scriptContext.setAttribute(PY_LANGUAGE_VARNAME, syntaxId, ScriptContext.ENGINE_SCOPE);
        scriptContext.setAttribute(PY_CODE_VARNAME, code, ScriptContext.ENGINE_SCOPE);
        scriptContext.setAttribute(PY_STYLE_VARNAME, this.configuration.getStyle(), ScriptContext.ENGINE_SCOPE);
        scriptContext.setAttribute(PY_LISTENER_VARNAME, listener, ScriptContext.ENGINE_SCOPE);
 
        this.engine.eval(this.script, scriptContext);
 
        List<Block> blocks;
        if (scriptContext.getAttribute(PY_LEXER_VARNAME) != null) {
            blocks = listener.getBlocks();
        } else { 
            blocks = this.plainTextParser.parse(new StringReader(code)).getChildren().get(0).getChildren();
        } 
 
6
CodeRank
This code example shows how to use the following methods:setAttribute
	} 
	 
	@Test public void testArraySyntax() throws Exception {
		TeiidScriptEngine tse = new TeiidScriptEngine();
		CompiledScript cs = tse.compile("root.1.2");
		SimpleScriptContext ssc = new SimpleScriptContext();
		ssc.setAttribute("root", new Object[] {new Object[] {"x", "y"}}, SimpleScriptContext.ENGINE_SCOPE);
		assertEquals("y", cs.eval(ssc));
	} 
	 
} 
5
CodeRank
This code example shows how to use the following methods:setBindings
 
    public Object run(Bindings args) throws Exception {
        if (args == null) {
            args = new SimpleBindings();
        } 
        ScriptContext ctx = new SimpleScriptContext();
        ctx.setBindings(args, ScriptContext.ENGINE_SCOPE);
        Object result = null; 
        if (!trackChanges && script != null) {
            result = script.eval(ctx);
        } else { 
            result = getCompiledScript().eval(ctx);
        } 
        return result; 
    } 
 
    public CompiledScript getCompiledScript() throws ScriptException {
        try { 
            Reader reader = script == null ? getReader() : getReaderIfModified();
            if (reader != null) {
5
CodeRank
This code example shows how to use the following methods:
    @Override 
    public void initialize(ExecutionContext executionContext) throws ExecutionContextException 
    { 
        // We're storing an instance of the Script Context class in the Execution Context so that it can be 
        // shared between different script invocations during the lifetime of the Execution Context. 
        executionContext.setProperty(SCRIPT_CONTEXT_ID, new SimpleScriptContext()); 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:setBindings
 
    public Object run(Bindings args) throws Exception {
        if (args == null) {
            args = new SimpleBindings();
        } 
        ScriptContext ctx = new SimpleScriptContext();
        ctx.setBindings(args, ScriptContext.ENGINE_SCOPE);
        Object result = null; 
        if (!trackChanges && script != null) {
            result = script.eval(ctx);
        } else { 
            result = getCompiledScript().eval(ctx);
        } 
        return result; 
    } 
 
    public CompiledScript getCompiledScript() throws ScriptException {
        try { 
            Reader reader = script == null ? getReader() : getReaderIfModified();
            if (reader != null) {
4
CodeRank
This code example shows how to use the following methods:setBindings
    public static ScriptContext createScriptContext(Map<String, Object> context) {
        Assert.notNull("context", context);
        Map<String, Object> localContext = new HashMap<String, Object>(context);
        localContext.put(WIDGET_CONTEXT_KEY, context);
        localContext.put("context", context); 
        ScriptContext scriptContext = new SimpleScriptContext();
        ScriptHelper helper = createScriptHelper(scriptContext);
        if (helper != null) {
            localContext.put(SCRIPT_HELPER_KEY, helper);
        } 
        Bindings bindings = new SimpleBindings(localContext);
        scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
        return scriptContext;
    } 
 
    /** 
     * Returns a <code>ScriptContext</code> that contains the members of <code>context</code>. 
     * <p>If a <code>CompiledScript</code> instance is to be shared by multiple threads, then 
     * each thread must create its own <code>ScriptContext</code> and pass it to the 
     * <code>CompiledScript</code> eval method.</p> 
3
CodeRank
See Code Examples for Java 8 SimpleScriptContext Methods: