KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > session > SessionListener


1 package org.apache.turbine.services.session;
2
3 /*
4  * Copyright 2001-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 import java.io.Serializable JavaDoc;
20 import javax.servlet.http.HttpSessionActivationListener JavaDoc;
21 import javax.servlet.http.HttpSessionEvent JavaDoc;
22 import javax.servlet.http.HttpSessionListener JavaDoc;
23
24 /**
25  * This class is a listener for both session creation and destruction,
26  * and for session activation and passivation. It must be configured
27  * via your web application's <code>web.xml</code> deployment
28  * descriptor as follows for the container to call it:
29  *
30  * <blockquote><code><pre>
31  * &lt;listener&gt;
32  * &lt;listener-class&gt;
33  * org.apache.turbine.session.SessionListener
34  * &lt;/listener-class&gt;
35  * &lt;/listener&gt;
36  * </pre></code></blockquote>
37  *
38  * <code>&lt;listener&gt;</code> elemements can occur between
39  * <code>&lt;context-param&gt;</code> and <code>&lt;servlet&gt;</code>
40  * elements in your deployment descriptor.
41  *
42  * The {@link #sessionCreated(HttpSessionEvent)} callback will
43  * automatically add an instance of this listener to any newly created
44  * <code>HttpSession</code> for detection of session passivation and
45  * re-activation.
46  *
47  * @since 2.3
48  * @author <a HREF="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
49  * @author <a HREF="mailto:dlr@apache.org">Daniel Rall</a>
50  * @version $Id: SessionListener.java,v 1.9.2.2 2004/05/20 03:06:50 seade Exp $
51  * @see javax.servlet.http.HttpSessionListener
52  */

53 public class SessionListener
54         implements HttpSessionListener JavaDoc, HttpSessionActivationListener JavaDoc, Serializable JavaDoc
55 {
56     // ---- HttpSessionListener implementation -----------------------------
57

58     /**
59      * Called by the servlet container when a new session is created
60      *
61      * @param event Session creation event.
62      */

63     public void sessionCreated(HttpSessionEvent JavaDoc event)
64     {
65         TurbineSession.addSession(event.getSession());
66         event.getSession().setAttribute(getClass().getName(), this);
67     }
68
69     /**
70      * Called by the servlet container when a session is destroyed
71      *
72      * @param event Session destruction event.
73      */

74     public void sessionDestroyed(HttpSessionEvent JavaDoc event)
75     {
76         TurbineSession.removeSession(event.getSession());
77     }
78
79
80     // ---- HttpSessionActivationListener implementation -------------------
81

82     /**
83      * Called by the servlet container when an existing session is
84      * (re-)activated.
85      *
86      * @param event Session activation event.
87      */

88     public void sessionDidActivate(HttpSessionEvent JavaDoc event)
89     {
90         TurbineSession.addSession(event.getSession());
91     }
92
93     /**
94      * Called by the servlet container when a an existing session is
95      * passivated.
96      *
97      * @param event Session passivation event.
98      */

99     public void sessionWillPassivate(HttpSessionEvent JavaDoc event)
100     {
101         TurbineSession.removeSession(event.getSession());
102     }
103 }
104
Popular Tags