01: /*
02: * $Id: AbstractSelectAction.java 471754 2006-11-06 14:55:09Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "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: 471754 $ $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: public boolean execute(ActionContext actionCtx) throws Exception {
48: // Identify the matching path for this request
49: String path = getPath(actionCtx);
50:
51: // Cache the corresponding ActonConfig instance
52: ModuleConfig moduleConfig = actionCtx.getModuleConfig();
53: ActionConfig actionConfig = moduleConfig.findActionConfig(path);
54:
55: if (actionConfig == null) {
56: // NOTE Shouldn't this be the responsibility of ModuleConfig?
57: // Locate the mapping for unknown paths (if any)
58: ActionConfig[] configs = moduleConfig.findActionConfigs();
59:
60: for (int i = 0; i < configs.length; i++) {
61: if (configs[i].getUnknown()) {
62: actionConfig = configs[i];
63:
64: break;
65: }
66: }
67: }
68:
69: if (actionConfig == null) {
70: throw new InvalidPathException(
71: "No action config found for the specified url.",
72: path);
73: }
74:
75: actionCtx.setActionConfig(actionConfig);
76:
77: return (false);
78: }
79:
80: // ------------------------------------------------------- Protected Methods
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: }
|