View Javadoc

1   /*
2    * $Id: ActionMapping.java 421119 2006-07-12 04:49:11Z wsmoak $
3    *
4    * Copyright 2000-2004 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.action;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.apache.struts.config.ActionConfig;
23  import org.apache.struts.config.ForwardConfig;
24  
25  import java.util.ArrayList;
26  
27  /***
28   * <p>An <strong>ActionMapping</strong> represents the information that the
29   * controller, <code>RequestProcessor</code>, knows about the mapping of a
30   * particular request to an instance of a particular <code>Action</code>
31   * class. The <code>ActionMapping</code> instance used to select a particular
32   * <code>Action</code> is passed on to that <code>Action</code>, thereby
33   * providing access to any custom configuration information included with the
34   * <code>ActionMapping</code> object.</p>
35   *
36   * <p>Since Struts 1.1 this class extends <code>ActionConfig</code>.
37   *
38   * <p><strong>NOTE</strong> - This class would have been deprecated and
39   * replaced by <code>org.apache.struts.config.ActionConfig</code> except for
40   * the fact that it is part of the public API that existing applications are
41   * using.</p>
42   *
43   * @version $Rev: 421119 $ $Date: 2005-08-26 21:58:39 -0400 (Fri, 26 Aug 2005)
44   *          $
45   */
46  public class ActionMapping extends ActionConfig {
47      /***
48       * <p>Commons Logging instance.</p>
49       *
50       * @since Struts 1.2.8
51       */
52      private static Log log = LogFactory.getLog(ActionMapping.class);
53  
54      /***
55       * <p>Find and return the <code>ForwardConfig</code> instance defining how
56       * forwarding to the specified logical name should be handled. This is
57       * performed by checking local and then global configurations for the
58       * specified forwarding configuration. If no forwarding configuration can
59       * be found, return <code>null</code>.</p>
60       *
61       * @param forwardName Logical name of the forwarding instance to be
62       *                    returned
63       * @return The local or global forward with the specified name.
64       */
65      public ActionForward findForward(String forwardName) {
66          ForwardConfig config = findForwardConfig(forwardName);
67  
68          if (config == null) {
69              config = getModuleConfig().findForwardConfig(forwardName);
70          }
71  
72          if (config == null) {
73              if (log.isWarnEnabled()) {
74                  log.warn("Unable to find '" + forwardName + "' forward.");
75              }
76          }
77  
78          return ((ActionForward) config);
79      }
80  
81      /***
82       * <p>Return the logical names of all locally defined forwards for this
83       * mapping. If there are no such forwards, a zero-length array is
84       * returned.</p>
85       *
86       * @return The forward names for this action mapping.
87       */
88      public String[] findForwards() {
89          ArrayList results = new ArrayList();
90          ForwardConfig[] fcs = findForwardConfigs();
91  
92          for (int i = 0; i < fcs.length; i++) {
93              results.add(fcs[i].getName());
94          }
95  
96          return ((String[]) results.toArray(new String[results.size()]));
97      }
98  
99      /***
100      * <p>Create (if necessary) and return an {@link ActionForward} that
101      * corresponds to the <code>input</code> property of this Action.</p>
102      *
103      * @return The input forward for this action mapping.
104      * @since Struts 1.1
105      */
106     public ActionForward getInputForward() {
107         if (getModuleConfig().getControllerConfig().getInputForward()) {
108             return (findForward(getInput()));
109         } else {
110             return (new ActionForward(getInput()));
111         }
112     }
113 }