package com.nailabs.abac.test; import java.util.*; import java.io.*; import com.nailabs.abac.trust.*; import com.nailabs.abac.process.*; public class TextGraphObserver implements Observer { HashMap nodeMap = new HashMap(10); PrintStream out; int count = 0; public TextGraphObserver(String name) { try { out = new PrintStream(new FileOutputStream(name + ".xml")); } catch(Exception ex) { ex.printStackTrace(out); } out.println("\n"); } public void update(TTGNode node) { if(!nodeMap.containsKey(node.getGoal().toString())) { nodeMap.put(node.getGoal().toString(), node); node.addObserver(this); //out.print(""); } } public void update(Observable o, Object arg) { if(o instanceof TTG) { if(arg instanceof TTGNode) { update((TTGNode)arg); out.println(""); return; } out.print(""); } else { if(o instanceof TTGNode && !(arg instanceof SatisfactionState)) { return; // skip over all but satisfaction states } out.print(""); if(o instanceof XMLizable) { out.print(((XMLizable)o).toXML()); } else { out.print(o); } } if(arg instanceof XMLizable) { out.print(((XMLizable)arg).toXML()); } else { out.print(arg); } out.println("\n"); out.flush(); } public void close() { out.print("\n"); out.println(""); out.flush(); out.close(); } }