Package org.apache.bsf

Examples of org.apache.bsf.BSFManager


     * Test of apply method, of class JRubyEngine.
     */
    @Test
    public void testApply() throws BSFException {
        logger1.info("apply");
        BSFManager manager = new BSFManager();
        JRubyEngine instance = new JRubyEngine();
        instance.initialize(manager, "jruby", null);
        String file = "";
        int line = 0;
        int col = 0;
View Full Code Here


     */
    @Test
    public void testEval() throws Exception {
        logger1.info("eval");
        BSFManager.registerScriptingEngine("jruby", "org.jruby.embed.bsf.JRubyEngine", new String[] {"rb"});
        BSFManager manager = new BSFManager();
        JRubyEngine instance = new JRubyEngine();
        instance.initialize(manager, "jruby", null);
        String file = "";
        int line = 0;
        int col = 0;
        Object expr = null;
        Object expResult = null;
        Object result = instance.eval(file, line, col, expr);
        assertEquals(expResult, result);

        expResult = "HELLO WORLD!";
        result = instance.eval("<script>", 0, 0, "message=\"Hello \" + \"World!\"\nmessage.upcase");
        assertEquals(expResult, result);

        manager.declareBean("greet", "Heeey", String.class);
        result = manager.eval("jruby", "<script>", 0, 0, "message=$greet + \" World!\"");
        expResult = "Heeey World!";
        assertEquals(expResult, result);
    }
View Full Code Here

     * Test of exec method, of class JRubyEngine.
     */
    @Test
    public void testExec() throws Exception {
        logger1.info("exec");
        BSFManager manager = new BSFManager();
        JRubyEngine instance = new JRubyEngine();
        instance.initialize(manager, "jruby", null);
        String file = "";
        int line = 0;
        int col = 0;
View Full Code Here

     */
    @Test
    public void testCall() throws Exception {
        logger1.info("call");
        BSFManager.registerScriptingEngine("jruby", "org.jruby.embed.bsf.JRubyEngine", new String[] {"rb"});
        BSFManager manager = new BSFManager();
        JRubyEngine instance = (JRubyEngine) manager.loadScriptingEngine("jruby");
        instance.initialize(manager, "jruby", null);
        Object recv = null;
        String method = "";
        Object[] args = null;
        Object expResult = null;
        Object result = instance.call(recv, method, args);
        assertEquals(expResult, result);

        String script =
                "# Radioactive decay\n" +
                "def amount_after_years(q0, t)\n" +
                  "q0 * Math.exp(1.0 / $h * Math.log(1.0/2.0) * t)\n" +
                "end\n" +
                "def years_to_amount(q0, q)\n" +
                  "$h * (Math.log(q) - Math.log(q0)) / Math.log(1.0/2.0)\n" +
                "end";
        recv = manager.eval("jruby", "radioactive_decay", 0, 0, script);
        method = "amount_after_years";
        args = new Object[2];
        args[0] = 10.0; args[1] = 1000;
       
        // Radium
        manager.declareBean("h", 1599, Long.class);
        result = instance.call(recv, method, args);
        assertEquals(6.482, (Double)result, 0.001);

        method = "years_to_amount";
        args[0] = 10.0; args[1] = 1.0;
View Full Code Here

     * Test of initialize method, of class JRubyEngine.
     */
    @Test
    public void testInitialize() throws Exception {
        logger1.info("initialize");
        BSFManager manager = new BSFManager();;
        String language = "";
        Vector someDeclaredBeans = null;
        JRubyEngine instance = new JRubyEngine();
        instance.initialize(manager, language, someDeclaredBeans);
    }
View Full Code Here

     * Test of declareBean method, of class JRubyEngine.
     */
    @Test
    public void testDeclareBean() throws Exception {
        logger1.info("declareBean");
        BSFManager manager = new BSFManager();
        JRubyEngine instance = new JRubyEngine();
        instance.initialize(manager, "jruby", null);
        manager.declareBean("abc", "aaabbbccc", String.class);
        BSFDeclaredBean bean = (BSFDeclaredBean) manager.getObjectRegistry().lookup("abc");
        instance.declareBean(bean);
    }
View Full Code Here

     * Test of undeclareBean method, of class JRubyEngine.
     */
    @Test
    public void testUndeclareBean() throws Exception {
        logger1.info("undeclareBean");
        BSFManager manager = new BSFManager();
        JRubyEngine instance = new JRubyEngine();
        instance.initialize(manager, "jruby", null);
        manager.declareBean("abc", "aaabbbccc", String.class);
        BSFDeclaredBean bean = (BSFDeclaredBean) manager.getObjectRegistry().lookup("abc");
        instance.undeclareBean(bean);
    }
View Full Code Here

     * Test of handleException method, of class JRubyEngine.
     */
    @Test
    public void testHandleException() throws BSFException {
        logger1.info("handleException");
        BSFManager manager = new BSFManager();
        JRubyEngine instance = new JRubyEngine();
        instance.initialize(manager, "jruby", null);
        BSFException bsfExcptn = new BSFException(BSFException.REASON_EXECUTION_ERROR, "test", new NullPointerException());
        instance.handleException(bsfExcptn);
    }
View Full Code Here

   
    public void setUp() throws Exception {
        super.setUp();
        BSFManager.registerScriptingEngine("ruby", "org.jruby.javasupport.bsf.JRubyEngine", new String[] { "rb" });
       
        manager = new BSFManager();
        String expression = loadScript(RUBY_SCRIPT);
        assertNotNull("Script loaded from " + RUBY_SCRIPT + " should exist", expression);
        manager.exec("ruby", "(java)", 1, 1, expression);
    }
View Full Code Here

    private static final long serialVersionUID = 234L;

    public void sampleOccurred(SampleEvent event) {
        try {
            BSFManager mgr = getManager();
            if (mgr == null) {
                log.error("Problem creating BSF manager");
                return;
            }
            mgr.declareBean("sampleEvent", event, SampleEvent.class);
            SampleResult result = event.getResult();
            mgr.declareBean("sampleResult", result, SampleResult.class);
            processFileOrScript(mgr);
            mgr.terminate();
        } catch (BSFException e) {
            log.warn("Problem in BSF script "+e);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.bsf.BSFManager

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.