KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > web > taglib > Listener


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/web/taglib/Listener.java#4 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2002-2002 Kana Software, Inc.
7 // Copyright (C) 2002-2005 Julian Hyde and others
8 // All Rights Reserved.
9 // You must accept the terms of that agreement to use this software.
10 //
11 // Julian Hyde, 28 March, 2002
12 */

13 package mondrian.web.taglib;
14
15 import javax.servlet.ServletContextEvent JavaDoc;
16 import javax.servlet.ServletContextListener JavaDoc;
17
18 /**
19  * <code>Listener</code> creates and destroys a {@link ApplResources} at the
20  * appropriate times in the servlet's life-cycle.
21  *
22  * <p>NOTE: This class must not depend upon any non-standard packages (such as
23  * <code>javax.transform</code>) because it is loaded when Tomcat starts, not
24  * when the servlet is loaded. (This might be a bug in Tomcat 4.0.3, because
25  * it worked in 4.0.1. But anyway.)
26  */

27
28 public class Listener implements ServletContextListener JavaDoc {
29
30     ApplicationContext applicationContext;
31
32     public Listener() {
33     }
34
35     public void contextInitialized(ServletContextEvent JavaDoc event) {
36         Class JavaDoc clazz;
37         try {
38             clazz = Class.forName("mondrian.web.taglib.ApplResources");
39         } catch (ClassNotFoundException JavaDoc e) {
40             throw new Error JavaDoc(
41                 "Received [" + e.toString() + "] while initializing servlet");
42         }
43         Object JavaDoc o = null;
44         try {
45             o = clazz.newInstance();
46         } catch (InstantiationException JavaDoc e) {
47             throw new Error JavaDoc(
48                 "Received [" + e.toString() + "] while initializing servlet");
49         } catch (IllegalAccessException JavaDoc e) {
50             throw new Error JavaDoc(
51                 "Received [" + e.toString() + "] while initializing servlet");
52         }
53         ApplicationContext applicationContext = (ApplicationContext) o;
54         applicationContext.init(event);
55     }
56
57     public void contextDestroyed(ServletContextEvent JavaDoc event) {
58         if (applicationContext != null) {
59             applicationContext.destroy(event);
60         }
61     }
62
63     interface ApplicationContext {
64         void init(ServletContextEvent JavaDoc event);
65         void destroy(ServletContextEvent JavaDoc event);
66     }
67 }
68
69 // End Listener.java
70
Popular Tags