1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.sitegraph.model;
23
24 import java.io.IOException;
25
26 /***
27 */
28 public class Link implements Render, Comparable {
29 public static final int TYPE_FORM = 0;
30 public static final int TYPE_ACTION = 1;
31 public static final int TYPE_HREF = 2;
32 public static final int TYPE_RESULT = 3;
33 public static final int TYPE_REDIRECT = 4;
34
35 private SiteGraphNode from;
36 private SiteGraphNode to;
37 private int type;
38 private String label;
39
40 public Link(SiteGraphNode from, SiteGraphNode to, int type, String label) {
41 this.from = from;
42 this.to = to;
43 this.type = type;
44 this.label = label;
45 }
46
47 public void render(IndentWriter writer) throws IOException {
48 writer.write(from.getFullName() + " -> " + to.getFullName() + " [label=\"" + getRealLabel() + "\"" + getColor() + "];");
49 }
50
51 private String getRealLabel() {
52 switch (type) {
53 case TYPE_ACTION:
54 return "action" + label;
55 case TYPE_FORM:
56 return "form" + label;
57 case TYPE_HREF:
58 return "href" + label;
59 case TYPE_REDIRECT:
60 return "redirect: " + label;
61 case TYPE_RESULT:
62 return label;
63 }
64
65 return "";
66 }
67
68 private String getColor() {
69 if (type == TYPE_RESULT || type == TYPE_ACTION) {
70 return ",color=\"darkseagreen2\"";
71 } else {
72 return "";
73 }
74 }
75
76 public int compareTo(Object o) {
77 Link other = (Link) o;
78 int result = from.compareTo(other.from);
79 if (result != 0) {
80 return result;
81 }
82
83 result = to.compareTo(other.to);
84 if (result != 0) {
85 return result;
86 }
87
88 result = label.compareTo(other.label);
89 if (result != 0) {
90 return result;
91 }
92
93 return new Integer(type).compareTo(new Integer(other.type));
94 }
95 }