diff options
author | Ingo Proetel <proetel@aicas.com> | 2003-08-11 14:13:27 +0000 |
---|---|---|
committer | Ingo Proetel <proetel@aicas.com> | 2003-08-11 14:13:27 +0000 |
commit | 56274448d6b91749c248b30d9eced609077edea6 (patch) | |
tree | 01ebaa4262a48201a0de00b8af3548b199e0b7b5 /gnu/java/rmi | |
parent | bfab26ee5b5d13dc39a0d3e11c7fd5f17a3ad8e9 (diff) | |
download | classpath-56274448d6b91749c248b30d9eced609077edea6.tar.gz |
* gnu/java/rmi/server/UnicastRef.java: make constructor public and check if serverobject
is compatible in case client and server are running in the same VM
* gnu/java/rmi/rmic/RMIC.java: fix that methods of the remote interfaces are used
instead of the xxxImpl class
Diffstat (limited to 'gnu/java/rmi')
-rw-r--r-- | gnu/java/rmi/rmic/RMIC.java | 90 | ||||
-rw-r--r-- | gnu/java/rmi/server/UnicastRef.java | 44 |
2 files changed, 90 insertions, 44 deletions
diff --git a/gnu/java/rmi/rmic/RMIC.java b/gnu/java/rmi/rmic/RMIC.java index ef4473247..0e5ef0bf9 100644 --- a/gnu/java/rmi/rmic/RMIC.java +++ b/gnu/java/rmi/rmic/RMIC.java @@ -43,10 +43,11 @@ import java.io.PrintWriter; import java.io.IOException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.rmi.RemoteException; import java.util.HashSet; import java.util.Iterator; import java.util.Arrays; -import java.lang.Comparable; + import gnu.java.rmi.server.RMIHashes; public class RMIC { @@ -71,7 +72,9 @@ private String fullclassname; private MethodRef[] remotemethods; private String stubname; private String skelname; +private int errorCount = 0; +private Class mRemoteInterface; public RMIC(String[] a) { args = a; } @@ -110,7 +113,11 @@ public boolean run() { } private boolean processClass(String classname) throws Exception { + errorCount = 0; analyzeClass(classname); + if(errorCount > 0) { + System.exit(1); + } generateStub(); if (need11Stubs) { generateSkel(); @@ -140,27 +147,32 @@ private void analyzeClass(String cname) throws Exception { } fullclassname = cname; + // ??? HashSet rmeths = new HashSet(); findClass(); - for (Class cls = clazz; cls != null; cls = cls.getSuperclass()) { - // Keep going down the inheritence tree until we hit the system - if (cls.getName().startsWith("java.")) { - 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 - - // Add this one in. - rmeths.add(meths[i]); - } - } + + // get the remote interface + mRemoteInterface = getRemoteInterface(clazz); + + // check if the methods of the remote interface declare RemoteExceptions + Method[] meths = mRemoteInterface.getDeclaredMethods(); + for (int i = 0; i < meths.length; i++) { +// NYI: ignore check until Method.getExceptionTypes is implemented +// Class[] exceptions = meths[i].getExceptionTypes(); +// int index = 0; +// for(;index < exceptions.length; index++){ +// if(exceptions[index].equals(RemoteException.class)){ +// break; +// } +// } +// if (index < exceptions.length) { + rmeths.add(meths[i]); +// } else { +// logError("Method "+meths[i]+" does not throw a java.rmi.RemoteException"); +// } } + // Convert into a MethodRef array and sort them remotemethods = new MethodRef[rmeths.size()]; int c = 0; @@ -278,7 +290,7 @@ private void generateStub() throws IOException { for (int i = 0; i < remotemethods.length; i++) { Method m = remotemethods[i].meth; out.print("$method_" + m.getName() + "_" + i + " = "); - out.print(fullclassname + ".class.getMethod(\"" + m.getName() + "\""); + out.print(mRemoteInterface.getName() + ".class.getMethod(\"" + m.getName() + "\""); out.print(", new java.lang.Class[] {"); // Output signature Class[] sig = m.getParameterTypes(); @@ -343,7 +355,9 @@ private void generateStub() throws IOException { } } out.print(") "); - out.print("throws "); +// NYI hard-code java.rmi.RemoteException until Method.getExceptionTypes is implemented +// out.print("throws "); + out.print("throws java.rmi.RemoteException"); for (int j = 0; j < except.length; j++) { out.print(getPrettyName(except[j])); if (j+1 < except.length) { @@ -1014,4 +1028,40 @@ public int compareTo(Object obj) { } + /** + * Looks for the java.rmi.Remote interface that that is implemented by theClazz. + * @param theClazz the class to look in + * @return the Remote interface of theClazz + */ + private Class getRemoteInterface(Class theClazz) + { + System.out.println( + "[RMIC]looking for remote interface in " + theClazz.getName()); + Class[] interfaces = theClazz.getInterfaces(); + System.out.println("[RMIC] got interface array"); + for (int i = 0; i < interfaces.length; i++) + { + if (java.rmi.Remote.class.isAssignableFrom(interfaces[i])) + { + System.out.println("[RMIC]found remote interface " + interfaces[i].getName()); + return interfaces[i]; + } + } + System.out.println("[RMIC]found no remote interface"); + + logError("Class "+ theClazz.getName() + + " is not a remote object. It does not implement an interface that is a java.rmi.Remote-interface."); + return null; + } + + /** + * Prints an error to System.err and increases the error count. + * @param theError + */ + private void logError(String theError){ + errorCount++; + System.err.println("error:"+theError); + } + + } diff --git a/gnu/java/rmi/server/UnicastRef.java b/gnu/java/rmi/server/UnicastRef.java index 9ab020db6..aaec7a3b4 100644 --- a/gnu/java/rmi/server/UnicastRef.java +++ b/gnu/java/rmi/server/UnicastRef.java @@ -37,32 +37,24 @@ exception statement from your version. */ package gnu.java.rmi.server; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.rmi.Remote; import java.rmi.RemoteException; -import java.rmi.server.RemoteRef; -import java.rmi.server.RMISocketFactory; +import java.rmi.server.ObjID; +import java.rmi.server.Operation; import java.rmi.server.RMIClientSocketFactory; -import java.rmi.server.RMIServerSocketFactory; -import java.rmi.server.RemoteObject; import java.rmi.server.RemoteCall; -import java.rmi.server.UnicastRemoteObject; -import java.rmi.server.Operation; -import java.rmi.server.ObjID; +import java.rmi.server.RemoteObject; +import java.rmi.server.RemoteRef; import java.rmi.server.UID; -import java.lang.reflect.Method; -import java.io.ObjectOutput; -import java.io.ObjectInput; -import java.io.IOException; -import java.net.Socket; -import java.net.InetAddress; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; - -import java.lang.reflect.InvocationTargetException; public class UnicastRef implements RemoteRef, ProtocolConstants { @@ -73,8 +65,9 @@ UnicastConnectionManager manager; /** * Used by serialization, and let subclass capable of having default constructor */ -//private -UnicastRef() { +// must be public otherwise java.rmi.RemoteObject cannot instantiate this class +// -- iP +public UnicastRef() { } public UnicastRef(ObjID objid, String host, int port, RMIClientSocketFactory csf) { @@ -90,7 +83,10 @@ public Object invoke(Remote obj, Method method, Object[] params, long opnum) thr // Check if client and server are in the same VM, then local call can be used to // replace remote call, but it's somewhat violating remote semantic. Object svrobj = manager.serverobj; - if(svrobj != null){ + + // Make sure that the server object is compatible. It could be loaded from a different + // classloader --iP + if(svrobj != null && method.getDeclaringClass().isInstance(svrobj)){ //local call Object ret = null; try{ |