01: package gnu.kawa.lispexpr;
02:
03: import gnu.mapping.*;
04: import java.io.*;
05: import gnu.bytecode.ClassType;
06: import gnu.kawa.functions.GetNamedPart;
07:
08: public class ClassNamespace extends Namespace implements Externalizable {
09: ClassType ctype;
10:
11: public ClassType getClassType() {
12: return ctype;
13: }
14:
15: public static ClassNamespace getInstance(String name,
16: ClassType ctype) {
17: synchronized (nsTable) {
18: Object old = nsTable.get(name);
19: if (old instanceof ClassNamespace)
20: return (ClassNamespace) old;
21: ClassNamespace ns = new ClassNamespace(ctype);
22: nsTable.put(name, ns);
23: return ns;
24: }
25: }
26:
27: public ClassNamespace() {
28: }
29:
30: public ClassNamespace(ClassType ctype) {
31: this .setName("class:" + ctype.getName());
32: this .ctype = ctype;
33: }
34:
35: public Object get(String name) {
36: try {
37: return GetNamedPart.getTypePart(ctype, name);
38: } catch (Throwable ex) {
39: throw WrappedException.wrapIfNeeded(ex);
40: }
41: }
42:
43: public void writeExternal(ObjectOutput out) throws IOException {
44: out.writeObject(ctype);
45: }
46:
47: public void readExternal(ObjectInput in) throws IOException,
48: ClassNotFoundException {
49: ctype = (ClassType) in.readObject();
50: setName("class:" + ctype.getName());
51: }
52:
53: public Object readResolve() throws ObjectStreamException {
54: String name = getName();
55: if (name != null) {
56: Namespace ns = (Namespace) nsTable.get(name);
57: if (ns instanceof ClassNamespace)
58: return ns;
59: nsTable.put(name, this);
60: }
61: return this;
62: }
63: }
|