View Javadoc

1   /*
2    * $Id: AbstractExecuteAction.java 421119 2006-07-12 04:49:11Z wsmoak $
3    *
4    * Copyright 2000-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts.chain.commands;
19  
20  import org.apache.struts.action.Action;
21  import org.apache.struts.action.ActionForm;
22  import org.apache.struts.chain.contexts.ActionContext;
23  import org.apache.struts.config.ActionConfig;
24  import org.apache.struts.config.ForwardConfig;
25  
26  /***
27   * <p>Invoke the appropriate <code>Action</code> for this request, and cache
28   * the returned <code>ActionForward</code>.</p>
29   *
30   * @version $Rev: 421119 $ $Date: 2005-06-04 10:58:46 -0400 (Sat, 04 Jun 2005)
31   *          $
32   */
33  public abstract class AbstractExecuteAction extends ActionCommandBase {
34      // ---------------------------------------------------------- Public Methods
35  
36      /***
37       * <p>Invoke the appropriate <code>Action</code> for this request, and
38       * cache the returned <code>ActionForward</code>.</p>
39       *
40       * @param actionCtx The <code>Context</code> for the current request
41       * @return <code>false</code> so that processing continues
42       * @throws Exception if thrown by the Action class
43       */
44      public boolean execute(ActionContext actionCtx)
45          throws Exception {
46          // Skip processing if the current request is not valid
47          Boolean valid = actionCtx.getFormValid();
48  
49          if ((valid == null) || !valid.booleanValue()) {
50              return (false);
51          }
52  
53          // Acquire the resources we will need to send to the Action
54          Action action = actionCtx.getAction();
55  
56          if (action == null) {
57              return (false);
58          }
59  
60          ActionConfig actionConfig = actionCtx.getActionConfig();
61          ActionForm actionForm = actionCtx.getActionForm();
62  
63          // Execute the Action for this request, caching returned ActionForward
64          ForwardConfig forwardConfig =
65              execute(actionCtx, action, actionConfig, actionForm);
66  
67          actionCtx.setForwardConfig(forwardConfig);
68  
69          return (false);
70      }
71  
72      // ------------------------------------------------------- Protected Methods
73  
74      /***
75       * <p>Execute the specified <code>Action</code>, and return the resulting
76       * <code>ForwardConfig</code>.</p>
77       *
78       * @param context      The <code>Context</code> for this request
79       * @param action       The <code>Action</code> to be executed
80       * @param actionConfig The <code>ActionConfig</code> defining this action
81       * @param actionForm   The <code>ActionForm</code> (if any) for this
82       *                     action
83       * @return ForwardConfig The next location, or null
84       * @throws Exception if thrown by the <code>Action</code>
85       */
86      protected abstract ForwardConfig execute(ActionContext context,
87          Action action, ActionConfig actionConfig, ActionForm actionForm)
88          throws Exception;
89  }