KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > lispexpr > ClassNamespace


1 package gnu.kawa.lispexpr;
2 import gnu.mapping.*;
3 import java.io.*;
4 import gnu.bytecode.ClassType;
5 import gnu.kawa.functions.GetNamedPart;
6
7 public class ClassNamespace extends Namespace implements Externalizable
8 {
9   ClassType ctype;
10
11   public ClassType getClassType ()
12   {
13     return ctype;
14   }
15
16   public static ClassNamespace getInstance (String JavaDoc name, ClassType ctype)
17   {
18     synchronized (nsTable)
19       {
20     Object JavaDoc old = nsTable.get(name);
21     if (old instanceof ClassNamespace)
22       return (ClassNamespace) old;
23     ClassNamespace ns = new ClassNamespace(ctype);
24     nsTable.put(name, ns);
25     return ns;
26       }
27   }
28
29   public ClassNamespace ()
30   {
31   }
32
33   public ClassNamespace (ClassType ctype)
34   {
35     this.setName("class:"+ctype.getName());
36     this.ctype = ctype;
37   }
38
39   public Object JavaDoc get (String JavaDoc name)
40   {
41     try
42       {
43         return GetNamedPart.getTypePart(ctype, name);
44       }
45     catch (Throwable JavaDoc ex)
46       {
47         throw WrappedException.wrapIfNeeded(ex);
48       }
49   }
50
51   public void writeExternal(ObjectOutput out) throws IOException
52   {
53     out.writeObject(ctype);
54   }
55
56   public void readExternal(ObjectInput in)
57     throws IOException, ClassNotFoundException JavaDoc
58   {
59     ctype = (ClassType) in.readObject();
60     setName("class:"+ctype.getName());
61   }
62
63   public Object JavaDoc readResolve() throws ObjectStreamException
64   {
65     String JavaDoc name = getName();
66     if (name != null)
67       {
68     Namespace ns = (Namespace) nsTable.get(name);
69     if (ns instanceof ClassNamespace)
70       return ns;
71     nsTable.put(name, this);
72       }
73     return this;
74   }
75 }
76
Popular Tags