KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > form > FormMVCMetaData


1 /*
2  * Copyright (c) 2003-2004, Inversoft, All Rights Reserved
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.form;
8
9
10 import javax.servlet.ServletRequest JavaDoc;
11
12 import com.inversoft.verge.mvc.MVCException;
13 import com.inversoft.verge.mvc.config.BaseFormConfig;
14 import com.inversoft.verge.mvc.config.BaseFormConfigMetaData;
15 import com.inversoft.verge.mvc.controller.form.config.FormMVCConfigRegistry;
16
17
18 /**
19  * <p>
20  * This class stores the information about the current request
21  * for the Form-Based MVC.
22  * </p>
23  *
24  * @author Brian Pontarelli
25  */

26 public class FormMVCMetaData extends BaseFormConfigMetaData {
27
28     private String JavaDoc action;
29
30     /**
31      * Default visible empty constructor.
32      */

33     FormMVCMetaData() {
34         // No-op
35
}
36
37     /**
38      * Constructs a new <code>FormMVCMetaData</code> with the given data.
39      *
40      * @param form The name of the form
41      * @param action The action
42      */

43     public FormMVCMetaData(String JavaDoc form, String JavaDoc action) {
44         super(form);
45         this.action = action;
46     }
47
48
49     /**
50      * Sets the form.
51      *
52      * @param form The name of the form
53      */

54     public void setForm(String JavaDoc form) {
55         this.form = form;
56     }
57
58     /**
59      * Retrieves the action.
60      *
61      * @return The action
62      */

63     public String JavaDoc getAction() {
64         return action;
65     }
66
67     /**
68      * Sets the action.
69      *
70      * @param action The action
71      */

72     public void setAction(String JavaDoc action) {
73         this.action = action;
74     }
75
76     /**
77      * Looks up the FormConfig from the FormMVCConfigRegistry. This method takes
78      * the SerlvetRequest object but this is optional. However, we highly suggest
79      * that you pass this object in in order to maintain request consistency. If
80      * you do not pass the request in, subsequent calls to this method could
81      * return different FormConfig instances, if the configuration is reloaded.
82      *
83      * @param request (Optional) The ServletRequest
84      * @throws MVCException If the form could not be found. This could be caused
85      * by the form not being specified in the request or the form not
86      * being defined in the configuration file.
87      */

88     public BaseFormConfig findFormConfig(ServletRequest JavaDoc request)
89     throws MVCException {
90         String JavaDoc formName = getForm();
91         if (formName == null) {
92             throw new MVCException("Form name not specified");
93         }
94
95         BaseFormConfig config =
96             FormMVCConfigRegistry.getInstance(request).lookupForm(formName);
97         if (config == null) {
98             throw new MVCException("Invalid form name: " + formName);
99         }
100
101         return config;
102     }
103 }
Popular Tags