Package javax.script

Examples of javax.script.Invocable.invokeFunction()


        ScriptEngine engine = factory.getEngineByName("groovy");
        String fact = "def factorial(n) { n == 1 ? 1 : n * factorial(n - 1) }";
        engine.eval(fact);
        Invocable inv = (Invocable) engine;
        Object[] params = {5};
        Object result = inv.invokeFunction("factorial", params);
        assertEquals(new Integer(120), result);
        // end::jsr223_invocable[]
    }
}
View Full Code Here


     * given arguments.
     */
    public Object call(String name, Object[] args) {
      Invocable invocable = (Invocable)engine;
      try {
        return invocable.invokeFunction(name, args);
      } catch (RuntimeException re) {
        throw re;
      } catch (Exception exp) {
        throw new RuntimeException(exp);
      }
View Full Code Here

        Product product = new Product();
        product.setName("Rubber");
        product.setPrice(1.99);
        product.setStock(1037);

        Object result = invocable.invokeFunction("getValueOfGoods", product);
        System.out.println(result);
    }

}
View Full Code Here

    public static void main(String[] args) throws Exception {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
        engine.eval(new FileReader("res/nashorn1.js"));

        Invocable invocable = (Invocable) engine;
        Object result = invocable.invokeFunction("fun1", "Peter Parker");
        System.out.println(result);
        System.out.println(result.getClass());

        invocable.invokeFunction("fun2", new Date());
        invocable.invokeFunction("fun2", LocalDateTime.now());
View Full Code Here

        Invocable invocable = (Invocable) engine;
        Object result = invocable.invokeFunction("fun1", "Peter Parker");
        System.out.println(result);
        System.out.println(result.getClass());

        invocable.invokeFunction("fun2", new Date());
        invocable.invokeFunction("fun2", LocalDateTime.now());
        invocable.invokeFunction("fun2", new Person());
    }

}
View Full Code Here

        Object result = invocable.invokeFunction("fun1", "Peter Parker");
        System.out.println(result);
        System.out.println(result.getClass());

        invocable.invokeFunction("fun2", new Date());
        invocable.invokeFunction("fun2", LocalDateTime.now());
        invocable.invokeFunction("fun2", new Person());
    }

}
View Full Code Here

        System.out.println(result);
        System.out.println(result.getClass());

        invocable.invokeFunction("fun2", new Date());
        invocable.invokeFunction("fun2", LocalDateTime.now());
        invocable.invokeFunction("fun2", new Person());
    }

}
View Full Code Here

    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByExtension("py");
    engine.eval("def hello(name):\n return 'Hello ' + name");
    assertTrue(engine instanceof Invocable);
    Invocable invocableScript = (Invocable) engine;
    assertEquals("Hello Monty", invocableScript.invokeFunction("hello", new Object[] { "Monty" }));
  }

}
View Full Code Here

    assertTrue(engine instanceof Invocable);
    Invocable invocableScript = (Invocable) engine;

    Object xmlIn = xmlHelper.toScriptXML(createOMElement("<a><b>petra</b></a>"));

    Object o = invocableScript.invokeFunction("isXML", new Object[]{xmlIn});
    assertTrue(o instanceof Boolean);
    assertTrue(((Boolean)o).booleanValue());
  }
 
  public void testInvokeFunctionOutXML() throws ScriptException, XMLStreamException, FactoryConfigurationError, NoSuchMethodException {
View Full Code Here

    assertTrue(engine instanceof Invocable);
    Invocable invocableScript = (Invocable) engine;

    Object xmlIn = xmlHelper.toScriptXML(createOMElement("<a><b>petra</b></a>"));

    Object xmlOut = invocableScript.invokeFunction("hello", new Object[]{xmlIn});
    OMElement omOut = xmlHelper.toOMElement(xmlOut);
    assertEquals("<foo><b>petra</b></foo>", omOut.toString());
  }

  public void testE4X() throws ScriptException, XMLStreamException, FactoryConfigurationError {
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.