1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts.chain.commands;
19
20 import org.apache.struts.Globals;
21 import org.apache.struts.chain.contexts.ActionContext;
22 import org.apache.struts.config.ModuleConfig;
23 import org.apache.struts.util.MessageResources;
24
25 /***
26 * <p>Cache the <code>ModuleConfig</code> and <code>MessageResources</code>
27 * instances for the sub-application module to be used for processing this
28 * request.</p>
29 *
30 * @version $Rev: 421119 $ $Date: 2005-11-12 13:01:44 -0500 (Sat, 12 Nov 2005)
31 * $
32 */
33 public abstract class AbstractSelectModule extends ActionCommandBase {
34
35
36
37 /***
38 * <p>Cache the <code>ModuleConfig</code> and <code>MessageResources</code>
39 * instances for the sub-application module to be used for processing this
40 * request.</p>
41 *
42 * @param actionCtx The <code>Context</code> for the current request
43 * @return <code>false</code> so that processing continues
44 * @throws IllegalArgumentException if no valid ModuleConfig or
45 * MessageResources can be identified for
46 * this request
47 * @throws Exception if thrown by the Action class
48 */
49 public boolean execute(ActionContext actionCtx)
50 throws Exception {
51 String prefix = getPrefix(actionCtx);
52
53
54 ModuleConfig moduleConfig =
55 (ModuleConfig) actionCtx.getApplicationScope().get(Globals.MODULE_KEY
56 + prefix);
57
58 if (moduleConfig == null) {
59 throw new IllegalArgumentException("No module config for prefix '"
60 + prefix + "'");
61 }
62
63 actionCtx.setModuleConfig(moduleConfig);
64
65 String key = Globals.MESSAGES_KEY + prefix;
66 MessageResources messageResources =
67 (MessageResources) actionCtx.getApplicationScope().get(key);
68
69 if (messageResources == null) {
70 throw new IllegalArgumentException(
71 "No message resources found in application scope under " + key);
72 }
73
74 actionCtx.setMessageResources(messageResources);
75
76 return (false);
77 }
78
79
80
81 /***
82 * <p>Calculate and return the module prefix for the module to be selected
83 * for this request.</p>
84 *
85 * @param context The <code>Context</code> for this request
86 * @return Module prefix to be used with this request
87 * @throws IllegalArgumentException if no valid ModuleConfig or
88 * MessageResources can be identified for
89 * this request
90 */
91 protected abstract String getPrefix(ActionContext context);
92 }