Package javax.script

Examples of javax.script.Invocable.invokeFunction()


    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


    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"}));
  }

//  public void testInvokeMethod() throws ScriptException {
//    ScriptEngineManager manager = new ScriptEngineManager();
//    ScriptEngine engine = manager.getEngineByExtension("js");
View Full Code Here

      // 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

      // Store the script in a String
      String js = Utils.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

      Invocable invocableEngine = (Invocable)engine;
      // Store the script in a String
      String js = Utils.getURLContent(jslink);
     
      // (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

        Object result = compiledScript == null ? engine.eval(scriptContent) : compiledScript.eval();
        if (engine instanceof Invocable) {
            final Invocable invocable = (Invocable) engine;

            try {
                result = invocable.invokeFunction(getFunctionName("process"));
            } catch (final NoSuchMethodException e) {
                //ignore
            }
        }
View Full Code Here

    public Object processItem(final Object item) throws Exception {
        final Object result = compiledScript == null ? engine.eval(scriptContent) : compiledScript.eval();
        if (engine instanceof Invocable) {
            final Invocable invocable = (Invocable) engine;
            try {
                return invocable.invokeFunction(getFunctionName("processItem"), item);
            } catch (final NoSuchMethodException e) {
                //the script does not implement processItem method, so just return the original item as is
                return item;
            }
        } else {
View Full Code Here

                                                        invocable = (Invocable)scriptEngine;
                                                    } catch (ClassCastException exception) {
                                                        throw new SerializationException(exception);
                                                    }

                                                    result = invocable.invokeFunction(methodName, args);
                                                }

                                                // If the function didn't return a value, return the default
                                                Class<?> returnType = method.getReturnType();
                                                if (returnType == Vote.class
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.