KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > form > config > ActionConfig


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.form.config;
8
9
10 import java.lang.reflect.Method JavaDoc;
11
12 import com.inversoft.util.ReflectionTools;
13 import com.inversoft.verge.mvc.config.BaseConfig;
14 import com.inversoft.verge.mvc.controller.WebBeanHandle;
15
16
17 /**
18  * This class stores an Action configuration
19  *
20  * @author Brian Pontarelli
21  * @since 1.0
22  * @version 2.0
23  */

24 public class ActionConfig extends BaseConfig {
25
26     private WebBeanHandle handle;
27     private String JavaDoc handleRID;
28     private boolean repository;
29     private boolean modelEnabled = true;
30     private boolean validationEnabled = true;
31     private boolean longTxnEnabled = false;
32     private String JavaDoc longTxnStartURL;
33     private String JavaDoc longTxnEndURL;
34     private String JavaDoc longTxnCategory;
35     private Method JavaDoc preHandle;
36     private Method JavaDoc postHandle;
37
38
39     /**
40      * The Generic constructor that sets up the action configuration given the
41      * attributes.
42      */

43     private ActionConfig(String JavaDoc name, boolean modelEnabled,
44             boolean validationEnabled, boolean longTxnEnabled,
45             String JavaDoc longTxnStartURL, String JavaDoc longTxnEndURL, String JavaDoc longTxnCategory) {
46         super(name);
47
48         this.modelEnabled = modelEnabled;
49         this.validationEnabled = validationEnabled;
50         this.longTxnEnabled = longTxnEnabled;
51         this.longTxnStartURL = longTxnStartURL;
52         this.longTxnEndURL = longTxnEndURL;
53         this.longTxnCategory = longTxnCategory;
54     }
55
56     /**
57      * Constructs a new action configuration object with the given name, bean and
58      * handle object
59      */

60     public ActionConfig(String JavaDoc name, WebBeanHandle handle, boolean modelEnabled,
61             boolean validationEnabled, boolean longTxnEnabled,
62             String JavaDoc longTxnStartURL, String JavaDoc longTxnEndURL, String JavaDoc longTxnCategory) {
63         this(name, modelEnabled, validationEnabled, longTxnEnabled,
64             longTxnStartURL, longTxnEndURL, longTxnCategory);
65
66         assert (handle != null) : "handle == null";
67         this.handle = handle;
68         setupMethods();
69     }
70
71     /**
72      * Constructs a new action configuration object with the given name and NO
73      * handle object. The handle MUST be setup before use. The handleRID given
74      * can be used when constructing the handle later
75      *
76      * @param name The name of the action
77      * @param handleRID The repository id of the handle bean
78      */

79     public ActionConfig(String JavaDoc name, String JavaDoc handleRID, boolean modelEnabled,
80             boolean validationEnabled, boolean longTxnEnabled,
81             String JavaDoc longTxnStartURL, String JavaDoc longTxnEndURL, String JavaDoc longTxnCategory) {
82         this(name, modelEnabled, validationEnabled, longTxnEnabled,
83             longTxnStartURL, longTxnEndURL, longTxnCategory);
84         this.handleRID = handleRID;
85         repository = true;
86     }
87
88
89     /**
90      * Sets up the pre and post handle methods
91      */

92     private void setupMethods() {
93         // Fetch the pre and post methods
94
Class JavaDoc klass = handle.getWebBean().getBeanClass();
95         Class JavaDoc[] params = handle.getHandleParams();
96         preHandle = ReflectionTools.findMethod(klass, "preHandle",
97             params, 0);
98
99         Class JavaDoc[] postParams = params;
100         if (params != null && params.length > 0) {
101             postParams = new Class JavaDoc[params.length + 1];
102             System.arraycopy(params, 0, postParams, 0, params.length);
103             postParams[params.length] = Object JavaDoc.class;
104         }
105
106         postHandle = ReflectionTools.findMethod(klass, "postHandle",
107             postParams, 0);
108     }
109
110
111     /**
112      * Returns the handleRID value
113      *
114      * @return The handle reposiory ID
115      */

116     public String JavaDoc getHandleRID() {
117         return handleRID;
118     }
119
120     /**
121      * Returns whether or not this Action is a repository item
122      *
123      * @return True if this action is a repository item, false otherwise
124      */

125     public boolean isRepository() {
126         return repository;
127     }
128
129     /**
130      * Returns the handle object for this action configuration
131      *
132      * @return The WebBeanHandle of this action
133      */

134     public WebBeanHandle getHandle() {
135         return handle;
136     }
137
138     /**
139      * Sets the handle object for this action configuration
140      *
141      * @param handle The WebBeanHandle of this action
142      */

143     void setHandle(WebBeanHandle handle) {
144         assert (handle != null) : "handle == null";
145         this.handle = handle;
146         setupMethods();
147     }
148
149
150     /**
151      * Returns whether or not the model is enabled for this action. The default
152      * is true.
153      *
154      * @return True if the model is enabled, false otherwise
155      */

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

165     void setModelEnabled(boolean modelEnabled) {
166         this.modelEnabled = modelEnabled;
167     }
168
169     /**
170      * Returns whether or not validation of the model is enabled for this action.
171      * The default is true.
172      *
173      * @return True if validation of the model is enabled, false otherwise
174      */

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

185     void setValidationEnabled(boolean validationEnabled) {
186         this.validationEnabled = validationEnabled;
187     }
188
189     /**
190      * Returns whether or not this action is a long transaction and the built in
191      * support for long transaction is enabled or not.
192      *
193      * @return True if long transaction support is enabled, false otherwise
194      */

195     public boolean isLongTxnEnabled() {
196         return longTxnEnabled;
197     }
198
199     /**
200      * Sets whether or not long transaction support is enabled for this action.
201      *
202      * @param longTxnEnabled True if long transaction support is enabled, false
203      * otherwise
204      */

205     void setLongTxnEnabled(boolean longTxnEnabled) {
206         this.longTxnEnabled = longTxnEnabled;
207     }
208
209     /**
210      * Returns the preHandle method for the action handler for this action.
211      *
212      * @return The preHandle method
213      */

214     public Method JavaDoc getPreHandleMethod() {
215         return preHandle;
216     }
217
218     /**
219      * Returns the postHandle method for the action handler for this action.
220      *
221      * @return The postHandle method
222      */

223     public Method JavaDoc getPostHandleMethod() {
224         return postHandle;
225     }
226
227     /**
228      * Returns the URL that will be used to start the long transaction
229      *
230      * @return The URL that will start the long transaction
231      */

232     public String JavaDoc getLongTxnStartURL() {
233         return longTxnStartURL;
234     }
235
236     /**
237      * Sets the URL that will be used to start the long transaction
238      *
239      * @param longTxnStartURL The URL that will start the long transaction
240      */

241     void setLongTxnStartURL(String JavaDoc longTxnStartURL) {
242         this.longTxnStartURL = longTxnStartURL;
243     }
244
245
246     /**
247      * Returns the URL that will be used to end the long transaction
248      *
249      * @return The URL that will end the long transaction
250      */

251     public String JavaDoc getLongTxnEndURL() {
252         return longTxnEndURL;
253     }
254
255     /**
256      * Sets the URL that will be used to end the long transaction
257      *
258      * @param longTxnEndURL The URL that will end the long transaction
259      */

260     void setLongTxnEndURL(String JavaDoc longTxnEndURL) {
261         this.longTxnEndURL = longTxnEndURL;
262     }
263
264     /**
265      * Returns the category to use when generating the meta-refresh in the end URL
266      * JSP.
267      *
268      * @return The category to use
269      */

270     public String JavaDoc getLongTxnCategory() {
271         return longTxnCategory;
272     }
273
274     /**
275      * Sets the category to use when generating the meta-refresh in the end URL
276      * JSP.
277      *
278      * @param longTxnCategory The category to user
279      */

280     void setLongTxnCategory(String JavaDoc longTxnCategory) {
281         this.longTxnCategory = longTxnCategory;
282     }
283 }
Popular Tags