KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > actionflow > config > ActionLink


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.controller.actionflow.config;
8
9
10 import com.inversoft.util.StringTools;
11
12
13 /**
14  * This class describes a link between two Nodes that is
15  * the result of an action. Actions are simple strings and
16  * links are a bridging between two nodes based on that
17  * action.
18  *
19  * @author Brian Pontarelli
20  * @since 2.0
21  * @version 2.0
22  */

23 public class ActionLink extends BaseLink {
24
25     private String JavaDoc action;
26
27
28     /**
29      * Constructs a new ActionLink with the given action name, origin Node
30      * and destination Node.
31      */

32     public ActionLink(String JavaDoc action, Node origin, Node destination) {
33
34         super(origin, destination);
35
36         if (StringTools.isEmpty(action)) {
37             throw new IllegalArgumentException JavaDoc("The action is invalid");
38         }
39
40         this.action = action;
41     }
42
43
44     /**
45      * Gets the action of this link
46      *
47      * @return Returns the action of this link
48      */

49     public String JavaDoc getAction() {
50         return action;
51     }
52     
53     /**
54      * Returns the value of the link, which is the action
55      *
56      * @return The value of the link (action)
57      */

58     public String JavaDoc getValue() {
59         return action;
60     }
61
62     /**
63      * Returns whether this Link accepts the given action. This returns true if
64      * the given action is equal to the action of this Link using the equals
65      * method of the String class.
66      *
67      * @param action The action to check for acceptance
68      * @return True if the given action equals the action of this Link
69      */

70     public boolean acceptAction(Object JavaDoc action) {
71         assert (action instanceof String JavaDoc) : "action must be a String";
72         assert (!StringTools.isEmpty((String JavaDoc) action)) : "action can not be null or empty";
73
74         return this.action.equals(action);
75     }
76     
77     /**
78      * Returns a String representation of this link suitable for debugging
79      */

80     public String JavaDoc toString() {
81         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
82         buf.append(getOrigin().getName()).append(" --(").append(action);
83         buf.append(")--> ").append(getDestination().getName());
84         return buf.toString();
85     }
86 }
87
Popular Tags