1 package com.opensymphony.webwork.webFlow.model; 2 3 import java.io.IOException ; 4 import java.util.ArrayList ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 8 13 public class SubGraph implements Render { 14 protected String name; 15 protected SubGraph parent; 16 protected List subGraphs; 17 protected List nodes; 18 19 public SubGraph(String name) { 20 this.name = name; 21 this.subGraphs = new ArrayList (); 22 this.nodes = new ArrayList (); 23 } 24 25 public String getName() { 26 return name; 27 } 28 29 public void addSubGraph(SubGraph subGraph) { 30 subGraph.setParent(this); 31 subGraphs.add(subGraph); 32 } 33 34 public void setParent(SubGraph parent) { 35 this.parent = parent; 36 } 37 38 public void addNode(WebFlowNode node) { 39 node.setParent(this); 40 Graph.nodeMap.put(node.getFullName(), node); 41 nodes.add(node); 42 } 43 44 public void render(IndentWriter writer) throws IOException { 45 writer.write("subgraph cluster_" + getPrefix() + " {", true); 47 writer.write("color=grey;"); 48 writer.write("fontcolor=grey;"); 49 writer.write("label=\"" + name + "\";"); 50 51 for (Iterator iterator = subGraphs.iterator(); iterator.hasNext();) { 53 SubGraph subGraph = (SubGraph) iterator.next(); 54 subGraph.render(new IndentWriter(writer)); 55 } 56 57 for (Iterator iterator = nodes.iterator(); iterator.hasNext();) { 59 WebFlowNode webFlowNode = (WebFlowNode) iterator.next(); 60 webFlowNode.render(writer); 61 } 62 63 writer.write("}", true); 65 } 66 67 public String getPrefix() { 68 if (parent == null) { 69 return name; 70 } else { 71 String prefix = parent.getPrefix(); 72 if (prefix.equals("")) { 73 return name; 74 } else { 75 return prefix + "_" + name; 76 } 77 } 78 } 79 80 public SubGraph create(String namespace) { 81 if (namespace.equals("")) { 82 return this; 83 } 84 85 String [] parts = namespace.split("\\/"); 86 SubGraph last = this; 87 for (int i = 0; i < parts.length; i++) { 88 String part = parts[i]; 89 if (part.equals("")) { 90 continue; 91 } 92 93 SubGraph subGraph = findSubGraph(part); 94 if (subGraph == null) { 95 subGraph = new SubGraph(part); 96 last.addSubGraph(subGraph); 97 } 98 99 last = subGraph; 100 } 101 102 return last; 103 } 104 105 private SubGraph findSubGraph(String name) { 106 for (Iterator iterator = subGraphs.iterator(); iterator.hasNext();) { 107 SubGraph subGraph = (SubGraph) iterator.next(); 108 if (subGraph.getName().equals(name)) { 109 return subGraph; 110 } 111 } 112 113 return null; 114 } 115 } 116 | Popular Tags |