View Javadoc

1   /*
2    * $Id: ExecuteForwardCommand.java 421119 2006-07-12 04:49:11Z wsmoak $
3    *
4    * Copyright 2003-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.commons.chain.Command;
21  import org.apache.struts.chain.contexts.ActionContext;
22  import org.apache.struts.config.ForwardConfig;
23  
24  /***
25   * <p>Look up and execute a commons-chain <code>Command</code> based on
26   * properties of the ActionContext's <code>forwardConfig</code> property.
27   * </p>
28   */
29  public class ExecuteForwardCommand extends ExecuteCommand {
30      /***
31       * <p>Return the command specified by the <code>command</code> and
32       * <code>catalog</code> properties of the <code>forwardConfig</code>
33       * property of the given <code>ActionContext</code>.  If
34       * <code>forwardConfig</code> is null, return null.</p>
35       *
36       * @param context Our ActionContext
37       * @return Command to execute or null
38       */
39      protected Command getCommand(ActionContext context) {
40          ForwardConfig forwardConfig = context.getForwardConfig();
41  
42          if (forwardConfig == null) {
43              return null;
44          }
45  
46          return getCommand(forwardConfig.getCommand(), forwardConfig.getCatalog());
47      }
48  
49      /***
50       * <p> Determine whether the forwardConfig should be processed. </p>
51       *
52       * @param context The ActionContext we are processing
53       * @return <p><code>true</code> if the given <code>ActionContext</code>
54       *         has a non-null <code>forwardConfig</code> property.</p>
55       */
56      protected boolean shouldProcess(ActionContext context) {
57          return (context.getForwardConfig() != null);
58      }
59  }