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.chain.contexts.ActionContext;
24 import org.apache.struts.config.ActionConfig;
25 import org.apache.struts.config.ModuleConfig;
26
27 /**
28 * <p>Cache the <code>ActionConfig</code> instance for the action to be used
29 * for processing this request.</p>
30 *
31 * @version $Rev: 471754 $ $Date: 2005-11-05 21:44:59 -0500 (Sat, 05 Nov 2005)
32 * $
33 */
34 public abstract class AbstractSelectAction extends ActionCommandBase {
35
36
37 /**
38 * <p>Cache the <code>ActionConfig</code> instance for the action to be
39 * used for processing this request.</p>
40 *
41 * @param actionCtx The <code>Context</code> for the current request
42 * @return <code>false</code> so that processing continues
43 * @throws InvalidPathException if no valid action can be identified for
44 * this request
45 * @throws Exception if thrown by the Action class
46 */
47 public boolean execute(ActionContext actionCtx)
48 throws Exception {
49
50 String path = getPath(actionCtx);
51
52
53 ModuleConfig moduleConfig = actionCtx.getModuleConfig();
54 ActionConfig actionConfig = moduleConfig.findActionConfig(path);
55
56 if (actionConfig == null) {
57
58
59 ActionConfig[] configs = moduleConfig.findActionConfigs();
60
61 for (int i = 0; i < configs.length; i++) {
62 if (configs[i].getUnknown()) {
63 actionConfig = configs[i];
64
65 break;
66 }
67 }
68 }
69
70 if (actionConfig == null) {
71 throw new InvalidPathException("No action config found for the specified url.",
72 path);
73 }
74
75 actionCtx.setActionConfig(actionConfig);
76
77 return (false);
78 }
79
80
81
82 /**
83 * <p>Return the path to be used to select the <code>ActionConfig</code>
84 * for this request.</p>
85 *
86 * @param context The <code>Context</code> for this request
87 * @return Path to be used to select the ActionConfig
88 */
89 protected abstract String getPath(ActionContext context);
90 }