1 /* 2 * $Id: AbstractExecuteAction.java 471754 2006-11-06 14:55:09Z husted $ 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: 471754 $ $Date: 2005-06-04 10:58:46 -0400 (Sat, 04 Jun 2005) 34 * $ 35 */ 36 public abstract class AbstractExecuteAction extends ActionCommandBase { 37 // ---------------------------------------------------------- Public Methods 38 39 /** 40 * <p>Invoke the appropriate <code>Action</code> for this request, and 41 * cache the returned <code>ActionForward</code>.</p> 42 * 43 * @param actionCtx The <code>Context</code> for the current request 44 * @return <code>false</code> so that processing continues 45 * @throws Exception if thrown by the Action class 46 */ 47 public boolean execute(ActionContext actionCtx) 48 throws Exception { 49 // Skip processing if the current request is not valid 50 Boolean valid = actionCtx.getFormValid(); 51 52 if ((valid == null) || !valid.booleanValue()) { 53 return (false); 54 } 55 56 // Acquire the resources we will need to send to the Action 57 Action action = actionCtx.getAction(); 58 59 if (action == null) { 60 return (false); 61 } 62 63 ActionConfig actionConfig = actionCtx.getActionConfig(); 64 ActionForm actionForm = actionCtx.getActionForm(); 65 66 // Execute the Action for this request, caching returned ActionForward 67 ForwardConfig forwardConfig = 68 execute(actionCtx, action, actionConfig, actionForm); 69 70 actionCtx.setForwardConfig(forwardConfig); 71 72 return (false); 73 } 74 75 // ------------------------------------------------------- Protected Methods 76 77 /** 78 * <p>Execute the specified <code>Action</code>, and return the resulting 79 * <code>ForwardConfig</code>.</p> 80 * 81 * @param context The <code>Context</code> for this request 82 * @param action The <code>Action</code> to be executed 83 * @param actionConfig The <code>ActionConfig</code> defining this action 84 * @param actionForm The <code>ActionForm</code> (if any) for this 85 * action 86 * @return ForwardConfig The next location, or null 87 * @throws Exception if thrown by the <code>Action</code> 88 */ 89 protected abstract ForwardConfig execute(ActionContext context, 90 Action action, ActionConfig actionConfig, ActionForm actionForm) 91 throws Exception; 92 }