KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > util > TypeInputStream


1 package polyglot.util;
2
3 import polyglot.main.Report;
4 import polyglot.types.*;
5
6 import java.util.*;
7 import java.io.*;
8
9 /** Input stream for reading type objects. */
10 public class TypeInputStream extends ObjectInputStream
11 {
12   protected TypeSystem ts;
13   protected Map cache;
14
15   public TypeInputStream( InputStream in, TypeSystem ts)
16     throws IOException
17   {
18     super( in);
19     enableResolveObject(true);
20     this.ts = ts;
21     this.cache = new HashMap();
22   }
23
24   public TypeSystem getTypeSystem()
25   {
26     return ts;
27   }
28
29   protected Object JavaDoc resolveObject(Object JavaDoc o) {
30     String JavaDoc s = "";
31     if (Report.should_report(Report.serialize, 2)) {
32       try {
33         s = o.toString();
34       } catch (NullPointerException JavaDoc e) {
35         s = "<NullPointerException thrown>";
36       }
37     }
38     if (o instanceof PlaceHolder) {
39       Object JavaDoc k = new IdentityKey(o);
40       TypeObject t = (TypeObject) cache.get(k);
41       if (t == null) {
42         t = ((PlaceHolder) o).resolve(ts);
43         cache.put(k, t);
44       }
45       if (Report.should_report(Report.serialize, 2)) {
46         Report.report(2, "- Resolving " + s + " : " + o.getClass()
47           + " to " + t + " : " + t.getClass());
48       }
49       return t;
50     }
51     else if (o instanceof Enum JavaDoc) {
52       if (Report.should_report(Report.serialize, 2)) {
53         Report.report(2, "- Interning " + s + " : " + o.getClass());
54       }
55       return ((Enum JavaDoc) o).intern();
56     }
57     else {
58       if (Report.should_report(Report.serialize, 2)) {
59         Report.report(2, "- " + s + " : " + o.getClass());
60       }
61       return o;
62     }
63   }
64 }
65
Popular Tags