Package javax.script

Examples of javax.script.Invocable


        return invocable.getInterface(EntryTransformer.class);
    }

    public RowTransformer getRowTransformer(String scriptName) {
        String content = load("row", scriptName);
        Invocable invocable = (Invocable) engine;
        try {
            engine.eval(content);
        } catch (ScriptException ex) {
            throw new IllegalStateException("Cannot evaluate script", ex);
        }
        return invocable.getInterface(RowTransformer.class);
    }
View Full Code Here


    /**
     * Call the script function of given name passing the
     * 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

    if (!(tmp instanceof Invocable)) {
      throw new HiveException("The script engine for " + language
          + " doesn't support invocable");
    }

    Invocable engine = (Invocable) tmp;

    String scriptText;
    if (script.startsWith("/")) {
      // The file is a file in HDFS
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());
        invocable.invokeFunction("fun2", new Person());
    }
View Full Code Here

  public void testInvokeFunction() throws ScriptException, NoSuchMethodException {
    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

  private ScriptEngine engine;
 
  public void testInvokeFunctionInXML() throws ScriptException, XMLStreamException, FactoryConfigurationError, NoSuchMethodException {
    engine.eval("function isXML(xml) { return typeof xml == 'xml'; }" );
    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());
  }
View Full Code Here

  }
 
  public void testInvokeFunctionOutXML() throws ScriptException, XMLStreamException, FactoryConfigurationError, NoSuchMethodException {
    engine.eval("function hello(xml) { return <foo>{xml.b}</foo>; }" );
    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());
  }
View Full Code Here

  public void testInvokeFunction() throws ScriptException, NoSuchMethodException {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByExtension("groovy");
    engine.eval("def hello(name) { return 'Hello ' + name }" );
    assertTrue(engine instanceof Invocable);
    Invocable invocableScript = (Invocable) engine;
    assertEquals("Hello petra", invocableScript.invokeFunction("hello", new Object[]{"petra"}));
  }
View Full Code Here

  public void testInvokeFunction() throws ScriptException, NoSuchMethodException {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByExtension("rb");
    engine.eval("def hello(s)\n   return \"Hello \" + s\nend" );
    assertTrue(engine instanceof Invocable);
    Invocable invocableScript = (Invocable) engine;
    assertEquals("Hello petra", invocableScript.invokeFunction("hello", new Object[]{"petra"}));
  }
View Full Code Here

   * @throws Exception
   */ 
  public Object createAST(Reader parser, String jsfile) throws Exception{   
    try {
      engine.eval(parser);
      Invocable invocableEngine = (Invocable)engine;
      // Store the script in a String
      String js = readFile2String(jsfile);
      //String js = getURLContent(codeURL);
     
      // (function name, script source, boolean for position details)
      AST = (String)invocableEngine.invokeFunction("parse2AST", js, true);
      //AST = invocableEngine.invokeFunction("parse2JSON", js, true);

    } catch (Exception ex) {
      ex.printStackTrace();
    }
View Full Code Here

TOP

Related Classes of javax.script.Invocable

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.