01: package org.drools.brms.gwtutil;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import java.lang.reflect.Method;
20:
21: import org.drools.brms.client.rpc.RepositoryService;
22:
23: /**
24: * This utility uses reflection to generate the async interface from the
25: * Service interface as per GWT standard.
26: *
27: * @author Michael Neale
28: */
29: public class AsyncInterfaceGenerator {
30:
31: public static void main(String[] args) throws Exception {
32: Class cls = RepositoryService.class;
33: String line = "";
34: Method[] methods = cls.getMethods();
35: for (int i = 0; i < methods.length; i++) {
36: Method meth = methods[i];
37: if (meth.getDeclaringClass() == cls) {
38: line += "public void " + meth.getName() + "(";
39: Class params[] = meth.getParameterTypes();
40: for (int j = 0; j < params.length; j++) {
41: String type = params[j].getName();
42: if (type.equals("[Ljava.lang.String;")) {
43: type = "String[]";
44: }
45: line += type;
46: line += " p" + j;
47: if (j < params.length - 1) {
48: line += ", ";
49: }
50: }
51: if (line.endsWith("(")) {
52: line += "AsyncCallback cb";
53: } else {
54: line += ", AsyncCallback cb";
55: }
56: line += ");\n";
57: }
58: }
59: System.out
60: .println("/** Generated by AsyncInterfaceGenerator hackery */");
61: System.out.println(line);
62: }
63:
64: }
|