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.action.Action;
24 import org.apache.struts.action.ActionForm;
25 import org.apache.struts.chain.contexts.ActionContext;
26 import org.apache.struts.config.ActionConfig;
27 import org.apache.struts.config.ForwardConfig;
28
29 /**
30 * <p>Invoke the appropriate <code>Action</code> for this request, and cache
31 * the returned <code>ActionForward</code>.</p>
32 *
33 * @version $Rev$
34 * @see ExecuteDispatcher
35 * @since Struts 1.3
36 */
37 public abstract class AbstractExecuteAction extends ActionCommandBase {
38 // ---------------------------------------------------------- Public Methods
39
40 /**
41 * <p>Invoke the appropriate <code>Action</code> for this request
42 * if a dispatcher is not available, and cache the returned
43 * <code>ActionForward</code>.</p>
44 *
45 * @param actionCtx The <code>Context</code> for the current request
46 * @return <code>false</code> so that processing continues
47 * @throws Exception if thrown by the Action class
48 */
49 @Override
50 protected boolean execute_(ActionContext actionCtx)
51 throws Exception {
52
53 // Skip processing if the current request is not valid
54 Boolean valid = actionCtx.getFormValid();
55 if ((valid == null) || !valid.booleanValue()) {
56 return CONTINUE_PROCESSING;
57 }
58
59 // Skip processing if a dispatcher is available
60 ActionConfig actionConfig = actionCtx.getActionConfig();
61 if (actionConfig.getDispatcher() != null) {
62 return CONTINUE_PROCESSING;
63 }
64
65 // Acquire the resources we will need to send to the Action
66 Action action = actionCtx.getAction();
67 if (action == null) {
68 return CONTINUE_PROCESSING;
69 }
70
71 ActionForm actionForm = actionCtx.getActionForm();
72
73 // Execute the Action for this request, caching returned ActionForward
74 ForwardConfig forwardConfig =
75 execute(actionCtx, action, actionConfig, actionForm);
76
77 actionCtx.setForwardConfig(forwardConfig);
78
79 return CONTINUE_PROCESSING;
80 }
81
82 // ------------------------------------------------------- Protected Methods
83
84 /**
85 * <p>Execute the specified <code>Action</code>, and return the resulting
86 * <code>ForwardConfig</code>.</p>
87 *
88 * @param context The <code>Context</code> for this request
89 * @param action The <code>Action</code> to be executed
90 * @param actionConfig The <code>ActionConfig</code> defining this action
91 * @param actionForm The <code>ActionForm</code> (if any) for this
92 * action
93 * @return ForwardConfig The next location, or null
94 * @throws Exception if thrown by the <code>Action</code>
95 */
96 protected abstract ForwardConfig execute(ActionContext context,
97 Action action, ActionConfig actionConfig, ActionForm actionForm)
98 throws Exception;
99 }