01: /*
02: * @(#)Import.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution of
07: * this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package pnuts.lang;
10:
11: import java.io.IOException;
12: import java.io.ObjectInputStream;
13: import java.io.Serializable;
14: import java.util.Hashtable;
15:
16: class Import implements Serializable {
17:
18: static final long serialVersionUID = 5497516072354034892L;
19:
20: /**
21: * @serial
22: */
23: private String name;
24:
25: transient private Hashtable table;
26:
27: public Import(String name) {
28: this .name = name;
29: this .table = new Hashtable(64);
30: }
31:
32: public String getName() {
33: return name;
34: }
35:
36: public Class get(String className, Context context) {
37: Class c = (Class) table.get(className);
38: if (c != null) {
39: return c;
40: }
41: String fullName = className;
42: try {
43: Class clazz = null;
44: if (name.length() > 0) {
45: fullName = name + "." + className;
46: }
47:
48: clazz = Pnuts.loadClass(fullName, context);
49: if (clazz != null) {
50: table.put(className, clazz);
51: }
52: return clazz;
53: } catch (ClassNotFoundException e) {
54: // if (Pnuts.debug()){
55: // System.out.println(fullName + " class not found");
56: // }
57: }
58: return null;
59: }
60:
61: void reset() {
62: table = new Hashtable(64);
63: }
64:
65: private void readObject(ObjectInputStream s) throws IOException,
66: ClassNotFoundException {
67: s.defaultReadObject();
68: table = new Hashtable(64);
69: }
70:
71: public String toString() {
72: return "import " + name;
73: }
74: }
|