View Javadoc

1   /*
2    * $Id: TilesServlet.java 531864 2007-04-24 10:24:30Z apetrelli $
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.tiles.web.startup;
22  
23  import org.apache.tiles.web.util.ServletContextAdapter;
24  
25  import javax.servlet.http.HttpServlet;
26  import javax.servlet.ServletContextEvent;
27  import javax.servlet.ServletException;
28  
29  /***
30   * Initialization Servlet. Provided for backwards compatibility.
31   * The prefered method of initialization is to use the TilesListener.
32   *
33   * @see org.apache.tiles.web.startup.TilesListener
34   * @version $Rev: 531864 $ $Date: 2007-04-24 12:24:30 +0200 (Tue, 24 Apr 2007) $
35   */
36  public class TilesServlet extends HttpServlet {
37  
38      /***
39       * The private listener instance, that is used to initialize Tiles
40       * container.
41       */
42      private TilesListener listener = new TilesListener();
43  
44      /*** {@inheritDoc} */
45      @Override
46      public void destroy() {
47          listener.contextDestroyed(createEvent());
48      }
49  
50      /*** {@inheritDoc} */
51      @Override
52      public void init() throws ServletException {
53          listener.contextInitialized(createEvent());
54      }
55  
56      /***
57       * Creates an servlet context event starting for the servlet configuration
58       * object.
59       *
60       * @return The servlet context event.
61       */
62      private ServletContextEvent createEvent() {
63          return new ServletContextEvent(
64              new ServletContextAdapter(getServletConfig())
65          );
66      }
67  
68  }