/[classpath]/classpath/gnu/java/rmi/rmic/RMIC.java
ViewVC logotype

Diff of /classpath/gnu/java/rmi/rmic/RMIC.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by tromey, Mon Mar 25 22:05:51 2002 UTC revision 1.8 by iproetel, Mon Aug 11 14:13:27 2003 UTC
# Line 43  import java.io.PrintWriter; Line 43  import java.io.PrintWriter;
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 {
# Line 71  private String fullclassname; Line 72  private String fullclassname;
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  }  }
# Line 110  public boolean run() { Line 113  public boolean run() {
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();
# Line 140  private void analyzeClass(String cname) Line 147  private void analyzeClass(String cname)
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;
# Line 278  private void generateStub() throws IOExc Line 290  private void generateStub() throws IOExc
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();
# Line 343  private void generateStub() throws IOExc Line 355  private void generateStub() throws IOExc
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) {
# Line 1014  public int compareTo(Object obj) { Line 1028  public int compareTo(Object obj) {
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  }  }

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26