KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > actionflow > ActionFlowMetaData


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;
8
9
10 import java.util.HashMap JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import javax.servlet.ServletRequest JavaDoc;
14
15 import com.inversoft.verge.mvc.MVCException;
16 import com.inversoft.verge.mvc.config.BaseFormConfig;
17 import com.inversoft.verge.mvc.config.BaseFormConfigMetaData;
18 import com.inversoft.verge.mvc.controller.actionflow.config.ActionFlowConfigRegistry;
19 import com.inversoft.verge.mvc.controller.actionflow.config.Namespace;
20
21
22 /**
23  * <p>
24  * This class is used to store the meta data used in calling
25  * the ActionFlow system.
26  * </p>
27  *
28  * @author Brian Pontarelli
29  * @since 2.0
30  * @version 2.0
31  */

32 public class ActionFlowMetaData extends BaseFormConfigMetaData {
33
34     private String JavaDoc entry;
35     private String JavaDoc action;
36     private String JavaDoc namespace;
37     private boolean modelEnabled = true;
38     private boolean validationEnabled = true;
39
40
41     /**
42      * Construsts a new empty <code>ActionFlowMetaData</code>.
43      */

44     ActionFlowMetaData() {
45     }
46
47     /**
48      * Constructs an <code>ActionFlowMetaData</code> from the information given.
49      *
50      * @param namespace The namespace
51      * @param form (Optional) The form
52      */

53     public ActionFlowMetaData(String JavaDoc namespace, String JavaDoc form) {
54         this(namespace, form, null, null, null);
55     }
56
57     /**
58      * Constructs an <code>ActionFlowMetaData</code> from the information given.
59      *
60      * @param namespace The namespace
61      * @param form (Optional) The form
62      * @param entry (Optional) The entry node
63      * @param action (Optional) The action
64      * @param extraParams The extraParams map
65      */

66     public ActionFlowMetaData(String JavaDoc namespace, String JavaDoc form, String JavaDoc entry,
67             String JavaDoc action, Map JavaDoc extraParams) {
68         super(form);
69         assert (namespace != null) : "namespace parameter missing";
70
71         this.entry = entry;
72         this.action = action;
73         this.namespace = namespace;
74
75         if (extraParams != null) {
76             String JavaDoc meStr =
77                 (String JavaDoc) extraParams.get(ActionFlowURLTools.MODEL_ENABLED_PARAM);
78             if (meStr != null) {
79                 this.modelEnabled = Boolean.valueOf(meStr).booleanValue();
80             }
81
82             String JavaDoc veStr =
83                 (String JavaDoc) extraParams.get(ActionFlowURLTools.VALIDATION_ENABLED_PARAM);
84             if (veStr != null) {
85                 this.validationEnabled = Boolean.valueOf(veStr).booleanValue();
86             }
87         }
88     }
89
90
91     /**
92      * Returns the name of the entry node
93      *
94      * @return The entry node name
95      */

96     public String JavaDoc getEntry() {
97         return entry;
98     }
99
100     /**
101      * Populates the tag's entry attribute
102      *
103      * @param entry The value of the tag's entry attribute
104      */

105     public void setEntry(String JavaDoc entry) {
106         this.entry = entry;
107     }
108
109     /**
110      * Returns the name of the action
111      *
112      * @return The action
113      */

114     public String JavaDoc getAction() {
115         return action;
116     }
117
118     /**
119      * Sets the name of the action
120      *
121      * @param action The action
122      */

123     public void setAction(String JavaDoc action) {
124         this.action = action;
125     }
126
127     /**
128      * Returns the name of the namespace to execute in
129      *
130      * @return The namespace
131      */

132     public String JavaDoc getNamespace() {
133         return namespace;
134     }
135
136     /**
137      * Populates the tag's namespace attribute
138      *
139      * @param namespace The value of the tag's namespace attribute
140      */

141     public void setNamespace(String JavaDoc namespace) {
142         this.namespace = namespace;
143     }
144
145     /**
146      * Sets the name of the form
147      *
148      * @param form The form
149      */

150     public void setForm(String JavaDoc form) {
151         this.form = form;
152     }
153
154     /**
155      * Returns whether or not the model is enabled for this request.
156      *
157      * @return True if the model is enabled, false otherwise
158      */

159     public boolean isModelEnabled() {
160         return modelEnabled;
161     }
162
163     /**
164      * Sets whether or not the model is enabled for this request.
165      *
166      * @param modelEnabled True if the model is enabled, false otherwise
167      */

168     public void setModelEnabled(boolean modelEnabled) {
169         this.modelEnabled = modelEnabled;
170     }
171
172     /**
173      * Returns whether or not validation of the model is enabled for this request.
174      *
175      * @return True if validation is enabled, false otherwise
176      */

177     public boolean isValidationEnabled() {
178         return validationEnabled;
179     }
180
181     /**
182      * Sets whether or not validation of the model is enabled for this request.
183      *
184      * @param validationEnabled True if validation is enabled, false otherwise
185      */

186     public void setValidationEnabled(boolean validationEnabled) {
187         this.validationEnabled = validationEnabled;
188     }
189
190     /**
191      * Using the information in this meta data, this method constructs a Map that
192      * can be used when generating the view links.
193      *
194      * @return A Map containing the entry, action and namespace
195      */

196     public Map JavaDoc getExtraParams() {
197         Map JavaDoc map = new HashMap JavaDoc();
198
199         if (!modelEnabled) {
200             map.put(ActionFlowURLTools.MODEL_ENABLED_PARAM,
201                 new Boolean JavaDoc(modelEnabled));
202         }
203
204         if (!validationEnabled) {
205             map.put(ActionFlowURLTools.VALIDATION_ENABLED_PARAM,
206                 new Boolean JavaDoc(validationEnabled));
207         }
208
209         return map;
210     }
211
212     /**
213      * Locates the {@link BaseFormConfig} object.
214      *
215      * @param request The ServletRequest to use if needed
216      * @return The FormConfig object and never null
217      * @throws MVCException If the FormConfig object could not be found
218      */

219     public BaseFormConfig findFormConfig(ServletRequest JavaDoc request)
220     throws MVCException {
221
222         Namespace namespace =
223             ActionFlowConfigRegistry.getInstance(request).lookup(this.namespace);
224         if (namespace == null) {
225             throw new MVCException("Invalid namespace named: " + this.namespace +
226                 " for form named: " + getForm());
227         }
228
229         BaseFormConfig form = namespace.lookupForm(getForm());
230         if (form == null) {
231             throw new MVCException("Form named: " + getForm() + " not found");
232         }
233
234         return form;
235     }
236 }
Popular Tags