Package org.apache.bsf

Examples of org.apache.bsf.BSFManager.eval()


                "org.jruby.embed.bsf.JRubyEngine", new String[]{"rb"});
        BSFManager bsf = new BSFManager();
        bsf.eval("jruby", "(java)", 1, 1, "$x='GVar'");
        bsf.eval("jruby", "(java)", 1, 1, "@gvar = \"$x = #{$x}\"");

        bsf.eval("jruby", "(java)", 1, 1, "x='LVar'");
        bsf.eval("jruby", "(java)", 1, 1, "at_exit { @result =  \"#{x} and #{$x} in an at_exit block\" }");
        Object ret = bsf.eval("jruby", "(java)", 1, 1, "@lvar = \"x = #{x}\";return @gvar, @lvar");
        List<String> expResult = Arrays.asList("$x = GVar", "x = LVar");
        assertEquals(expResult, ret);
        logger1.info(ret.toString());
View Full Code Here


        BSFManager bsf = new BSFManager();
        bsf.eval("jruby", "(java)", 1, 1, "$x='GVar'");
        bsf.eval("jruby", "(java)", 1, 1, "@gvar = \"$x = #{$x}\"");

        bsf.eval("jruby", "(java)", 1, 1, "x='LVar'");
        bsf.eval("jruby", "(java)", 1, 1, "at_exit { @result =  \"#{x} and #{$x} in an at_exit block\" }");
        Object ret = bsf.eval("jruby", "(java)", 1, 1, "@lvar = \"x = #{x}\";return @gvar, @lvar");
        List<String> expResult = Arrays.asList("$x = GVar", "x = LVar");
        assertEquals(expResult, ret);
        logger1.info(ret.toString());
        bsf.terminate();
View Full Code Here

        bsf.eval("jruby", "(java)", 1, 1, "$x='GVar'");
        bsf.eval("jruby", "(java)", 1, 1, "@gvar = \"$x = #{$x}\"");

        bsf.eval("jruby", "(java)", 1, 1, "x='LVar'");
        bsf.eval("jruby", "(java)", 1, 1, "at_exit { @result =  \"#{x} and #{$x} in an at_exit block\" }");
        Object ret = bsf.eval("jruby", "(java)", 1, 1, "@lvar = \"x = #{x}\";return @gvar, @lvar");
        List<String> expResult = Arrays.asList("$x = GVar", "x = LVar");
        assertEquals(expResult, ret);
        logger1.info(ret.toString());
        bsf.terminate();
    }
View Full Code Here

        try {
            BSFManager m = createManager();
            declareBeans(m);
            // execute the script
            if (engine == null) {
                return m.eval(getLanguage(), execName, 0, 0, getScript());
            }
            return engine.eval(execName, 0, 0, getScript());
        } catch (BSFException be) {
            throw getBuildException(be);
        } finally {
View Full Code Here

    @Test
    public void testSimpleIntegration() throws BSFException {
        // tag::bsf_simple[]
        String myScript = "println('Hello World')\n  return [1, 2, 3]";
        BSFManager manager = new BSFManager();
        List answer = (List) manager.eval("groovy", "myScript.groovy", 0, 0, myScript);
        assertEquals(3, answer.size());
        // end::bsf_simple[]
    }

    @Test
View Full Code Here

    @Test
    public void testVariablePassing() throws BSFException {
        // tag::bsf_variable_passing[]
        BSFManager manager = new BSFManager();
        manager.declareBean("xyz", 4, Integer.class);
        Object answer = manager.eval("groovy", "test.groovy", 0, 0, "xyz + 1");
        assertEquals(5, answer);
        // end::bsf_variable_passing[]
    }

    @Test
View Full Code Here

        s.append(l).append('\n');
      }
      script = s.toString();
    }

    mgr.eval(language, String.valueOf(scriptFile), 0, 0, script);
    }
}
View Full Code Here

                    }
                }                                               
            }                   
                                                                                    
            // execute the script
            Object result = bsfManager.eval(scriptType, cacheName, 0, 0, scriptString);
           
            // check the result
            if (result != null && !(result instanceof String)) {
                throw new EventHandlerException("Event did not return a String result, it returned a " + result.getClass().getName());          
            }
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.