KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > servlet > ActionData


1 package jodd.servlet;
2
3 import java.util.HashMap;
4
5 /**
6  * Util value object class for ActionController. It holds information for all
7  * actions defined in the configuration xml file.
8  *
9  * @see ActionController
10  */

11 final class ActionData {
12
13     /**
14      * Default constructor.
15      */

16     public ActionData() {
17     }
18
19     /**
20      * Constructor.
21      *
22      * @param path
23      * @param type
24      */

25     public ActionData(String path, String type) {
26         setPath(path);
27         setType(type);
28         setMethod(null);
29     }
30
31     /**
32      * Constructor.
33      *
34      * @param path
35      * @param type
36      */

37     public ActionData(String path, String type, String method) {
38         setPath(path);
39         setType(type);
40         setMethod(method);
41     }
42
43     // ---------------------------------------------------------------- path
44

45     private String path;
46     /**
47      * Sets the request path that triggers an ActionServlet.
48      *
49      * @param v
50      */

51     public void setPath(String v) {
52         path = v;
53     }
54     /**
55      * Get path that triggers an ActionServlet.
56      *
57      * @return
58      */

59     public String getPath() {
60         return path;
61     }
62
63     // ---------------------------------------------------------------- type
64

65     private String type;
66     /**
67      * Sets the type of the ActionServlet that will be executed. It is the name
68      * of the class that will be loaded and instanced first time when needed.
69      *
70      * @param v
71      */

72     public void setType(String v) {
73         type = v;
74     }
75     /**
76      * Returns name of the ActionServlet type.
77      *
78      * @return
79      */

80     public String getType() {
81         return type;
82     }
83
84     // ---------------------------------------------------------------- method
85

86     private String method;
87     /**
88      * Sets the ActionServlet method that will handle the action.
89      * If null, default doAction will be called.
90      *
91      * @param v method name
92      */

93     public void setMethod(String v) {
94         method = v;
95     }
96     /**
97      * Returns the name of the method on wich action is mapped.
98      *
99      * @return name od the mapped action
100      */

101     public String getMethod() {
102         return method;
103     }
104
105     // ---------------------------------------------------------------- action
106

107     private ActionServlet action = null;
108     /**
109      * Assigns specific ActionServlet object to a request.
110      *
111      * @param v ActionServlet object
112      */

113     public void setAction(ActionServlet v) {
114         action = v;
115     }
116     /**
117      * Returns assigned ActionServlet.
118      *
119      * @return assigned ActionServlet, or null if no object assigned
120      */

121     public ActionServlet getAction() {
122         return action;
123     }
124     
125     // ---------------------------------------------------------------- forwards
126

127     private HashMap forwards = new HashMap();
128     
129     /**
130      * Defines an forward. They are eather real forward eather redirects. This is
131      * just 1-1 list of names and associated paths where to forward/redirect.
132      *
133      * @param name name of the action
134      * @param path request path that will trigger ActionServlet
135      * @param redirect boolean-like string that defines if ActionServlet will forward (default)
136      * or redirect (if "true") after processing ActionServlet.
137      */

138     public void putForwardPath(String name, String path, String redirect) {
139         Boolean rdrct = Boolean.FALSE;
140         if (redirect.equalsIgnoreCase("true")) {
141             rdrct = Boolean.TRUE;
142         }
143         forwards.put(name, new Object[] {path, rdrct});
144     }
145     /**
146      * Returns forward path assigned with the given name.
147      *
148      * @param name
149      *
150      * @return assiged forward path, null if doesn't exist
151      */

152     public String getForwardPath(String name) {
153         Object[] fwds = (Object[]) forwards.get(name);
154         if (fwds == null) {
155             return null;
156         }
157         return (String)(fwds[0]);
158     }
159     /**
160      * Gets the information for a forward: will it be forwarded or redirected.
161      *
162      * @param name
163      *
164      * @return false for forward (or error), true for redirect
165      */

166     public boolean isForwardRedirect(String name) {
167         Object[] flag = (Object[]) forwards.get(name);
168         if (flag == null) {
169             return false;
170         }
171         Boolean b = (Boolean) (flag[1]);
172         return b.booleanValue();
173     }
174
175
176     // ---------------------------------------------------------------- parameters
177

178     private HashMap parameters = new HashMap();
179
180     /**
181      * Defines action parameters.
182      *
183      * @param name parameter name
184      * @param value parameter value
185      */

186     public void putParameter(String name, String value) {
187         if (name == null) {
188             return;
189         }
190         parameters.put(name, value);
191     }
192
193     /**
194      * Returns action parameter value.
195      *
196      * @param name parameer name
197      *
198      * @return action parameter value
199      */

200     public String getParameter(String name) {
201         return (String) parameters.get(name);
202     }
203
204 }
205
Popular Tags