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 _ht = new Hashtable(); 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(""); } 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 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 v = (Vector)prop.get(); if (v != null) { Enumeration ve = v.elements(); while (ve.hasMoreElements()) { this.saveMaybeProp(ve.nextElement()); } } this._out.undent(); this._out.println("}"); } else { this.saveMaybeProp(prop.get()); } } } }