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