01: package jsint;
02:
03: /** An Importer that knows how to import a single class. **/
04: public class SingleImporter implements Importer {
05: String fullName;
06: Class c;
07:
08: public SingleImporter(String fullName) {
09: this .fullName = fullName;
10: reset();
11: }
12:
13: public Class classNamed(String name) {
14: /* An import may occur before the class is on the classpath,
15: so Import.forName() will return null. **/
16: if (c == null)
17: reset();
18: return (fullName.equals(name) || fullName.endsWith("." + name)) ? c
19: : null;
20: }
21:
22: public boolean equals(Object x) {
23: return this .getClass() == x.getClass()
24: && this .fullName == ((SingleImporter) x).fullName;
25: }
26:
27: public int hashCode() {
28: return this .fullName.hashCode();
29: }
30:
31: public String toString() {
32: return "(import " + fullName + ")";
33: }
34:
35: public void reset() {
36: this.c = Import.forName(fullName);
37: }
38: }
|