1.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java Tue Jan 26 04:36:23 2016 +0100
1.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/impl/Console.java Fri Mar 25 11:12:16 2016 +0100
1.3 @@ -223,7 +223,7 @@
1.4 static String invoke(String clazz, String method) throws
1.5 ClassNotFoundException, InvocationTargetException, IllegalAccessException,
1.6 InstantiationException, InterruptedException {
1.7 - final Object r = new Case(null).invokeMethod(clazz, method);
1.8 + final Object r = new Case(null).invokeMethod(clazz, method, null);
1.9 return r == null ? "null" : r.toString().toString();
1.10 }
1.11
1.12 @@ -315,6 +315,10 @@
1.13 public String getHtmlFragment() {
1.14 return value("html", data);
1.15 }
1.16 +
1.17 + public String[] getArgs() {
1.18 + return values("args", data);
1.19 + }
1.20
1.21 void again(Object[] arr) {
1.22 try {
1.23 @@ -334,21 +338,24 @@
1.24 setAttr("bck2brwsr.fragment", "innerHTML", this.getHtmlFragment());
1.25 }
1.26 log("Invoking " + this.getClassName() + '.' + this.getMethodName() + " as request: " + this.getRequestId());
1.27 - Object result = invokeMethod(this.getClassName(), this.getMethodName());
1.28 + Object result = invokeMethod(this.getClassName(), this.getMethodName(), this.getArgs());
1.29 setAttr("bck2brwsr.fragment", "innerHTML", "");
1.30 log("Result: " + result);
1.31 result = encodeURL("" + result);
1.32 return result;
1.33 }
1.34
1.35 - private Object invokeMethod(String clazz, String method)
1.36 + private Object invokeMethod(String clazz, String method, String[] args)
1.37 throws ClassNotFoundException, InvocationTargetException,
1.38 InterruptedException, IllegalAccessException, IllegalArgumentException,
1.39 InstantiationException {
1.40 Method found = null;
1.41 + if (args == null) {
1.42 + args = new String[0];
1.43 + }
1.44 Class<?> c = Class.forName(clazz);
1.45 for (Method m : c.getMethods()) {
1.46 - if (m.getName().equals(method)) {
1.47 + if (m.getName().equals(method) && m.getParameterTypes().length == args.length) {
1.48 found = m;
1.49 }
1.50 }
1.51 @@ -358,13 +365,13 @@
1.52 double now;
1.53 if ((found.getModifiers() & Modifier.STATIC) != 0) {
1.54 now = getTime();
1.55 - res = found.invoke(null);
1.56 + res = found.invoke(null, (Object[]) args);
1.57 } else {
1.58 if (inst == null) {
1.59 inst = c.newInstance();
1.60 }
1.61 now = getTime();
1.62 - res = found.invoke(inst);
1.63 + res = found.invoke(inst, (Object[]) args);
1.64 }
1.65 double took = Math.round((float)(getTime() - now));
1.66 time += took;
1.67 @@ -392,5 +399,12 @@
1.68 + "return v.toString();"
1.69 )
1.70 private static native String value(String p, Object d);
1.71 +
1.72 + @JavaScriptBody(args = {"p", "d"}, body =
1.73 + "var v = d[p];\n"
1.74 + + "if (typeof v === 'undefined') return null;\n"
1.75 + + "return v;"
1.76 + )
1.77 + private static native String[] values(String p, Object d);
1.78 }
1.79 }