summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/Manifest.java
blob: dc888a930e0acb7f6478f7529eb4cc41fe07883f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package NET.worlds.scape;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

public class Manifest {
   private IndentStream _out;
   private Hashtable<Object, String> _ht = new Hashtable<Object, String>();
   private int _lastID = 0;

   public Manifest(IndentStream out) {
      this._out = out;
      this._out.println("MANIFEST Worlds, Inc.");
      this._out.indent();
   }

   public Manifest(String name) throws IOException {
      this(new IndentStream(new FileOutputStream(name)));
   }

   public void done() {
      this._out.undent();
      this._out.println("END MANIFEST");
      this._out.close();
      this._out = null;
      this._ht = null;
   }

   private void printID(String s) {
      this._out.print(" (#" + s + ")");
   }

   private void printRef(Object obj) {
      if (obj instanceof SuperRoot) {
         this._out.print(((SuperRoot)obj).getName());
      } else {
         this._out.print("<anonymous>");
      }

      if (this._ht.containsKey(obj)) {
         this.printID(this._ht.get(obj));
         this._out.println(" --q.v.--");
      } else {
         String newID = Integer.toString(this._lastID++);
         this._ht.put(obj, newID);
         this.printID(newID);
         this._out.println(":" + obj.getClass().getName() + " [");
         this._out.indent();
         this.saveProps((Properties)obj);
         this._out.undent();
         this._out.println("]");
      }
   }

   private void saveMaybeProp(Object obj) {
      if (obj instanceof Properties && !obj.getClass().getName().equals("NET.worlds.scape.Transform")) {
         this.printRef(obj);
      } else {
         this._out.println(obj);
      }
   }

   public void saveProps(Properties obj) {
      Enumeration<Object> pe = new EnumProperties(obj);

      while (pe.hasMoreElements()) {
         Property prop = (Property)pe.nextElement();
         this._out.print(prop.getName());
         this._out.print(" := ");
         if (prop instanceof VectorProperty) {
            this._out.println("{");
            this._out.indent();
            Vector<Object> v = (Vector<Object>)prop.get();
            if (v != null) {
               Enumeration<Object> ve = v.elements();

               while (ve.hasMoreElements()) {
                  this.saveMaybeProp(ve.nextElement());
               }
            }

            this._out.undent();
            this._out.println("}");
         } else {
            this.saveMaybeProp(prop.get());
         }
      }
   }
}