/[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.12 by mkoch, Wed Oct 13 14:32:33 2004 UTC revision 1.13 by mkoch, Wed Oct 20 08:45:39 2004 UTC
# Line 52  import java.util.HashSet; Line 52  import java.util.HashSet;
52  import java.util.Iterator;  import java.util.Iterator;
53  import java.util.Set;  import java.util.Set;
54    
 public class RMIC {  
55    
56  private String[] args;  public class RMIC
57  private int next;  {
58  private Exception exception;    private String[] args;
59      private int next;
60  private boolean keep = false;    private Exception exception;
61  private boolean need11Stubs = true;    private boolean keep = false;
62  private boolean need12Stubs = true;    private boolean need11Stubs = true;
63  private boolean compile = true;    private boolean need12Stubs = true;
64  private boolean verbose;    private boolean compile = true;
65  private String destination;    private boolean verbose;
66      private String destination;
67  private PrintWriter out;    private PrintWriter out;
68  private TabbedWriter ctrl;    private TabbedWriter ctrl;
69      private Class clazz;
70  private Class clazz;    private String classname;
71  private String classname;    private String fullclassname;
72  private String fullclassname;    private MethodRef[] remotemethods;
73  private MethodRef[] remotemethods;    private String stubname;
74  private String stubname;    private String skelname;
75  private String skelname;    private int errorCount = 0;
76  private int errorCount = 0;    private Class mRemoteInterface;
77    
78  private Class mRemoteInterface;    public RMIC(String[] a)
79  public RMIC(String[] a) {    {
80          args = a;      args = a;
81  }    }
82    
83  public static void main(String args[]) {    public static void main(String[] args)
84          RMIC r = new RMIC(args);    {
85          if (r.run() == false) {      RMIC r = new RMIC(args);
86                  Exception exception = r.getException();      if (r.run() == false)
87                  if (exception != null) {        {
88                          exception.printStackTrace();          Exception e = r.getException();
89                  }          if (e != null)
90                  else {            e.printStackTrace();
91                          System.exit(1);          else
92                  }            System.exit(1);
93          }        }
94  }    }
95    
96  public boolean run() {    public boolean run()
97          parseOptions();    {
98          if (next >= args.length) {      parseOptions();
99                  error("no class names found");      if (next >= args.length)
100          }        error("no class names found");
101          for (int i = next; i < args.length; i++) {      for (int i = next; i < args.length; i++)
102                  try {        {
103                          if (verbose) {          try
104                                  System.out.println("[Processing class " + args[i] + ".class]");            {
105                          }              if (verbose)
106                          processClass(args[i].replace(File.separatorChar, '.'));                System.out.println("[Processing class " + args[i] + ".class]");
107                  }              processClass(args[i].replace(File.separatorChar, '.'));
108                  catch (Exception e) {            }
109                          exception = e;          catch (Exception e)
110                          return (false);            {
111                  }              exception = e;
112          }              return (false);
113          return (true);            }
114  }        }
115        return (true);
116      }
117    
118      private boolean processClass(String classname) throws Exception
119      {
120        errorCount = 0;
121        analyzeClass(classname);
122        if (errorCount > 0)
123          System.exit(1);
124        generateStub();
125        if (need11Stubs)
126          generateSkel();
127        if (compile)
128          {
129            compile(stubname.replace('.', File.separatorChar) + ".java");
130            if (need11Stubs)
131              compile(skelname.replace('.', File.separatorChar) + ".java");
132          }
133        if (! keep)
134          {
135            (new File(stubname.replace('.', File.separatorChar) + ".java")).delete();
136            if (need11Stubs)
137              (new File(skelname.replace('.', File.separatorChar) + ".java"))
138              .delete();
139          }
140        return (true);
141      }
142    
143      private void analyzeClass(String cname) throws Exception
144      {
145        if (verbose)
146          System.out.println("[analyze class " + cname + "]");
147        int p = cname.lastIndexOf('.');
148        if (p != -1)
149          classname = cname.substring(p + 1);
150        else
151          classname = cname;
152        fullclassname = cname;
153    
154        HashSet rmeths = new HashSet();
155        findClass();
156    
157        // get the remote interface
158        mRemoteInterface = getRemoteInterface(clazz);
159        if (mRemoteInterface == null)
160          return;
161        if (verbose)
162          System.out.println("[implements " + mRemoteInterface.getName() + "]");
163    
164        // check if the methods of the remote interface declare RemoteExceptions
165        Method[] meths = mRemoteInterface.getDeclaredMethods();
166        for (int i = 0; i < meths.length; i++)
167          {
168            Class[] exceptions = meths[i].getExceptionTypes();
169            int index = 0;
170            for (; index < exceptions.length; index++)
171              {
172                if (exceptions[index].equals(RemoteException.class))
173                  break;
174              }
175            if (index < exceptions.length)
176              rmeths.add(meths[i]);
177            else
178              logError("Method " + meths[i]
179                       + " does not throw a java.rmi.RemoteException");
180          }
181    
182        // Convert into a MethodRef array and sort them
183        remotemethods = new MethodRef[rmeths.size()];
184        int c = 0;
185        for (Iterator i = rmeths.iterator(); i.hasNext();)
186          remotemethods[c++] = new MethodRef((Method) i.next());
187        Arrays.sort(remotemethods);
188      }
189    
190      public Exception getException()
191      {
192        return (exception);
193      }
194    
195      private void findClass() throws ClassNotFoundException
196      {
197        clazz =
198          Class.forName(fullclassname, true, ClassLoader.getSystemClassLoader());
199      }
200    
201      private void generateStub() throws IOException
202      {
203        stubname = fullclassname + "_Stub";
204        String stubclassname = classname + "_Stub";
205        ctrl =
206          new TabbedWriter(new FileWriter((destination == null ? ""
207                                                               : destination
208                                                               + File.separator)
209                                          + stubname.replace('.',
210                                                             File.separatorChar)
211                                          + ".java"));
212        out = new PrintWriter(ctrl);
213    
214        if (verbose)
215          System.out.println("[Generating class " + stubname + ".java]");
216    
217        out.println("// Stub class generated by rmic - DO NOT EDIT!");
218        out.println();
219        if (fullclassname != classname)
220          {
221            String pname =
222              fullclassname.substring(0, fullclassname.lastIndexOf('.'));
223            out.println("package " + pname + ";");
224            out.println();
225          }
226    
227  private boolean processClass(String classname) throws Exception {      out.print("public final class " + stubclassname);
228          errorCount = 0;      ctrl.indent();
229          analyzeClass(classname);      out.println("extends java.rmi.server.RemoteStub");
230          if(errorCount > 0) {  
231                  System.exit(1);      // Output interfaces we implement
232          }      out.print("implements ");
233          generateStub();      /* Scan implemented interfaces, and only print remote interfaces. */
234          if (need11Stubs) {      Class[] ifaces = clazz.getInterfaces();
235                  generateSkel();      Set remoteIfaces = new HashSet();
236          }      for (int i = 0; i < ifaces.length; i++)
237          if (compile) {        {
238                  compile(stubname.replace('.', File.separatorChar) + ".java");          Class iface = ifaces[i];
239                  if (need11Stubs) {          if (java.rmi.Remote.class.isAssignableFrom(iface))
240                          compile(skelname.replace('.', File.separatorChar) + ".java");            remoteIfaces.add(iface);
241                  }        }
242          }      Iterator iter = remoteIfaces.iterator();
243          if (!keep) {      while (iter.hasNext())
244                  (new File(stubname.replace('.', File.separatorChar) + ".java")).delete();        {
245                  if (need11Stubs) {          /* Print remote interface. */
246                          (new File(skelname.replace('.', File.separatorChar) + ".java")).delete();          Class iface = (Class) iter.next();
247                  }          out.print(iface.getName());
248          }  
249          return (true);          /* Print ", " if more remote interfaces follow. */
250  }          if (iter.hasNext())
251              out.print(", ");
252          }
253        ctrl.unindent();
254        out.print("{");
255        ctrl.indent();
256    
257        // UID
258        if (need12Stubs)
259          {
260            out.println("private static final long serialVersionUID = 2L;");
261            out.println();
262          }
263    
264  private void analyzeClass(String cname) throws Exception {      // InterfaceHash - don't know how to calculate this - XXX
265          if(verbose){      if (need11Stubs)
266                          System.out.println("[analyze class "+cname+"]");        {
267                  }          out.println("private static final long interfaceHash = "
268          int p = cname.lastIndexOf('.');                      + RMIHashes.getInterfaceHash(clazz) + "L;");
269          if (p != -1) {          out.println();
270                  classname = cname.substring(p+1);          if (need12Stubs)
271          }            {
272          else {              out.println("private static boolean useNewInvoke;");
273                  classname = cname;              out.println();
274          }            }
         fullclassname = cname;  
   
           
         HashSet rmeths = new HashSet();  
         findClass();  
           
         // get the remote interface  
         mRemoteInterface = getRemoteInterface(clazz);  
         if(mRemoteInterface == null)  
                 return;  
         if(verbose){  
                 System.out.println("[implements "+mRemoteInterface.getName()+"]");  
         }  
   
         // check if the methods of the remote interface declare RemoteExceptions  
         Method[] meths = mRemoteInterface.getDeclaredMethods();  
         for (int i = 0; i < meths.length; i++) {  
                 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;  
         for (Iterator i = rmeths.iterator(); i.hasNext(); ) {  
                 remotemethods[c++] = new MethodRef((Method)i.next());  
         }  
         Arrays.sort(remotemethods);  
 }  
275    
276  public Exception getException() {          // Operation table
277          return (exception);          out.print("private static final java.rmi.server.Operation[] operations = {");
 }  
278    
279  private void findClass() throws ClassNotFoundException {          ctrl.indent();
280          clazz = Class.forName(fullclassname, true, ClassLoader.getSystemClassLoader());          for (int i = 0; i < remotemethods.length; i++)
281  }            {
282                Method m = remotemethods[i].meth;
283                out.print("new java.rmi.server.Operation(\"");
284                out.print(getPrettyName(m.getReturnType()) + " ");
285                out.print(m.getName() + "(");
286                // Output signature
287                Class[] sig = m.getParameterTypes();
288                for (int j = 0; j < sig.length; j++)
289                  {
290                    out.print(getPrettyName(sig[j]));
291                    if (j + 1 < sig.length)
292                      out.print(", ");
293                  }
294                out.print(")\")");
295                if (i + 1 < remotemethods.length)
296                  out.println(",");
297              }
298            ctrl.unindent();
299            out.println("};");
300            out.println();
301          }
302    
303  private void generateStub() throws IOException {      // Set of method references.
304          stubname = fullclassname + "_Stub";      if (need12Stubs)
305          String stubclassname = classname + "_Stub";        {
306          ctrl = new TabbedWriter(new FileWriter((destination == null ? "" : destination + File.separator)          for (int i = 0; i < remotemethods.length; i++)
307                                                 + stubname.replace('.', File.separatorChar)            {
308                                                 + ".java"));              Method m = remotemethods[i].meth;
309          out = new PrintWriter(ctrl);              out.println("private static java.lang.reflect.Method $method_"
310                            + m.getName() + "_" + i + ";");
311          if (verbose) {            }
                 System.out.println("[Generating class " + stubname + ".java]");  
         }  
312    
313          out.println("// Stub class generated by rmic - DO NOT EDIT!");          // Initialize the methods references.
314          out.println();          out.println();
315          if (fullclassname != classname) {          out.print("static {");
316                  String pname = fullclassname.substring(0, fullclassname.lastIndexOf('.'));          ctrl.indent();
                 out.println("package " + pname + ";");  
                 out.println();  
         }  
317    
318          out.print("public final class " + stubclassname);          out.print("try {");
319          ctrl.indent();          ctrl.indent();
320          out.println("extends java.rmi.server.RemoteStub");  
321                    if (need11Stubs)
322          // Output interfaces we implement            {
323          out.print("implements ");              out.println("java.rmi.server.RemoteRef.class.getMethod(\"invoke\", new java.lang.Class[] { java.rmi.Remote.class, java.lang.reflect.Method.class, java.lang.Object[].class, long.class });");
324          /* Scan implemented interfaces, and only print remote interfaces. */              out.println("useNewInvoke = true;");
325          Class[] ifaces = clazz.getInterfaces();            }
326          Set remoteIfaces = new HashSet();  
327          for (int i = 0; i < ifaces.length; i++) {          for (int i = 0; i < remotemethods.length; i++)
328                  Class iface = ifaces[i];            {
329                  if (java.rmi.Remote.class.isAssignableFrom(iface)) {              Method m = remotemethods[i].meth;
330                          remoteIfaces.add(iface);              out.print("$method_" + m.getName() + "_" + i + " = ");
331                  }              out.print(mRemoteInterface.getName() + ".class.getMethod(\""
332          }                        + m.getName() + "\"");
333          Iterator iter = remoteIfaces.iterator();              out.print(", new java.lang.Class[] {");
334          while (iter.hasNext()) {              // Output signature
335                  /* Print remote interface. */              Class[] sig = m.getParameterTypes();
336                  Class iface = (Class) iter.next();              for (int j = 0; j < sig.length; j++)
337                  out.print(iface.getName());                {
338                    out.print(getPrettyName(sig[j]) + ".class");
339                  /* Print ", " if more remote interfaces follow. */                  if (j + 1 < sig.length)
340                  if (iter.hasNext()) {                    out.print(", ");
341                          out.print(", ");                }
342                  }              out.println("});");
343          }            }
344          ctrl.unindent();          ctrl.unindent();
345          out.print("{");          out.println("}");
346            out.print("catch (java.lang.NoSuchMethodException e) {");
347          ctrl.indent();          ctrl.indent();
348            if (need11Stubs)
349              out.print("useNewInvoke = false;");
350            else
351              out.print("throw new java.lang.NoSuchMethodError(\"stub class initialization failed\");");
352    
353          // UID          ctrl.unindent();
354          if (need12Stubs) {          out.print("}");
                 out.println("private static final long serialVersionUID = 2L;");  
                 out.println();  
         }  
355    
356          // InterfaceHash - don't know how to calculate this - XXX          ctrl.unindent();
357          if (need11Stubs) {          out.println("}");
358                  out.println("private static final long interfaceHash = " + RMIHashes.getInterfaceHash(clazz) + "L;");          out.println();
359                  out.println();        }
                 if (need12Stubs) {  
                         out.println("private static boolean useNewInvoke;");  
                         out.println();  
                 }  
360    
361                  // Operation table      // Constructors
362                  out.print("private static final java.rmi.server.Operation[] operations = {");      if (need11Stubs)
363          {
364            out.print("public " + stubclassname + "() {");
365            ctrl.indent();
366            out.print("super();");
367            ctrl.unindent();
368            out.println("}");
369          }
370    
371                  ctrl.indent();      if (need12Stubs)
372                  for (int i = 0; i < remotemethods.length; i++) {        {
373                          Method m = remotemethods[i].meth;          out.print("public " + stubclassname
374                          out.print("new java.rmi.server.Operation(\"");                    + "(java.rmi.server.RemoteRef ref) {");
375                          out.print(getPrettyName(m.getReturnType()) + " ");          ctrl.indent();
376                          out.print(m.getName() + "(");          out.print("super(ref);");
377                          // Output signature          ctrl.unindent();
378                          Class[] sig = m.getParameterTypes();          out.println("}");
379                          for (int j = 0; j < sig.length; j++) {        }
                                 out.print(getPrettyName(sig[j]));  
                                 if (j+1 < sig.length) {  
                                         out.print(", ");  
                                 }  
                         }  
                         out.print(")\")");  
                         if (i + 1 < remotemethods.length) {  
                                 out.println(",");  
                         }  
                 }  
                 ctrl.unindent();  
                 out.println("};");  
                 out.println();  
         }  
380    
381          // Set of method references.      // Method implementations
382          if (need12Stubs) {      for (int i = 0; i < remotemethods.length; i++)
383                  for (int i = 0; i < remotemethods.length; i++) {        {
384                          Method m = remotemethods[i].meth;          Method m = remotemethods[i].meth;
385                          out.println("private static java.lang.reflect.Method $method_" + m.getName() + "_" + i + ";");          Class[] sig = m.getParameterTypes();
386                  }          Class returntype = m.getReturnType();
387            Class[] except = sortExceptions(m.getExceptionTypes());
388    
389                  // Initialize the methods references.          out.println();
390                  out.println();          out.print("public " + getPrettyName(returntype) + " " + m.getName()
391                  out.print("static {");                    + "(");
392                  ctrl.indent();          for (int j = 0; j < sig.length; j++)
393              {
394                out.print(getPrettyName(sig[j]));
395                out.print(" $param_" + j);
396                if (j + 1 < sig.length)
397                  out.print(", ");
398              }
399            out.print(") ");
400            out.print("throws ");
401            for (int j = 0; j < except.length; j++)
402              {
403                out.print(getPrettyName(except[j]));
404                if (j + 1 < except.length)
405                  out.print(", ");
406              }
407            out.print(" {");
408            ctrl.indent();
409    
410                  out.print("try {");          out.print("try {");
411                  ctrl.indent();          ctrl.indent();
412    
413                  if (need11Stubs) {          if (need12Stubs)
414                          out.println("java.rmi.server.RemoteRef.class.getMethod(\"invoke\", new java.lang.Class[] { java.rmi.Remote.class, java.lang.reflect.Method.class, java.lang.Object[].class, long.class });");            {
415                          out.println("useNewInvoke = true;");              if (need11Stubs)
416                  }                {
417                    out.print("if (useNewInvoke) {");
                 for (int i = 0; i < remotemethods.length; i++) {  
                         Method m = remotemethods[i].meth;  
                         out.print("$method_" + m.getName() + "_" + i + " = ");  
                         out.print(mRemoteInterface.getName() + ".class.getMethod(\"" + m.getName() + "\"");  
                         out.print(", new java.lang.Class[] {");  
                         // Output signature  
                         Class[] sig = m.getParameterTypes();  
                         for (int j = 0; j < sig.length; j++) {  
                                 out.print(getPrettyName(sig[j]) + ".class");  
                                 if (j+1 < sig.length) {  
                                         out.print(", ");  
                                 }  
                         }  
                         out.println("});");  
                 }  
                 ctrl.unindent();  
                 out.println("}");  
                 out.print("catch (java.lang.NoSuchMethodException e) {");  
418                  ctrl.indent();                  ctrl.indent();
419                  if (need11Stubs) {                }
420                          out.print("useNewInvoke = false;");              if (returntype != Void.TYPE)
421                  }                out.print("java.lang.Object $result = ");
422                  else {              out.print("ref.invoke(this, $method_" + m.getName() + "_" + i
423                          out.print("throw new java.lang.NoSuchMethodError(\"stub class initialization failed\");");                        + ", ");
424                  }              if (sig.length == 0)
425                  out.print("null, ");
426                  ctrl.unindent();              else
427                  out.print("}");                {
428                    out.print("new java.lang.Object[] {");
429                    for (int j = 0; j < sig.length; j++)
430                      {
431                        if (sig[j] == Boolean.TYPE)
432                          out.print("new java.lang.Boolean($param_" + j + ")");
433                        else if (sig[j] == Byte.TYPE)
434                          out.print("new java.lang.Byte($param_" + j + ")");
435                        else if (sig[j] == Character.TYPE)
436                          out.print("new java.lang.Character($param_" + j + ")");
437                        else if (sig[j] == Short.TYPE)
438                          out.print("new java.lang.Short($param_" + j + ")");
439                        else if (sig[j] == Integer.TYPE)
440                          out.print("new java.lang.Integer($param_" + j + ")");
441                        else if (sig[j] == Long.TYPE)
442                          out.print("new java.lang.Long($param_" + j + ")");
443                        else if (sig[j] == Float.TYPE)
444                          out.print("new java.lang.Float($param_" + j + ")");
445                        else if (sig[j] == Double.TYPE)
446                          out.print("new java.lang.Double($param_" + j + ")");
447                        else
448                          out.print("$param_" + j);
449                        if (j + 1 < sig.length)
450                          out.print(", ");
451                      }
452                    out.print("}, ");
453                  }
454                out.print(Long.toString(remotemethods[i].hash) + "L");
455                out.print(");");
456    
457                  ctrl.unindent();              if (returntype != Void.TYPE)
458                  out.println("}");                {
459                  out.println();                  out.println();
460          }                  out.print("return (");
461                    if (returntype == Boolean.TYPE)
462                      out.print("((java.lang.Boolean)$result).booleanValue()");
463                    else if (returntype == Byte.TYPE)
464                      out.print("((java.lang.Byte)$result).byteValue()");
465                    else if (returntype == Character.TYPE)
466                      out.print("((java.lang.Character)$result).charValue()");
467                    else if (returntype == Short.TYPE)
468                      out.print("((java.lang.Short)$result).shortValue()");
469                    else if (returntype == Integer.TYPE)
470                      out.print("((java.lang.Integer)$result).intValue()");
471                    else if (returntype == Long.TYPE)
472                      out.print("((java.lang.Long)$result).longValue()");
473                    else if (returntype == Float.TYPE)
474                      out.print("((java.lang.Float)$result).floatValue()");
475                    else if (returntype == Double.TYPE)
476                      out.print("((java.lang.Double)$result).doubleValue()");
477                    else
478                      out.print("(" + getPrettyName(returntype) + ")$result");
479                    out.print(");");
480                  }
481    
482          // Constructors              if (need11Stubs)
483          if (need11Stubs) {                {
                 out.print("public " + stubclassname + "() {");  
                 ctrl.indent();  
                 out.print("super();");  
484                  ctrl.unindent();                  ctrl.unindent();
485                  out.println("}");                  out.println("}");
486          }                  out.print("else {");
   
         if (need12Stubs) {  
                 out.print("public " + stubclassname + "(java.rmi.server.RemoteRef ref) {");  
487                  ctrl.indent();                  ctrl.indent();
488                  out.print("super(ref);");                }
489                  ctrl.unindent();            }
                 out.println("}");  
         }  
   
         // Method implementations  
         for (int i = 0; i < remotemethods.length; i++) {  
                 Method m = remotemethods[i].meth;  
                 Class[] sig = m.getParameterTypes();  
                 Class returntype = m.getReturnType();  
                 Class[] except = sortExceptions(m.getExceptionTypes());  
490    
491            if (need11Stubs)
492              {
493                out.println("java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, "
494                            + i + ", interfaceHash);");
495                out.print("try {");
496                ctrl.indent();
497                out.print("java.io.ObjectOutput out = call.getOutputStream();");
498                for (int j = 0; j < sig.length; j++)
499                  {
500                  out.println();                  out.println();
501                  out.print("public " + getPrettyName(returntype) + " " + m.getName() + "(");                  if (sig[j] == Boolean.TYPE)
502                  for (int j = 0; j < sig.length; j++) {                    out.print("out.writeBoolean(");
503                          out.print(getPrettyName(sig[j]));                  else if (sig[j] == Byte.TYPE)
504                          out.print(" $param_" + j);                    out.print("out.writeByte(");
505                          if (j+1 < sig.length) {                  else if (sig[j] == Character.TYPE)
506                                  out.print(", ");                    out.print("out.writeChar(");
507                          }                  else if (sig[j] == Short.TYPE)
508                  }                    out.print("out.writeShort(");
509                  out.print(") ");                  else if (sig[j] == Integer.TYPE)
510                  out.print("throws ");                    out.print("out.writeInt(");
511                  for (int j = 0; j < except.length; j++) {                  else if (sig[j] == Long.TYPE)
512                          out.print(getPrettyName(except[j]));                    out.print("out.writeLong(");
513                          if (j+1 < except.length) {                  else if (sig[j] == Float.TYPE)
514                                  out.print(", ");                    out.print("out.writeFloat(");
515                          }                  else if (sig[j] == Double.TYPE)
516                  }                    out.print("out.writeDouble(");
517                  out.print(" {");                  else
518                  ctrl.indent();                    out.print("out.writeObject(");
519                    out.print("$param_" + j + ");");
520                  out.print("try {");                }
521                ctrl.unindent();
522                out.println("}");
523                out.print("catch (java.io.IOException e) {");
524                ctrl.indent();
525                out.print("throw new java.rmi.MarshalException(\"error marshalling arguments\", e);");
526                ctrl.unindent();
527                out.println("}");
528                out.println("ref.invoke(call);");
529                if (returntype != Void.TYPE)
530                  out.println(getPrettyName(returntype) + " $result;");
531                out.print("try {");
532                ctrl.indent();
533                out.print("java.io.ObjectInput in = call.getInputStream();");
534                boolean needcastcheck = false;
535                if (returntype != Void.TYPE)
536                  {
537                    out.println();
538                    out.print("$result = ");
539                    if (returntype == Boolean.TYPE)
540                      out.print("in.readBoolean();");
541                    else if (returntype == Byte.TYPE)
542                      out.print("in.readByte();");
543                    else if (returntype == Character.TYPE)
544                      out.print("in.readChar();");
545                    else if (returntype == Short.TYPE)
546                      out.print("in.readShort();");
547                    else if (returntype == Integer.TYPE)
548                      out.print("in.readInt();");
549                    else if (returntype == Long.TYPE)
550                      out.print("in.readLong();");
551                    else if (returntype == Float.TYPE)
552                      out.print("in.readFloat();");
553                    else if (returntype == Double.TYPE)
554                      out.print("in.readDouble();");
555                    else
556                      {
557                        if (returntype != Object.class)
558                          out.print("(" + getPrettyName(returntype) + ")");
559                        else
560                          needcastcheck = true;
561                        out.print("in.readObject();");
562                      }
563                    out.println();
564                    out.print("return ($result);");
565                  }
566                ctrl.unindent();
567                out.println("}");
568                out.print("catch (java.io.IOException e) {");
569                ctrl.indent();
570                out.print("throw new java.rmi.UnmarshalException(\"error unmarshalling return\", e);");
571                ctrl.unindent();
572                out.println("}");
573                if (needcastcheck)
574                  {
575                    out.print("catch (java.lang.ClassNotFoundException e) {");
576                  ctrl.indent();                  ctrl.indent();
577                    out.print("throw new java.rmi.UnmarshalException(\"error unmarshalling return\", e);");
                 if (need12Stubs) {  
                         if (need11Stubs) {  
                                 out.print("if (useNewInvoke) {");  
                                 ctrl.indent();  
                         }  
                         if (returntype != Void.TYPE) {  
                                 out.print("java.lang.Object $result = ");  
                         }  
                         out.print("ref.invoke(this, $method_" + m.getName() + "_" + i + ", ");  
                         if (sig.length == 0) {  
                                 out.print("null, ");  
                         }  
                         else {  
                                 out.print("new java.lang.Object[] {");  
                                 for (int j = 0; j < sig.length; j++) {  
                                         if (sig[j] == Boolean.TYPE) {  
                                                 out.print("new java.lang.Boolean($param_" + j + ")");  
                                         }  
                                         else if (sig[j] == Byte.TYPE) {  
                                                 out.print("new java.lang.Byte($param_" + j + ")");  
                                         }  
                                         else if (sig[j] == Character.TYPE) {  
                                                 out.print("new java.lang.Character($param_" + j + ")");  
                                         }  
                                         else if (sig[j] == Short.TYPE) {  
                                                 out.print("new java.lang.Short($param_" + j + ")");  
                                         }  
                                         else if (sig[j] == Integer.TYPE) {  
                                                 out.print("new java.lang.Integer($param_" + j + ")");  
                                         }  
                                         else if (sig[j] == Long.TYPE) {  
                                                 out.print("new java.lang.Long($param_" + j + ")");  
                                         }  
                                         else if (sig[j] == Float.TYPE) {  
                                                 out.print("new java.lang.Float($param_" + j + ")");  
                                         }  
                                         else if (sig[j] == Double.TYPE) {  
                                                 out.print("new java.lang.Double($param_" + j + ")");  
                                         }  
                                         else {  
                                                 out.print("$param_" + j);  
                                         }  
                                         if (j+1 < sig.length) {  
                                                 out.print(", ");  
                                         }  
                                 }  
                                 out.print("}, ");  
                         }  
                         out.print(Long.toString(remotemethods[i].hash) + "L");  
                         out.print(");");  
   
                         if (returntype != Void.TYPE) {  
                                 out.println();  
                                 out.print("return (");  
                                 if (returntype == Boolean.TYPE) {  
                                         out.print("((java.lang.Boolean)$result).booleanValue()");  
                                 }  
                                 else if (returntype == Byte.TYPE) {  
                                         out.print("((java.lang.Byte)$result).byteValue()");  
                                 }  
                                 else if (returntype == Character.TYPE) {  
                                         out.print("((java.lang.Character)$result).charValue()");  
                                 }  
                                 else if (returntype == Short.TYPE) {  
                                         out.print("((java.lang.Short)$result).shortValue()");  
                                 }  
                                 else if (returntype == Integer.TYPE) {  
                                         out.print("((java.lang.Integer)$result).intValue()");  
                                 }  
                                 else if (returntype == Long.TYPE) {  
                                         out.print("((java.lang.Long)$result).longValue()");  
                                 }  
                                 else if (returntype == Float.TYPE) {  
                                         out.print("((java.lang.Float)$result).floatValue()");  
                                 }  
                                 else if (returntype == Double.TYPE) {  
                                         out.print("((java.lang.Double)$result).doubleValue()");  
                                 }  
                                 else {  
                                         out.print("(" + getPrettyName(returntype) + ")$result");  
                                 }  
                                 out.print(");");  
                         }  
   
                         if (need11Stubs) {  
                                 ctrl.unindent();  
                                 out.println("}");  
                                 out.print("else {");  
                                 ctrl.indent();  
                         }  
                 }  
   
                 if (need11Stubs) {  
                         out.println("java.rmi.server.RemoteCall call = ref.newCall((java.rmi.server.RemoteObject)this, operations, " + i + ", interfaceHash);");  
                         out.print("try {");  
                         ctrl.indent();  
                         out.print("java.io.ObjectOutput out = call.getOutputStream();");  
                         for (int j = 0; j < sig.length; j++) {  
                                 out.println();  
                                 if (sig[j] == Boolean.TYPE) {  
                                         out.print("out.writeBoolean(");  
                                 }  
                                 else if (sig[j] == Byte.TYPE) {  
                                         out.print("out.writeByte(");  
                                 }  
                                 else if (sig[j] == Character.TYPE) {  
                                         out.print("out.writeChar(");  
                                 }  
                                 else if (sig[j] == Short.TYPE) {  
                                         out.print("out.writeShort(");  
                                 }  
                                 else if (sig[j] == Integer.TYPE) {  
                                         out.print("out.writeInt(");  
                                 }  
                                 else if (sig[j] == Long.TYPE) {  
                                         out.print("out.writeLong(");  
                                 }  
                                 else if (sig[j] == Float.TYPE) {  
                                         out.print("out.writeFloat(");  
                                 }  
                                 else if (sig[j] == Double.TYPE) {  
                                         out.print("out.writeDouble(");  
                                 }  
                                 else {  
                                         out.print("out.writeObject(");  
                                 }  
                                 out.print("$param_" + j + ");");  
                         }  
                         ctrl.unindent();  
                         out.println("}");  
                         out.print("catch (java.io.IOException e) {");  
                         ctrl.indent();  
                         out.print("throw new java.rmi.MarshalException(\"error marshalling arguments\", e);");  
                         ctrl.unindent();  
                         out.println("}");  
                         out.println("ref.invoke(call);");  
                         if (returntype != Void.TYPE) {  
                                 out.println(getPrettyName(returntype) + " $result;");  
                         }  
                         out.print("try {");  
                         ctrl.indent();  
                         out.print("java.io.ObjectInput in = call.getInputStream();");  
                         boolean needcastcheck = false;  
                         if (returntype != Void.TYPE) {  
                                 out.println();  
                                 out.print("$result = ");  
                                 if (returntype == Boolean.TYPE) {  
                                         out.print("in.readBoolean();");  
                                 }  
                                 else if (returntype == Byte.TYPE) {  
                                         out.print("in.readByte();");  
                                 }  
                                 else if (returntype == Character.TYPE) {  
                                         out.print("in.readChar();");  
                                 }  
                                 else if (returntype == Short.TYPE) {  
                                         out.print("in.readShort();");  
                                 }  
                                 else if (returntype == Integer.TYPE) {  
                                         out.print("in.readInt();");  
                                 }  
                                 else if (returntype == Long.TYPE) {  
                                         out.print("in.readLong();");  
                                 }  
                                 else if (returntype == Float.TYPE) {  
                                         out.print("in.readFloat();");  
                                 }  
                                 else if (returntype == Double.TYPE) {  
                                         out.print("in.readDouble();");  
                                 }  
                                 else {  
                                         if (returntype != Object.class) {  
                                                 out.print("(" + getPrettyName(returntype) + ")");  
                                         }  
                                         else {  
                                                 needcastcheck = true;  
                                         }  
                                         out.print("in.readObject();");  
                                 }  
                                 out.println();  
                                 out.print("return ($result);");  
                         }  
                         ctrl.unindent();  
                         out.println("}");  
                         out.print("catch (java.io.IOException e) {");  
                         ctrl.indent();  
                         out.print("throw new java.rmi.UnmarshalException(\"error unmarshalling return\", e);");  
                         ctrl.unindent();  
                         out.println("}");  
                         if (needcastcheck) {  
                                 out.print("catch (java.lang.ClassNotFoundException e) {");  
                                 ctrl.indent();  
                                 out.print("throw new java.rmi.UnmarshalException(\"error unmarshalling return\", e);");  
                                 ctrl.unindent();  
                                 out.println("}");  
                         }  
                         out.print("finally {");  
                         ctrl.indent();  
                         out.print("ref.done(call);");  
                         ctrl.unindent();  
                         out.print("}");  
   
                         if (need12Stubs && need11Stubs) {  
                                 ctrl.unindent();  
                                 out.print("}");  
                         }  
                 }  
   
578                  ctrl.unindent();                  ctrl.unindent();
579                  out.print("}");                  out.println("}");
580                  }
581                  boolean needgeneral = true;              out.print("finally {");
582                  for (int j = 0; j < except.length; j++) {              ctrl.indent();
583                          out.println();              out.print("ref.done(call);");
584                          out.print("catch (" + getPrettyName(except[j]) + " e) {");              ctrl.unindent();
585                          ctrl.indent();              out.print("}");
                         out.print("throw e;");  
                         ctrl.unindent();  
                         out.print("}");  
                         if (except[j] == Exception.class) {  
                                 needgeneral = false;  
                         }  
                 }  
                 if (needgeneral) {  
                         out.println();  
                         out.print("catch (java.lang.Exception e) {");  
                         ctrl.indent();  
                         out.print("throw new java.rmi.UnexpectedException(\"undeclared checked exception\", e);");  
                         ctrl.unindent();  
                         out.print("}");  
                 }  
586    
587                if (need12Stubs && need11Stubs)
588                  {
589                  ctrl.unindent();                  ctrl.unindent();
590                  out.print("}");                  out.print("}");
591                  out.println();                }
592          }            }
593    
594          ctrl.unindent();          ctrl.unindent();
595          out.println("}");          out.print("}");
   
         out.close();  
 }  
596    
597  private void generateSkel() throws IOException {          boolean needgeneral = true;
598          skelname = fullclassname + "_Skel";          for (int j = 0; j < except.length; j++)
599          String skelclassname = classname + "_Skel";            {
600          ctrl = new TabbedWriter(new FileWriter((destination == null ? "" : destination + File.separator)              out.println();
601                                                 + skelname.replace('.', File.separatorChar)              out.print("catch (" + getPrettyName(except[j]) + " e) {");
602                                                 + ".java"));              ctrl.indent();
603          out = new PrintWriter(ctrl);              out.print("throw e;");
604                ctrl.unindent();
605          if (verbose) {              out.print("}");
606                  System.out.println("[Generating class " + skelname + ".java]");              if (except[j] == Exception.class)
607          }                needgeneral = false;
608              }
609            if (needgeneral)
610              {
611                out.println();
612                out.print("catch (java.lang.Exception e) {");
613                ctrl.indent();
614                out.print("throw new java.rmi.UnexpectedException(\"undeclared checked exception\", e);");
615                ctrl.unindent();
616                out.print("}");
617              }
618    
619          out.println("// Skel class generated by rmic - DO NOT EDIT!");          ctrl.unindent();
620            out.print("}");
621          out.println();          out.println();
622          if (fullclassname != classname) {        }
                 String pname = fullclassname.substring(0, fullclassname.lastIndexOf('.'));  
                 out.println("package " + pname + ";");  
                 out.println();  
         }  
623    
624          out.print("public final class " + skelclassname);      ctrl.unindent();
625          ctrl.indent();      out.println("}");
           
         // Output interfaces we implement  
         out.print("implements java.rmi.server.Skeleton");  
626    
627          ctrl.unindent();      out.close();
628          out.print("{");    }
         ctrl.indent();  
629    
630          // Interface hash - don't know how to calculate this - XXX    private void generateSkel() throws IOException
631          out.println("private static final long interfaceHash = " + RMIHashes.getInterfaceHash(clazz) + "L;");    {
632        skelname = fullclassname + "_Skel";
633        String skelclassname = classname + "_Skel";
634        ctrl =
635          new TabbedWriter(new FileWriter((destination == null ? ""
636                                                               : destination
637                                                               + File.separator)
638                                          + skelname.replace('.',
639                                                             File.separatorChar)
640                                          + ".java"));
641        out = new PrintWriter(ctrl);
642    
643        if (verbose)
644          System.out.println("[Generating class " + skelname + ".java]");
645    
646        out.println("// Skel class generated by rmic - DO NOT EDIT!");
647        out.println();
648        if (fullclassname != classname)
649          {
650            String pname =
651              fullclassname.substring(0, fullclassname.lastIndexOf('.'));
652            out.println("package " + pname + ";");
653          out.println();          out.println();
654          }
655    
656          // Operation table      out.print("public final class " + skelclassname);
657          out.print("private static final java.rmi.server.Operation[] operations = {");      ctrl.indent();
   
         ctrl.indent();  
         for (int i = 0; i < remotemethods.length; i++) {  
                 Method m = remotemethods[i].meth;  
                 out.print("new java.rmi.server.Operation(\"");  
                 out.print(getPrettyName(m.getReturnType()) + " ");  
                 out.print(m.getName() + "(");  
                 // Output signature  
                 Class[] sig = m.getParameterTypes();  
                 for (int j = 0; j < sig.length; j++) {  
                         out.print(getPrettyName(sig[j]));  
                         if (j+1 < sig.length) {  
                                 out.print(", ");  
                         }  
                 }  
                 out.print("\")");  
                 if (i + 1 < remotemethods.length) {  
                         out.println(",");  
                 }  
         }  
         ctrl.unindent();  
         out.println("};");  
658    
659          out.println();      // Output interfaces we implement
660        out.print("implements java.rmi.server.Skeleton");
661    
662          // getOperations method      ctrl.unindent();
663          out.print("public java.rmi.server.Operation[] getOperations() {");      out.print("{");
664        ctrl.indent();
665    
666        // Interface hash - don't know how to calculate this - XXX
667        out.println("private static final long interfaceHash = "
668                    + RMIHashes.getInterfaceHash(clazz) + "L;");
669        out.println();
670    
671        // Operation table
672        out.print("private static final java.rmi.server.Operation[] operations = {");
673    
674        ctrl.indent();
675        for (int i = 0; i < remotemethods.length; i++)
676          {
677            Method m = remotemethods[i].meth;
678            out.print("new java.rmi.server.Operation(\"");
679            out.print(getPrettyName(m.getReturnType()) + " ");
680            out.print(m.getName() + "(");
681            // Output signature
682            Class[] sig = m.getParameterTypes();
683            for (int j = 0; j < sig.length; j++)
684              {
685                out.print(getPrettyName(sig[j]));
686                if (j + 1 < sig.length)
687                  out.print(", ");
688              }
689            out.print("\")");
690            if (i + 1 < remotemethods.length)
691              out.println(",");
692          }
693        ctrl.unindent();
694        out.println("};");
695    
696        out.println();
697    
698        // getOperations method
699        out.print("public java.rmi.server.Operation[] getOperations() {");
700        ctrl.indent();
701        out.print("return ((java.rmi.server.Operation[]) operations.clone());");
702        ctrl.unindent();
703        out.println("}");
704    
705        out.println();
706    
707        // Dispatch method
708        out.print("public void dispatch(java.rmi.Remote obj, java.rmi.server.RemoteCall call, int opnum, long hash) throws java.lang.Exception {");
709        ctrl.indent();
710    
711        out.print("if (opnum < 0) {");
712        ctrl.indent();
713    
714        for (int i = 0; i < remotemethods.length; i++)
715          {
716            out.print("if (hash == " + Long.toString(remotemethods[i].hash)
717                      + "L) {");
718          ctrl.indent();          ctrl.indent();
719          out.print("return ((java.rmi.server.Operation[]) operations.clone());");          out.print("opnum = " + i + ";");
720          ctrl.unindent();          ctrl.unindent();
721          out.println("}");          out.println("}");
722            out.print("else ");
723          out.println();        }
724        out.print("{");
725          // Dispatch method      ctrl.indent();
726          out.print("public void dispatch(java.rmi.Remote obj, java.rmi.server.RemoteCall call, int opnum, long hash) throws java.lang.Exception {");      out.print("throw new java.rmi.server.SkeletonMismatchException(\"interface hash mismatch\");");
727        ctrl.unindent();
728        out.print("}");
729    
730        ctrl.unindent();
731        out.println("}");
732        out.print("else if (hash != interfaceHash) {");
733        ctrl.indent();
734        out.print("throw new java.rmi.server.SkeletonMismatchException(\"interface hash mismatch\");");
735        ctrl.unindent();
736        out.println("}");
737    
738        out.println();
739    
740        out.println(fullclassname + " server = (" + fullclassname + ")obj;");
741        out.println("switch (opnum) {");
742    
743        // Method dispatch
744        for (int i = 0; i < remotemethods.length; i++)
745          {
746            Method m = remotemethods[i].meth;
747            out.println("case " + i + ":");
748            out.print("{");
749          ctrl.indent();          ctrl.indent();
750    
751          out.print("if (opnum < 0) {");          Class[] sig = m.getParameterTypes();
752          ctrl.indent();          for (int j = 0; j < sig.length; j++)
753              {
754                out.print(getPrettyName(sig[j]));
755                out.println(" $param_" + j + ";");
756              }
757    
758          for (int i = 0; i < remotemethods.length; i++) {          out.print("try {");
759                  out.print("if (hash == " + Long.toString(remotemethods[i].hash) + "L) {");          boolean needcastcheck = false;
                 ctrl.indent();  
                 out.print("opnum = " + i + ";");  
                 ctrl.unindent();  
                 out.println("}");  
                 out.print("else ");  
         }  
         out.print("{");  
760          ctrl.indent();          ctrl.indent();
761          out.print("throw new java.rmi.server.SkeletonMismatchException(\"interface hash mismatch\");");          out.println("java.io.ObjectInput in = call.getInputStream();");
762            for (int j = 0; j < sig.length; j++)
763              {
764                out.print("$param_" + j + " = ");
765                if (sig[j] == Boolean.TYPE)
766                  out.print("in.readBoolean();");
767                else if (sig[j] == Byte.TYPE)
768                  out.print("in.readByte();");
769                else if (sig[j] == Character.TYPE)
770                  out.print("in.readChar();");
771                else if (sig[j] == Short.TYPE)
772                  out.print("in.readShort();");
773                else if (sig[j] == Integer.TYPE)
774                  out.print("in.readInt();");
775                else if (sig[j] == Long.TYPE)
776                  out.print("in.readLong();");
777                else if (sig[j] == Float.TYPE)
778                  out.print("in.readFloat();");
779                else if (sig[j] == Double.TYPE)
780                  out.print("in.readDouble();");
781                else
782                  {
783                    if (sig[j] != Object.class)
784                      {
785                        out.print("(" + getPrettyName(sig[j]) + ")");
786                        needcastcheck = true;
787                      }
788                    out.print("in.readObject();");
789                  }
790                out.println();
791              }
792          ctrl.unindent();          ctrl.unindent();
793          out.print("}");          out.println("}");
794            out.print("catch (java.io.IOException e) {");
795            ctrl.indent();
796            out.print("throw new java.rmi.UnmarshalException(\"error unmarshalling arguments\", e);");
797          ctrl.unindent();          ctrl.unindent();
798          out.println("}");          out.println("}");
799          out.print("else if (hash != interfaceHash) {");          if (needcastcheck)
800              {
801                out.print("catch (java.lang.ClassCastException e) {");
802                ctrl.indent();
803                out.print("throw new java.rmi.UnmarshalException(\"error unmarshalling arguments\", e);");
804                ctrl.unindent();
805                out.println("}");
806              }
807            out.print("finally {");
808          ctrl.indent();          ctrl.indent();
809          out.print("throw new java.rmi.server.SkeletonMismatchException(\"interface hash mismatch\");");          out.print("call.releaseInputStream();");
810          ctrl.unindent();          ctrl.unindent();
811          out.println("}");          out.println("}");
812    
813          out.println();          Class returntype = m.getReturnType();
814            if (returntype != Void.TYPE)
815          out.println(fullclassname + " server = (" + fullclassname + ")obj;");            out.print(getPrettyName(returntype) + " $result = ");
816          out.println("switch (opnum) {");          out.print("server." + m.getName() + "(");
817            for (int j = 0; j < sig.length; j++)
818          // Method dispatch            {
819          for (int i = 0; i < remotemethods.length; i++) {              out.print("$param_" + j);
820                  Method m = remotemethods[i].meth;              if (j + 1 < sig.length)
821                  out.println("case " + i + ":");                out.print(", ");
822                  out.print("{");            }
823                  ctrl.indent();          out.println(");");
   
                 Class[] sig = m.getParameterTypes();  
                 for (int j = 0; j < sig.length; j++) {  
                         out.print(getPrettyName(sig[j]));  
                         out.println(" $param_" + j + ";");  
                 }  
   
                 out.print("try {");  
                 boolean needcastcheck = false;  
                 ctrl.indent();  
                 out.println("java.io.ObjectInput in = call.getInputStream();");  
                 for (int j = 0; j < sig.length; j++) {  
                         out.print("$param_" + j + " = ");  
                         if (sig[j] == Boolean.TYPE) {  
                                 out.print("in.readBoolean();");  
                         }  
                         else if (sig[j] == Byte.TYPE) {  
                                 out.print("in.readByte();");  
                         }  
                         else if (sig[j] == Character.TYPE) {  
                                 out.print("in.readChar();");  
                         }  
                         else if (sig[j] == Short.TYPE) {  
                                 out.print("in.readShort();");  
                         }  
                         else if (sig[j] == Integer.TYPE) {  
                                 out.print("in.readInt();");  
                         }  
                         else if (sig[j] == Long.TYPE) {  
                                 out.print("in.readLong();");  
                         }  
                         else if (sig[j] == Float.TYPE) {  
                                 out.print("in.readFloat();");  
                         }  
                         else if (sig[j] == Double.TYPE) {  
                                 out.print("in.readDouble();");  
                         }  
                         else {  
                                 if (sig[j] != Object.class) {  
                                         out.print("(" + getPrettyName(sig[j]) + ")");  
                                         needcastcheck = true;  
                                 }  
                                 out.print("in.readObject();");  
                         }  
                         out.println();  
                 }  
                 ctrl.unindent();  
                 out.println("}");  
                 out.print("catch (java.io.IOException e) {");  
                 ctrl.indent();  
                 out.print("throw new java.rmi.UnmarshalException(\"error unmarshalling arguments\", e);");  
                 ctrl.unindent();  
                 out.println("}");  
                 if (needcastcheck) {  
                         out.print("catch (java.lang.ClassCastException e) {");  
                         ctrl.indent();  
                         out.print("throw new java.rmi.UnmarshalException(\"error unmarshalling arguments\", e);");  
                         ctrl.unindent();  
                         out.println("}");  
                 }  
                 out.print("finally {");  
                 ctrl.indent();  
                 out.print("call.releaseInputStream();");  
                 ctrl.unindent();  
                 out.println("}");  
   
                 Class returntype = m.getReturnType();  
                 if (returntype != Void.TYPE) {  
                         out.print(getPrettyName(returntype) + " $result = ");  
                 }  
                 out.print("server." + m.getName() + "(");  
                 for (int j = 0; j < sig.length; j++) {  
                         out.print("$param_" + j);  
                         if (j + 1 < sig.length) {  
                                 out.print(", ");  
                         }  
                 }  
                 out.println(");");  
   
                 out.print("try {");  
                 ctrl.indent();  
                 out.print("java.io.ObjectOutput out = call.getResultStream(true);");  
                 if (returntype != Void.TYPE) {  
                         out.println();  
                         if (returntype == Boolean.TYPE) {  
                                 out.print("out.writeBoolean($result);");  
                         }  
                         else if (returntype == Byte.TYPE) {  
                                 out.print("out.writeByte($result);");  
                         }  
                         else if (returntype == Character.TYPE) {  
                                 out.print("out.writeChar($result);");  
                         }  
                         else if (returntype == Short.TYPE) {  
                                 out.print("out.writeShort($result);");  
                         }  
                         else if (returntype == Integer.TYPE) {  
                                 out.print("out.writeInt($result);");  
                         }  
                         else if (returntype == Long.TYPE) {  
                                 out.print("out.writeLong($result);");  
                         }  
                         else if (returntype == Float.TYPE) {  
                                 out.print("out.writeFloat($result);");  
                         }  
                         else if (returntype == Double.TYPE) {  
                                 out.print("out.writeDouble($result);");  
                         }  
                         else {  
                                 out.print("out.writeObject($result);");  
                         }  
                 }  
                 ctrl.unindent();  
                 out.println("}");  
                 out.print("catch (java.io.IOException e) {");  
                 ctrl.indent();  
                 out.print("throw new java.rmi.MarshalException(\"error marshalling return\", e);");  
                 ctrl.unindent();  
                 out.println("}");  
                 out.print("break;");  
   
                 ctrl.unindent();  
                 out.println("}");  
                 out.println();  
         }  
824    
825          out.print("default:");          out.print("try {");
826          ctrl.indent();          ctrl.indent();
827          out.print("throw new java.rmi.UnmarshalException(\"invalid method number\");");          out.print("java.io.ObjectOutput out = call.getResultStream(true);");
828            if (returntype != Void.TYPE)
829              {
830                out.println();
831                if (returntype == Boolean.TYPE)
832                  out.print("out.writeBoolean($result);");
833                else if (returntype == Byte.TYPE)
834                  out.print("out.writeByte($result);");
835                else if (returntype == Character.TYPE)
836                  out.print("out.writeChar($result);");
837                else if (returntype == Short.TYPE)
838                  out.print("out.writeShort($result);");
839                else if (returntype == Integer.TYPE)
840                  out.print("out.writeInt($result);");
841                else if (returntype == Long.TYPE)
842                  out.print("out.writeLong($result);");
843                else if (returntype == Float.TYPE)
844                  out.print("out.writeFloat($result);");
845                else if (returntype == Double.TYPE)
846                  out.print("out.writeDouble($result);");
847                else
848                  out.print("out.writeObject($result);");
849              }
850          ctrl.unindent();          ctrl.unindent();
851          out.print("}");          out.println("}");
852            out.print("catch (java.io.IOException e) {");
853            ctrl.indent();
854            out.print("throw new java.rmi.MarshalException(\"error marshalling return\", e);");
855          ctrl.unindent();          ctrl.unindent();
856          out.print("}");          out.println("}");
857            out.print("break;");
858    
859          ctrl.unindent();          ctrl.unindent();
860          out.println("}");          out.println("}");
861            out.println();
862          }
863    
864          out.close();      out.print("default:");
865  }      ctrl.indent();
866        out.print("throw new java.rmi.UnmarshalException(\"invalid method number\");");
867  private void compile(String name) throws Exception {      ctrl.unindent();
868          Compiler comp = Compiler.getInstance();      out.print("}");
869          if (verbose) {  
870                  System.out.println("[Compiling class " + name + "]");      ctrl.unindent();
871          }      out.print("}");
872          comp.setDestination(destination);  
873          comp.compile(name);      ctrl.unindent();
874  }      out.println("}");
875    
876  private static String getPrettyName(Class cls) {      out.close();
877          StringBuffer str = new StringBuffer();    }
878          for (int count = 0;; count++) {  
879                  if (!cls.isArray()) {    private void compile(String name) throws Exception
880                          str.append(cls.getName());    {
881                          for (; count > 0; count--) {      Compiler comp = Compiler.getInstance();
882                                  str.append("[]");      if (verbose)
883                          }        System.out.println("[Compiling class " + name + "]");
884                          return (str.toString());      comp.setDestination(destination);
885                  }      comp.compile(name);
886                  cls = cls.getComponentType();    }
887          }  
888  }    private static String getPrettyName(Class cls)
889      {
890        StringBuffer str = new StringBuffer();
891        for (int count = 0;; count++)
892          {
893            if (! cls.isArray())
894              {
895                str.append(cls.getName());
896                for (; count > 0; count--)
897                  str.append("[]");
898                return (str.toString());
899              }
900            cls = cls.getComponentType();
901          }
902      }
903    
904  /**  /**
905   * Sort exceptions so the most general go last.   * Sort exceptions so the most general go last.
906   */   */
907  private Class[] sortExceptions(Class[] except) {    private Class[] sortExceptions(Class[] except)
908          for (int i = 0; i < except.length; i++) {    {
909                  for (int j = i+1; j < except.length; j++) {      for (int i = 0; i < except.length; i++)
910                          if (except[i].isAssignableFrom(except[j])) {        {
911                                  Class tmp = except[i];          for (int j = i + 1; j < except.length; j++)
912                                  except[i] = except[j];            {
913                                  except[j] = tmp;              if (except[i].isAssignableFrom(except[j]))
914                          }                {
915                  }                  Class tmp = except[i];
916          }                  except[i] = except[j];
917          return (except);                  except[j] = tmp;
918  }                }
919              }
920          }
921        return (except);
922      }
923    
924  /**  /**
925   * Process the options until we find the first argument.   * Process the options until we find the first argument.
926   */   */
927  private void parseOptions() {    private void parseOptions()
928          for (;;) {    {
929                  if (next >= args.length || args[next].charAt(0) != '-') {      for (;;)
930                          break;        {
931                  }          if (next >= args.length || args[next].charAt(0) != '-')
932                  String arg = args[next];            break;
933                  next++;          String arg = args[next];
934            next++;
935                  // Accept `--' options if they look long enough.  
936                  if (arg.length() > 3 && arg.charAt(0) == '-'          // Accept `--' options if they look long enough.
937                      && arg.charAt(1) == '-')          if (arg.length() > 3 && arg.charAt(0) == '-' && arg.charAt(1) == '-')
938                    arg = arg.substring(1);            arg = arg.substring(1);
939    
940                  if (arg.equals("-keep")) {          if (arg.equals("-keep"))
941                          keep = true;            keep = true;
942                  }          else if (arg.equals("-keepgenerated"))
943                  else if (arg.equals("-keepgenerated")) {            keep = true;
944                          keep = true;          else if (arg.equals("-v1.1"))
945                  }            {
946                  else if (arg.equals("-v1.1")) {              need11Stubs = true;
947                          need11Stubs = true;              need12Stubs = false;
948                          need12Stubs = false;            }
949                  }          else if (arg.equals("-vcompat"))
950                  else if (arg.equals("-vcompat")) {            {
951                          need11Stubs = true;              need11Stubs = true;
952                          need12Stubs = true;              need12Stubs = true;
953                  }            }
954                  else if (arg.equals("-v1.2")) {          else if (arg.equals("-v1.2"))
955                          need11Stubs = false;            {
956                          need12Stubs = true;              need11Stubs = false;
957                  }              need12Stubs = true;
958                  else if (arg.equals("-g")) {            }
959                  }          else if (arg.equals("-g"))
960                  else if (arg.equals("-depend")) {            {
961                  }            }
962                  else if (arg.equals("-nowarn")) {          else if (arg.equals("-depend"))
963                  }            {
964                  else if (arg.equals("-verbose")) {            }
965                          verbose = true;          else if (arg.equals("-nowarn"))
966                  }            {
967                  else if (arg.equals("-nocompile")) {            }
968                          compile = false;          else if (arg.equals("-verbose"))
969                  }            verbose = true;
970                  else if (arg.equals("-classpath")) {          else if (arg.equals("-nocompile"))
971                          next++;            compile = false;
972                  }          else if (arg.equals("-classpath"))
973                  else if (arg.equals("-help")) {            next++;
974                          usage();          else if (arg.equals("-help"))
975                  }            usage();
976                  else if (arg.equals("-version")) {          else if (arg.equals("-version"))
977                          System.out.println("rmic ("            {
978                                             + System.getProperty("java.vm.name")              System.out.println("rmic (" + System.getProperty("java.vm.name")
979                                             + ") "                                 + ") " + System.getProperty("java.vm.version"));
980                                             + System.getProperty("java.vm.version"));              System.out.println();
981                          System.out.println();              System.out.println("Copyright 2002 Free Software Foundation, Inc.");
982                          System.out.println("Copyright 2002 Free Software Foundation, Inc.");              System.out.println("This is free software; see the source for copying conditions.  There is NO");
983                          System.out.println("This is free software; see the source for copying conditions.  There is NO");              System.out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
984                          System.out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");              System.exit(0);
985                          System.exit(0);            }
986                  }          else if (arg.equals("-d"))
987                  else if (arg.equals("-d")) {            {
988                          destination = args[next];              destination = args[next];
989                          next++;              next++;
990                  }            }
991                  else if (arg.charAt(1) == 'J') {          else if (arg.charAt(1) == 'J')
992                  }            {
993                  else {            }
994                          error("unrecognized option `" + arg + "'");          else
995                  }            error("unrecognized option `" + arg + "'");
996          }        }
997  }    }
998    
999  /**  /**
1000   * Looks for the java.rmi.Remote interface that that is implemented by theClazz.   * Looks for the java.rmi.Remote interface that that is implemented by theClazz.
1001   * @param theClazz the class to look in     * @param theClazz the class to look in
1002   * @return the Remote interface of theClazz or null if theClazz does not implement a Remote interface   * @return the Remote interface of theClazz or null if theClazz does not implement a Remote interface
1003   */   */
1004  private Class getRemoteInterface(Class theClazz)    private Class getRemoteInterface(Class theClazz)
1005  {    {
1006          Class[] interfaces = theClazz.getInterfaces();      Class[] interfaces = theClazz.getInterfaces();
1007          for (int i = 0; i < interfaces.length; i++)      for (int i = 0; i < interfaces.length; i++)
1008          {        {
1009                  if (java.rmi.Remote.class.isAssignableFrom(interfaces[i]))          if (java.rmi.Remote.class.isAssignableFrom(interfaces[i]))
1010                  {            return interfaces[i];
1011                          return interfaces[i];        }
1012                  }      logError("Class " + theClazz.getName()
1013          }               + " is not a remote object. It does not implement an interface that is a java.rmi.Remote-interface.");
1014          logError("Class "+ theClazz.getName()      return null;
1015                          + " is not a remote object. It does not implement an interface that is a java.rmi.Remote-interface.");    }
1016          return null;  
 }  
           
1017  /**  /**
1018   * Prints an error to System.err and increases the error count.   * Prints an error to System.err and increases the error count.
1019   * @param theError   * @param theError
1020   */   */
1021  private void logError(String theError){    private void logError(String theError)
1022          errorCount++;    {
1023          System.err.println("error:"+theError);      errorCount++;
1024  }      System.err.println("error:" + theError);
1025      }
1026  private static void error(String message) {  
1027          System.err.println("rmic: " + message);    private static void error(String message)
1028          System.err.println("Try `rmic --help' for more information.");    {
1029          System.exit(1);      System.err.println("rmic: " + message);
1030  }      System.err.println("Try `rmic --help' for more information.");
1031        System.exit(1);
1032  private static void usage() {    }
1033          System.out.println(  
1034  "Usage: rmic [OPTION]... CLASS...\n" +    private static void usage()
1035  "\n" +    {
1036  "       -keep                   Don't delete any intermediate files\n" +      System.out.println("Usage: rmic [OPTION]... CLASS...\n" + "\n"
1037  "       -keepgenerated          Same as -keep\n" +                         + "      -keep                   Don't delete any intermediate files\n"
1038  "       -v1.1                   Java 1.1 style stubs only\n" +                         + "      -keepgenerated          Same as -keep\n"
1039  "       -vcompat                Java 1.1 & Java 1.2 stubs\n" +                         + "      -v1.1                   Java 1.1 style stubs only\n"
1040  "       -v1.2                   Java 1.2 style stubs only\n" +                         + "      -vcompat                Java 1.1 & Java 1.2 stubs\n"
1041  "       -g *                    Generated debugging information\n" +                         + "      -v1.2                   Java 1.2 style stubs only\n"
1042  "       -depend *               Recompile out-of-date files\n" +                         + "      -g *                    Generated debugging information\n"
1043  "       -nowarn *               Suppress warning messages\n" +                         + "      -depend *               Recompile out-of-date files\n"
1044  "       -nocompile              Don't compile the generated files\n" +                         + "      -nowarn *               Suppress warning messages\n"
1045  "       -verbose                Output what's going on\n" +                         + "      -nocompile              Don't compile the generated files\n"
1046  "       -classpath <path> *     Use given path as classpath\n" +                         + "      -verbose                Output what's going on\n"
1047  "       -d <directory>          Specify where to place generated classes\n" +                         + "      -classpath <path> *     Use given path as classpath\n"
1048  "       -J<flag> *              Pass flag to Java\n" +                         + "      -d <directory>          Specify where to place generated classes\n"
1049  "       -help                   Print this help, then exit\n" +                         + "      -J<flag> *              Pass flag to Java\n"
1050  "       -version                Print version number, then exit\n" +                         + "      -help                   Print this help, then exit\n"
1051  "\n" +                         + "      -version                Print version number, then exit\n" + "\n"
1052  "  * Option currently ignored\n" +                         + "  * Option currently ignored\n"
1053  "Long options can be used with `--option' form as well."                         + "Long options can be used with `--option' form as well.");
1054          );      System.exit(0);
1055          System.exit(0);    }
1056  }  
1057      static class MethodRef
1058  static class MethodRef      implements Comparable
1059          implements Comparable {    {
1060        Method meth;
1061  Method meth;      String sig;
1062  String sig;      long hash;
1063  long hash;  
1064        MethodRef(Method m)
1065  MethodRef(Method m) {      {
1066          meth = m;        meth = m;
1067          // We match on the name - but what about overloading? - XXX        // We match on the name - but what about overloading? - XXX
1068          sig = m.getName();        sig = m.getName();
1069          hash = RMIHashes.getMethodHash(m);        hash = RMIHashes.getMethodHash(m);
1070  }      }
1071    
1072  public int compareTo(Object obj) {      public int compareTo(Object obj)
1073          MethodRef that = (MethodRef)obj;      {
1074          return (this.sig.compareTo(that.sig));        MethodRef that = (MethodRef) obj;
1075  }        return (this.sig.compareTo(that.sig));
1076        }
1077  }    }
   
1078  }  }

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

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