KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > webFlow > model > Graph


1 package com.opensymphony.webwork.webFlow.model;
2
3 import java.io.IOException JavaDoc;
4 import java.util.*;
5
6 /**
7  * User: plightbo
8  * Date: Jun 26, 2005
9  * Time: 4:58:30 PM
10  */

11 public class Graph extends SubGraph {
12     private Set links;
13     public static Map nodeMap = new TreeMap();
14
15     public Graph() {
16         super("");
17         this.links = new TreeSet();
18     }
19
20     public void addLink(Link link) {
21         links.add(link);
22     }
23
24     public void render(IndentWriter writer) throws IOException JavaDoc {
25         // write out the header
26
writer.write("digraph mygraph {", true);
27         writer.write("fontsize=10;");
28         writer.write("fontname=helvetica;");
29         writer.write("node [fontsize=10, fontname=helvetica, style=filled, shape=rectangle]");
30         writer.write("edge [fontsize=10, fontname=helvetica]");
31
32         // render all the subgraphs
33
for (Iterator iterator = subGraphs.iterator(); iterator.hasNext();) {
34             SubGraph subGraph = (SubGraph) iterator.next();
35             subGraph.render(new IndentWriter(writer));
36         }
37
38         // render all the nodes
39
for (Iterator iterator = nodes.iterator(); iterator.hasNext();) {
40             WebFlowNode webFlowNode = (WebFlowNode) iterator.next();
41             webFlowNode.render(writer);
42         }
43
44         // finally, render the links
45
for (Iterator iterator = links.iterator(); iterator.hasNext();) {
46             Link link = (Link) iterator.next();
47             link.render(writer);
48         }
49
50         // and now the footer
51
writer.write("}", true);
52     }
53
54     public WebFlowNode findNode(String JavaDoc location, WebFlowNode ref) {
55         if (location.startsWith("/")) {
56             location = location.substring(1);
57         } else {
58             // not absolute, so use the reference node
59
String JavaDoc prefix = null;
60             if (ref.getParent() != null) {
61                 prefix = ref.getParent().getPrefix();
62                 location = prefix + "_" + location;
63             }
64         }
65
66         location = location.replaceAll("[\\.\\/\\-\\$\\{\\}]", "_");
67
68         return (WebFlowNode) nodeMap.get(location);
69     }
70 }
71
Popular Tags