KickJava   Java API By Example, From Geeks To Geeks.

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


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.commons.chain.web.WebContext;
23 import org.apache.struts.Globals;
24 import org.apache.struts.chain.Constants;
25 import org.apache.struts.config.ActionConfig;
26 import org.apache.struts.config.ModuleConfig;
27
28
29 /**
30  * <p>Cache the <code>ActionConfig</code> instance for the
31  * action to be used for processing this request.</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 AbstractSelectAction implements Command {
38
39
40     // ------------------------------------------------------ Instance Variables
41

42
43     private String JavaDoc actionConfigKey = Constants.ACTION_CONFIG_KEY;
44     private String JavaDoc moduleConfigKey = Constants.MODULE_CONFIG_KEY;
45
46
47     // -------------------------------------------------------------- Properties
48

49
50     /**
51      * <p>Return the context attribute key under which the
52      * <code>ActionConfig</code> for the currently selected application
53      * action is stored.</p>
54      */

55     public String JavaDoc getActionConfigKey() {
56
57         return (this.actionConfigKey);
58
59     }
60
61
62     /**
63      * <p>Set the context attribute key under which the
64      * <code>ActionConfig</code> for the currently selected application
65      * action is stored.</p>
66      *
67      * @param actionConfigKey The new context attribute key
68      */

69     public void setActionConfigKey(String JavaDoc actionConfigKey) {
70
71         this.actionConfigKey = actionConfigKey;
72
73     }
74
75
76     /**
77      * <p>Return the context attribute key under which the
78      * <code>ModuleConfig</code> for the currently selected application
79      * module is stored.</p>
80      */

81     public String JavaDoc getModuleConfigKey() {
82
83         return (this.moduleConfigKey);
84
85     }
86
87
88     /**
89      * <p>Set the context attribute key under which the
90      * <code>ModuleConfig</code> for the currently selected application
91      * module is stored.</p>
92      *
93      * @param moduleConfigKey The new context attribute key
94      */

95     public void setModuleConfigKey(String JavaDoc moduleConfigKey) {
96
97         this.moduleConfigKey = moduleConfigKey;
98
99     }
100
101
102     // ---------------------------------------------------------- Public Methods
103

104
105     /**
106      * <p>Cache the <code>ActionConfig</code> instance for the
107      * action to be used for processing this request.</p>
108      *
109      * @param context The <code>Context</code> for the current request
110      *
111      * @exception IllegalArgumentException if no valid
112      * action can be identified for this request
113      *
114      * @return <code>false</code> so that processing continues
115      */

116     public boolean execute(Context context) throws Exception JavaDoc {
117
118         // Identify the matching path for this request
119
String JavaDoc path = getPath(context);
120
121         // Cache the corresponding ActonConfig instance
122
WebContext wcontext = (WebContext) context;
123         ModuleConfig moduleConfig = (ModuleConfig)
124             wcontext.get(getModuleConfigKey());
125         ActionConfig actionConfig = moduleConfig.findActionConfig(path);
126
127         if (actionConfig == null) {
128             // Locate the mapping for unknown paths (if any)
129
ActionConfig configs[] = moduleConfig.findActionConfigs();
130             for (int i = 0; i < configs.length; i++) {
131                 if (configs[i].getUnknown()) {
132                     actionConfig = configs[i];
133                     break;
134                 }
135             }
136
137         }
138
139         if (actionConfig == null) {
140             throw new IllegalArgumentException JavaDoc("No action config for '" +
141                                                path + "'");
142         }
143         wcontext.put(getActionConfigKey(), actionConfig);
144         wcontext.getRequestScope().put(Globals.MAPPING_KEY, actionConfig);
145         return (false);
146
147     }
148
149
150     // ------------------------------------------------------- Protected Methods
151

152
153     /**
154      * <p>Return the path to be used to select the <code>ActionConfig</code>
155      * for this request.</p>
156      *
157      * @param context The <code>Context</code> for this request
158      *
159      * @exception IllegalArgumentException if no valid
160      * action can be identified for this request
161      */

162     protected abstract String JavaDoc getPath(Context context);
163
164
165 }
166
Popular Tags