KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > context > ContextLoaderListener


1 /*
2  * Copyright 2002-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.context;
18
19 import javax.servlet.ServletContextEvent JavaDoc;
20 import javax.servlet.ServletContextListener JavaDoc;
21
22 /**
23  * Bootstrap listener to start up Spring's root {@link WebApplicationContext}.
24  * Simply delegates to {@link ContextLoader}.
25  *
26  * <p>This listener should be registered after
27  * {@link org.springframework.web.util.Log4jConfigListener}
28  * in <code>web.xml</code>, if the latter is used.
29  *
30  * <p>For Servlet 2.2 containers and Servlet 2.3 ones that do not initalize
31  * listeners before servlets, use {@link ContextLoaderServlet}.
32  * See the latter's Javadoc for details.
33  *
34  * @author Juergen Hoeller
35  * @since 17.02.2003
36  * @see ContextLoaderServlet
37  * @see org.springframework.web.util.Log4jConfigListener
38  */

39 public class ContextLoaderListener implements ServletContextListener JavaDoc {
40
41     private ContextLoader contextLoader;
42
43
44     /**
45      * Initialize the root web application context.
46      */

47     public void contextInitialized(ServletContextEvent JavaDoc event) {
48         this.contextLoader = createContextLoader();
49         this.contextLoader.initWebApplicationContext(event.getServletContext());
50     }
51
52     /**
53      * Create the ContextLoader to use. Can be overridden in subclasses.
54      * @return the new ContextLoader
55      */

56     protected ContextLoader createContextLoader() {
57         return new ContextLoader();
58     }
59
60     /**
61      * Return the ContextLoader used by this listener.
62      * @return the current ContextLoader
63      */

64     public ContextLoader getContextLoader() {
65         return this.contextLoader;
66     }
67
68
69     /**
70      * Close the root web application context.
71      */

72     public void contextDestroyed(ServletContextEvent JavaDoc event) {
73         if (this.contextLoader != null) {
74             this.contextLoader.closeWebApplicationContext(event.getServletContext());
75         }
76     }
77
78 }
79
Popular Tags