43 |
import java.io.IOException; |
import java.io.IOException; |
44 |
import java.lang.reflect.Method; |
import java.lang.reflect.Method; |
45 |
import java.lang.reflect.Modifier; |
import java.lang.reflect.Modifier; |
46 |
|
import java.rmi.RemoteException; |
47 |
import java.util.HashSet; |
import java.util.HashSet; |
48 |
import java.util.Iterator; |
import java.util.Iterator; |
49 |
import java.util.Arrays; |
import java.util.Arrays; |
50 |
import java.lang.Comparable; |
|
51 |
import gnu.java.rmi.server.RMIHashes; |
import gnu.java.rmi.server.RMIHashes; |
52 |
|
|
53 |
public class RMIC { |
public class RMIC { |
72 |
private MethodRef[] remotemethods; |
private MethodRef[] remotemethods; |
73 |
private String stubname; |
private String stubname; |
74 |
private String skelname; |
private String skelname; |
75 |
|
private int errorCount = 0; |
76 |
|
|
77 |
|
private Class mRemoteInterface; |
78 |
public RMIC(String[] a) { |
public RMIC(String[] a) { |
79 |
args = a; |
args = a; |
80 |
} |
} |
113 |
} |
} |
114 |
|
|
115 |
private boolean processClass(String classname) throws Exception { |
private boolean processClass(String classname) throws Exception { |
116 |
|
errorCount = 0; |
117 |
analyzeClass(classname); |
analyzeClass(classname); |
118 |
|
if(errorCount > 0) { |
119 |
|
System.exit(1); |
120 |
|
} |
121 |
generateStub(); |
generateStub(); |
122 |
if (need11Stubs) { |
if (need11Stubs) { |
123 |
generateSkel(); |
generateSkel(); |
147 |
} |
} |
148 |
fullclassname = cname; |
fullclassname = cname; |
149 |
|
|
150 |
|
// ??? |
151 |
HashSet rmeths = new HashSet(); |
HashSet rmeths = new HashSet(); |
152 |
findClass(); |
findClass(); |
153 |
for (Class cls = clazz; cls != null; cls = cls.getSuperclass()) { |
|
154 |
// Keep going down the inheritence tree until we hit the system |
// get the remote interface |
155 |
if (cls.getName().startsWith("java.")) { |
mRemoteInterface = getRemoteInterface(clazz); |
|
break; |
|
|
} |
|
|
|
|
|
Method[] meths = cls.getDeclaredMethods(); |
|
|
for (int i = 0; i < meths.length; i++) { |
|
|
// Only include public methods |
|
|
int mods = meths[i].getModifiers(); |
|
|
if (Modifier.isPublic(mods) && !Modifier.isStatic(mods)) { |
|
|
// Should check exceptions here. - XXX |
|
156 |
|
|
157 |
// Add this one in. |
// check if the methods of the remote interface declare RemoteExceptions |
158 |
rmeths.add(meths[i]); |
Method[] meths = mRemoteInterface.getDeclaredMethods(); |
159 |
} |
for (int i = 0; i < meths.length; i++) { |
160 |
} |
// NYI: ignore check until Method.getExceptionTypes is implemented |
161 |
|
// Class[] exceptions = meths[i].getExceptionTypes(); |
162 |
|
// int index = 0; |
163 |
|
// for(;index < exceptions.length; index++){ |
164 |
|
// if(exceptions[index].equals(RemoteException.class)){ |
165 |
|
// break; |
166 |
|
// } |
167 |
|
// } |
168 |
|
// if (index < exceptions.length) { |
169 |
|
rmeths.add(meths[i]); |
170 |
|
// } else { |
171 |
|
// logError("Method "+meths[i]+" does not throw a java.rmi.RemoteException"); |
172 |
|
// } |
173 |
} |
} |
174 |
|
|
175 |
|
|
176 |
// Convert into a MethodRef array and sort them |
// Convert into a MethodRef array and sort them |
177 |
remotemethods = new MethodRef[rmeths.size()]; |
remotemethods = new MethodRef[rmeths.size()]; |
178 |
int c = 0; |
int c = 0; |
290 |
for (int i = 0; i < remotemethods.length; i++) { |
for (int i = 0; i < remotemethods.length; i++) { |
291 |
Method m = remotemethods[i].meth; |
Method m = remotemethods[i].meth; |
292 |
out.print("$method_" + m.getName() + "_" + i + " = "); |
out.print("$method_" + m.getName() + "_" + i + " = "); |
293 |
out.print(fullclassname + ".class.getMethod(\"" + m.getName() + "\""); |
out.print(mRemoteInterface.getName() + ".class.getMethod(\"" + m.getName() + "\""); |
294 |
out.print(", new java.lang.Class[] {"); |
out.print(", new java.lang.Class[] {"); |
295 |
// Output signature |
// Output signature |
296 |
Class[] sig = m.getParameterTypes(); |
Class[] sig = m.getParameterTypes(); |
355 |
} |
} |
356 |
} |
} |
357 |
out.print(") "); |
out.print(") "); |
358 |
out.print("throws "); |
// NYI hard-code java.rmi.RemoteException until Method.getExceptionTypes is implemented |
359 |
|
// out.print("throws "); |
360 |
|
out.print("throws java.rmi.RemoteException"); |
361 |
for (int j = 0; j < except.length; j++) { |
for (int j = 0; j < except.length; j++) { |
362 |
out.print(getPrettyName(except[j])); |
out.print(getPrettyName(except[j])); |
363 |
if (j+1 < except.length) { |
if (j+1 < except.length) { |
1028 |
|
|
1029 |
} |
} |
1030 |
|
|
1031 |
|
/** |
1032 |
|
* Looks for the java.rmi.Remote interface that that is implemented by theClazz. |
1033 |
|
* @param theClazz the class to look in |
1034 |
|
* @return the Remote interface of theClazz |
1035 |
|
*/ |
1036 |
|
private Class getRemoteInterface(Class theClazz) |
1037 |
|
{ |
1038 |
|
System.out.println( |
1039 |
|
"[RMIC]looking for remote interface in " + theClazz.getName()); |
1040 |
|
Class[] interfaces = theClazz.getInterfaces(); |
1041 |
|
System.out.println("[RMIC] got interface array"); |
1042 |
|
for (int i = 0; i < interfaces.length; i++) |
1043 |
|
{ |
1044 |
|
if (java.rmi.Remote.class.isAssignableFrom(interfaces[i])) |
1045 |
|
{ |
1046 |
|
System.out.println("[RMIC]found remote interface " + interfaces[i].getName()); |
1047 |
|
return interfaces[i]; |
1048 |
|
} |
1049 |
|
} |
1050 |
|
System.out.println("[RMIC]found no remote interface"); |
1051 |
|
|
1052 |
|
logError("Class "+ theClazz.getName() |
1053 |
|
+ " is not a remote object. It does not implement an interface that is a java.rmi.Remote-interface."); |
1054 |
|
return null; |
1055 |
|
} |
1056 |
|
|
1057 |
|
/** |
1058 |
|
* Prints an error to System.err and increases the error count. |
1059 |
|
* @param theError |
1060 |
|
*/ |
1061 |
|
private void logError(String theError){ |
1062 |
|
errorCount++; |
1063 |
|
System.err.println("error:"+theError); |
1064 |
|
} |
1065 |
|
|
1066 |
|
|
1067 |
} |
} |