View Javadoc

1   /*
2    * $Id: ActionController.java 421151 2006-07-12 06:07:14Z wsmoak $
3    *
4    * Copyright 1999-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  
19  package org.apache.struts.tiles;
20  
21  import java.io.IOException;
22  
23  import javax.servlet.ServletContext;
24  import javax.servlet.ServletException;
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.http.HttpServletResponse;
27  
28  import org.apache.struts.action.Action;
29  
30  /***
31   * Struts wrapper implementation of Controller.  This implementation wraps an
32   * <code>Action</code> in a <code>Controller</code>.
33   */
34  public class ActionController implements Controller {
35  
36      /***
37       * Struts action wrapped.
38       */
39      private Action action = null;
40  
41      /***
42       * Constructor.
43       *
44       * @param action Action to be wrapped.
45       */
46      public ActionController(Action action) {
47          this.action = action;
48      }
49  
50      /***
51       * Method associated to a tile and called immediately before tile is
52       * included.  This implementation calls a Struts Action. No servlet is
53       * set by this method.
54       *
55       * @param tileContext    Current tile context.
56       * @param request        Current request.
57       * @param response       Current response.
58       * @param servletContext Current servlet context.
59       */
60      public void perform(
61              ComponentContext tileContext,
62              HttpServletRequest request,
63              HttpServletResponse response,
64              ServletContext servletContext)
65              throws ServletException, IOException {
66  
67          try {
68              action.execute(null, null, request, response);
69  
70          } catch (Exception e) {
71              throw new ServletException(e);
72          }
73      }
74  
75      /***
76       * @see org.apache.struts.tiles.Controller#execute(org.apache.struts.tiles.ComponentContext, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletContext)
77       */
78      public void execute(
79              ComponentContext tileContext,
80              HttpServletRequest request,
81              HttpServletResponse response,
82              ServletContext servletContext)
83              throws Exception {
84  
85          this.action.execute(null, null, request, response);
86  
87      }
88  }