1 |
/* ASMRMIC.java -- |
/* RMIC.java -- |
2 |
Copyright (c) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005 |
Copyright (c) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005 |
3 |
Free Software Foundation, Inc. |
Free Software Foundation, Inc. |
4 |
|
|
65 |
{ |
{ |
66 |
private String[] args; |
private String[] args; |
67 |
private int next; |
private int next; |
68 |
private Exception exception; |
private List errors = new ArrayList(); |
69 |
private boolean keep = false; |
private boolean keep = false; |
70 |
private boolean need11Stubs = true; |
private boolean need11Stubs = true; |
71 |
private boolean need12Stubs = true; |
private boolean need12Stubs = true; |
97 |
|
|
98 |
public static void main(String[] args) |
public static void main(String[] args) |
99 |
{ |
{ |
100 |
|
if (rmic(args)) |
101 |
|
System.exit(0); |
102 |
|
else |
103 |
|
System.exit(1); |
104 |
|
} |
105 |
|
|
106 |
|
/** |
107 |
|
* @return true if compilation was successful |
108 |
|
*/ |
109 |
|
public static boolean rmic(String[] args) |
110 |
|
{ |
111 |
RMIC r = new RMIC(args); |
RMIC r = new RMIC(args); |
112 |
if (r.run() == false) |
return r.run(); |
|
{ |
|
|
Exception e = r.getException(); |
|
|
if (e != null) |
|
|
e.printStackTrace(); |
|
|
else |
|
|
System.exit(1); |
|
|
} |
|
113 |
} |
} |
114 |
|
|
115 |
public boolean run() |
/** |
116 |
|
* @return true if run was successful |
117 |
|
*/ |
118 |
|
private boolean run() |
119 |
{ |
{ |
120 |
parseOptions(); |
boolean done = parseOptions(); |
121 |
|
if (done) |
122 |
|
return errorCount == 0; |
123 |
|
|
124 |
if (next >= args.length) |
if (next >= args.length) |
125 |
error("no class names found"); |
{ |
126 |
|
usage(); |
127 |
|
return false; |
128 |
|
} |
129 |
|
|
130 |
for (int i = next; i < args.length; i++) |
for (int i = next; i < args.length; i++) |
131 |
{ |
{ |
132 |
try |
try |
133 |
{ |
{ |
134 |
if (verbose) |
if (verbose) |
135 |
System.out.println("[Processing class " + args[i] + ".class]"); |
System.out.println("[Processing class " + args[i] + ".class]"); |
136 |
processClass(args[i].replace(File.separatorChar, '.')); |
processClass(args[i].replace(File.separatorChar, '.')); |
137 |
} |
} |
138 |
catch (Exception e) |
catch (IOException e) |
139 |
{ |
{ |
140 |
exception = e; |
errors.add(e); |
141 |
return (false); |
} |
142 |
} |
catch (RMICException e) |
143 |
|
{ |
144 |
|
errors.add(e); |
145 |
|
} |
146 |
} |
} |
147 |
return (true); |
if (errors.size() > 0) |
148 |
|
{ |
149 |
|
for (Iterator it = errors.iterator(); it.hasNext(); ) |
150 |
|
{ |
151 |
|
Exception ex = (Exception) it.next(); |
152 |
|
logError(ex); |
153 |
|
} |
154 |
|
} |
155 |
|
|
156 |
|
return errorCount == 0; |
157 |
} |
} |
158 |
|
|
159 |
private boolean processClass(String cls) throws Exception |
private void processClass(String cls) throws IOException, RMICException |
160 |
{ |
{ |
161 |
// reset class specific vars |
// reset class specific vars |
162 |
clazz = null; |
clazz = null; |
168 |
skelname = null; |
skelname = null; |
169 |
mRemoteInterfaces = new ArrayList(); |
mRemoteInterfaces = new ArrayList(); |
170 |
|
|
|
errorCount = 0; |
|
|
|
|
171 |
analyzeClass(cls); |
analyzeClass(cls); |
|
if (errorCount > 0) |
|
|
System.exit(1); |
|
172 |
generateStub(); |
generateStub(); |
173 |
if (need11Stubs) |
if (need11Stubs) |
174 |
generateSkel(); |
generateSkel(); |
|
return (true); |
|
175 |
} |
} |
176 |
|
|
177 |
private void analyzeClass(String cname) throws Exception |
private void analyzeClass(String cname) |
178 |
|
throws RMICException |
179 |
{ |
{ |
180 |
if (verbose) |
if (verbose) |
181 |
System.out.println("[analyze class " + cname + "]"); |
System.out.println("[analyze class " + cname + "]"); |
190 |
findRemoteMethods(); |
findRemoteMethods(); |
191 |
} |
} |
192 |
|
|
193 |
|
/** |
194 |
|
* @deprecated |
195 |
|
*/ |
196 |
public Exception getException() |
public Exception getException() |
197 |
{ |
{ |
198 |
return (exception); |
return errors.size() == 0 ? null : (Exception) errors.get(0); |
199 |
} |
} |
200 |
|
|
201 |
private void findClass() |
private void findClass() |
202 |
|
throws RMICException |
203 |
{ |
{ |
204 |
|
ClassLoader cl = (loader == null |
205 |
|
? ClassLoader.getSystemClassLoader() |
206 |
|
: loader); |
207 |
try |
try |
208 |
{ |
{ |
|
ClassLoader cl = (loader == null |
|
|
? ClassLoader.getSystemClassLoader() |
|
|
: loader); |
|
209 |
clazz = Class.forName(fullclassname, false, cl); |
clazz = Class.forName(fullclassname, false, cl); |
210 |
} |
} |
211 |
catch (ClassNotFoundException cnfe) |
catch (ClassNotFoundException cnfe) |
212 |
{ |
{ |
213 |
System.err.println(fullclassname + " not found in " + classpath); |
throw new RMICException |
214 |
throw new RuntimeException(cnfe); |
("Class " + fullclassname + " not found in classpath", cnfe); |
215 |
} |
} |
216 |
|
|
217 |
if (! Remote.class.isAssignableFrom(clazz)) |
if (! Remote.class.isAssignableFrom(clazz)) |
218 |
{ |
{ |
219 |
logError("Class " + clazz.getName() + " is not a remote object. " |
throw new RMICException |
220 |
+ "It does not implement an interface that is a " |
("Class " + clazz.getName() |
221 |
+ "java.rmi.Remote-interface."); |
+ " does not implement a remote interface."); |
|
throw new RuntimeException |
|
|
("Class " + clazz.getName() + " is not a remote object. " |
|
|
+ "It does not implement an interface that is a " |
|
|
+ "java.rmi.Remote-interface."); |
|
222 |
} |
} |
223 |
} |
} |
224 |
|
|
434 |
} |
} |
435 |
} |
} |
436 |
|
|
437 |
private void generateStub() throws IOException |
private void generateStub() |
438 |
|
throws IOException |
439 |
{ |
{ |
440 |
stubname = fullclassname + "_Stub"; |
stubname = fullclassname + "_Stub"; |
441 |
String stubclassname = classname + "_Stub"; |
String stubclassname = classname + "_Stub"; |
1618 |
|
|
1619 |
/** |
/** |
1620 |
* Process the options until we find the first argument. |
* Process the options until we find the first argument. |
1621 |
|
* |
1622 |
|
* @return true if further processing should stop |
1623 |
*/ |
*/ |
1624 |
private void parseOptions() |
private boolean parseOptions() |
1625 |
{ |
{ |
1626 |
for (;;) |
for (;;) |
1627 |
{ |
{ |
1683 |
} |
} |
1684 |
catch (java.net.MalformedURLException mue) |
catch (java.net.MalformedURLException mue) |
1685 |
{ |
{ |
1686 |
error("malformed classpath component " + path); |
logError("malformed classpath component " + path); |
1687 |
|
return true; |
1688 |
} |
} |
1689 |
} |
} |
1690 |
loader = new URLClassLoader(u); |
loader = new URLClassLoader(u); |
1691 |
} |
} |
1692 |
else if (arg.equals("-help")) |
else if (arg.equals("-help")) |
1693 |
usage(); |
{ |
1694 |
|
usage(); |
1695 |
|
return true; |
1696 |
|
} |
1697 |
else if (arg.equals("-version")) |
else if (arg.equals("-version")) |
1698 |
{ |
{ |
1699 |
System.out.println("rmic (" + System.getProperty("java.vm.name") |
System.out.println("rmic (" + System.getProperty("java.vm.name") |
1702 |
System.out.println("Copyright 2002 Free Software Foundation, Inc."); |
System.out.println("Copyright 2002 Free Software Foundation, Inc."); |
1703 |
System.out.println("This is free software; see the source for copying conditions. There is NO"); |
System.out.println("This is free software; see the source for copying conditions. There is NO"); |
1704 |
System.out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); |
System.out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); |
1705 |
System.exit(0); |
return true; |
1706 |
} |
} |
1707 |
else if (arg.equals("-d")) |
else if (arg.equals("-d")) |
1708 |
{ |
{ |
1710 |
next++; |
next++; |
1711 |
} |
} |
1712 |
else if (arg.charAt(1) == 'J') |
else if (arg.charAt(1) == 'J') |
1713 |
{ |
/* ignoring -J flags that are supposed to be passed to the |
1714 |
} |
underlying Java interpreter */ |
1715 |
else |
continue; |
1716 |
error("unrecognized option `" + arg + "'"); |
else |
1717 |
|
{ |
1718 |
|
logError("unrecognized option '" + arg + "'"); |
1719 |
|
return true; |
1720 |
|
} |
1721 |
} |
} |
1722 |
|
|
1723 |
|
return false; |
1724 |
} |
} |
1725 |
|
|
1726 |
private void findRemoteMethods() { |
private void findRemoteMethods() |
1727 |
|
throws RMICException |
1728 |
|
{ |
1729 |
List rmeths = new ArrayList(); |
List rmeths = new ArrayList(); |
1730 |
for (Class cur = clazz; cur != null; cur = cur.getSuperclass()) |
for (Class cur = clazz; cur != null; cur = cur.getSuperclass()) |
1731 |
{ |
{ |
1755 |
|
|
1756 |
if (! throwsRemote) |
if (! throwsRemote) |
1757 |
{ |
{ |
1758 |
logError("Method " + m |
throw new RMICException |
1759 |
+ " does not throw a RemoteException"); |
("Method " + m + " in interface " + remoteInterface |
1760 |
continue; |
+ " does not throw a RemoteException"); |
1761 |
} |
} |
1762 |
|
|
1763 |
rmeths.add(m); |
rmeths.add(m); |
1798 |
|
|
1799 |
/** |
/** |
1800 |
* Prints an error to System.err and increases the error count. |
* Prints an error to System.err and increases the error count. |
|
* @param theError |
|
1801 |
*/ |
*/ |
1802 |
private void logError(String theError) |
private void logError(Exception theError) |
1803 |
{ |
{ |
1804 |
errorCount++; |
logError(theError.getMessage()); |
1805 |
System.err.println("error:" + theError); |
if (verbose) |
1806 |
|
theError.printStackTrace(System.err); |
1807 |
} |
} |
1808 |
|
|
1809 |
private static void error(String message) |
/** |
1810 |
|
* Prints an error to System.err and increases the error count. |
1811 |
|
*/ |
1812 |
|
private void logError(String theError) |
1813 |
{ |
{ |
1814 |
System.err.println("rmic: " + message); |
errorCount++; |
1815 |
System.err.println("Try `rmic --help' for more information."); |
System.err.println("error: " + theError); |
|
System.exit(1); |
|
1816 |
} |
} |
1817 |
|
|
1818 |
private static void usage() |
private static void usage() |
1835 |
+ " -version Print version number, then exit\n" + "\n" |
+ " -version Print version number, then exit\n" + "\n" |
1836 |
+ " * Option currently ignored\n" |
+ " * Option currently ignored\n" |
1837 |
+ "Long options can be used with `--option' form as well."); |
+ "Long options can be used with `--option' form as well."); |
|
System.exit(0); |
|
1838 |
} |
} |
1839 |
|
|
1840 |
private static String getPrettyName(Class cls) |
private static String getPrettyName(Class cls) |