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