1 /*
2 * $Id$
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
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$ $Date: 2005-11-05 21:44:59 -0500 (Sat, 05 Nov 2005)
32 * $
33 */
34 public abstract class AbstractSelectAction extends ActionCommandBase {
35 // ---------------------------------------------------------- Public Methods
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 @Override
48 protected boolean execute_(ActionContext actionCtx)
49 throws Exception {
50 // Identify the matching path for this request
51 String path = getPath(actionCtx);
52
53 // Cache the corresponding ActonConfig instance
54 ModuleConfig moduleConfig = actionCtx.getModuleConfig();
55 ActionConfig actionConfig = moduleConfig.findActionConfig(path);
56
57 if (actionConfig == null) {
58 // NOTE Shouldn't this be the responsibility of ModuleConfig?
59 // Locate the mapping for unknown paths (if any)
60 ActionConfig[] configs = moduleConfig.findActionConfigs();
61
62 for (int i = 0; i < configs.length; i++) {
63 if (configs[i].getUnknown()) {
64 actionConfig = configs[i];
65
66 break;
67 }
68 }
69 }
70
71 if (actionConfig == null) {
72 throw new InvalidPathException("No action config found for the specified url.",
73 path);
74 }
75
76 actionCtx.setActionConfig(actionConfig);
77
78 return CONTINUE_PROCESSING;
79 }
80
81 // ------------------------------------------------------- Protected Methods
82
83 /**
84 * <p>Return the path to be used to select the <code>ActionConfig</code>
85 * for this request.</p>
86 *
87 * @param context The <code>Context</code> for this request
88 * @return Path to be used to select the ActionConfig
89 */
90 protected abstract String getPath(ActionContext context);
91 }