KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > chain > AbstractExecuteAction


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.struts.chain;
18
19
20 import org.apache.commons.chain.Command;
21 import org.apache.commons.chain.Context;
22 import org.apache.struts.chain.Constants;
23 import org.apache.struts.action.Action;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.config.ActionConfig;
26 import org.apache.struts.config.ForwardConfig;
27
28
29 /**
30  * <p>Invoke the appropriate <code>Action</code> for this request, and cache
31  * the returned <code>ActionForward</code>.</p>
32  *
33  * @author Craig R. McClanahan
34  * @version $Rev: 54933 $ $Date: 2004-10-16 18:04:52 +0100 (Sat, 16 Oct 2004) $
35  */

36
37 public abstract class AbstractExecuteAction implements Command {
38
39
40     // ------------------------------------------------------ Instance Variables
41

42
43     private String JavaDoc actionKey = Constants.ACTION_KEY;
44     private String JavaDoc actionConfigKey = Constants.ACTION_CONFIG_KEY;
45     private String JavaDoc actionFormKey = Constants.ACTION_FORM_KEY;
46     private String JavaDoc forwardConfigKey = Constants.FORWARD_CONFIG_KEY;
47     private String JavaDoc validKey = Constants.VALID_KEY;
48
49
50     // -------------------------------------------------------------- Properties
51

52
53     /**
54      * <p>Return the context attribute key under which the
55      * <code>Action</code> for the currently selected application
56      * action is stored.</p>
57      */

58     public String JavaDoc getActionKey() {
59
60         return (this.actionKey);
61
62     }
63
64
65     /**
66      * <p>Set the context attribute key under which the
67      * <code>Action</code> for the currently selected application
68      * action is stored.</p>
69      *
70      * @param actionKey The new context attribute key
71      */

72     public void setActionKey(String JavaDoc actionKey) {
73
74         this.actionKey = actionKey;
75
76     }
77
78
79     /**
80      * <p>Return the context attribute key under which the
81      * <code>ActionConfig</code> for the currently selected application
82      * action is stored.</p>
83      */

84     public String JavaDoc getActionConfigKey() {
85
86         return (this.actionConfigKey);
87
88     }
89
90
91     /**
92      * <p>Set the context attribute key under which the
93      * <code>ActionConfig</code> for the currently selected application
94      * action is stored.</p>
95      *
96      * @param actionConfigKey The new context attribute key
97      */

98     public void setActionConfigKey(String JavaDoc actionConfigKey) {
99
100         this.actionConfigKey = actionConfigKey;
101
102     }
103
104
105     /**
106      * <p>Return the context attribute key under which the
107      * <code>ActionForm</code> for the currently selected application
108      * action is stored.</p>
109      */

110     public String JavaDoc getActionFormKey() {
111
112         return (this.actionFormKey);
113
114     }
115
116
117     /**
118      * <p>Set the context attribute key under which the
119      * <code>ActionForm</code> for the currently selected application
120      * action is stored.</p>
121      *
122      * @param actionFormKey The new context attribute key
123      */

124     public void setActionFormKey(String JavaDoc actionFormKey) {
125
126         this.actionFormKey = actionFormKey;
127
128     }
129
130
131     /**
132      * <p>Return the context attribute key under which the
133      * <code>ForwardConfig</code> for the currently selected application
134      * action is stored.</p>
135      */

136     public String JavaDoc getForwardConfigKey() {
137
138         return (this.forwardConfigKey);
139
140     }
141
142
143     /**
144      * <p>Set the context attribute key under which the
145      * <code>ForwardConfig</code> for the currently selected application
146      * action is stored.</p>
147      *
148      * @param forwardConfigKey The new context attribute key
149      */

150     public void setForwardConfigKey(String JavaDoc forwardConfigKey) {
151
152         this.forwardConfigKey = forwardConfigKey;
153
154     }
155
156
157     /**
158      * <p>Return the context attribute key under which the
159      * validity flag for this request is stored.</p>
160      */

161     public String JavaDoc getValidKey() {
162
163         return (this.validKey);
164
165     }
166
167
168     /**
169      * <p>Set the context attribute key under which the
170      * validity flag for this request is stored.</p>
171      *
172      * @param validKey The new context attribute key
173      */

174     public void setValidKey(String JavaDoc validKey) {
175
176         this.validKey = validKey;
177
178     }
179
180
181     // ---------------------------------------------------------- Public Methods
182

183
184     /**
185      * <p>Invoke the appropriate <code>Action</code> for this request, and cache
186      * the returned <code>ActionForward</code>.</p>
187      *
188      * @param context The <code>Context</code> for the current request
189      *
190      * @exception InvalidPathException if no valid
191      * action can be identified for this request
192      *
193      * @return <code>false</code> so that processing continues
194      */

195     public boolean execute(Context context) throws Exception JavaDoc {
196
197         // Skip processing if the current request is not valid
198
Boolean JavaDoc valid = (Boolean JavaDoc) context.get(getValidKey());
199         if ((valid == null) || !valid.booleanValue()) {
200             return (false);
201         }
202
203         // Acquire the resources we will need to send to the Action
204
Action action = (Action)
205             context.get(getActionKey());
206         if (action == null) {
207             return (false);
208         }
209         ActionConfig actionConfig = (ActionConfig)
210             context.get(getActionConfigKey());
211         ActionForm actionForm = (ActionForm)
212             context.get(getActionFormKey());
213
214         // Execute the Action for this request, caching returned ActionForward
215
ForwardConfig forwardConfig =
216             execute(context, action, actionConfig, actionForm);
217         context.put(getForwardConfigKey(), forwardConfig);
218
219         return (false);
220
221     }
222
223
224     // ------------------------------------------------------- Protected Methods
225

226
227     /**
228      * <p>Execute the specified <code>Action</code>, and return the resulting
229      * <code>ForwardConfig</code>.</p>
230      *
231      * @param context The <code>Context</code> for this request
232      * @param action The <code>Action</code> to be executed
233      * @param actionConfig The <code>ActionConfig</code> defining this action
234      * @param actionForm The <code>ActionForm</code> (if any) for
235      * this action
236      *
237      * @exception Exception if thrown by the <code>Action</code>
238      */

239     protected abstract ForwardConfig execute(Context context,
240                                              Action action,
241                                              ActionConfig actionConfig,
242                                              ActionForm actionForm)
243         throws Exception JavaDoc;
244
245
246 }
247
Popular Tags