KickJava   Java API By Example, From Geeks To Geeks.

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


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

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