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