1 package org.apache.turbine.services.session;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.Serializable;
20 import javax.servlet.http.HttpSessionActivationListener;
21 import javax.servlet.http.HttpSessionEvent;
22 import javax.servlet.http.HttpSessionListener;
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 * <listener>
32 * <listener-class>
33 * org.apache.turbine.session.SessionListener
34 * </listener-class>
35 * </listener>
36 * </pre></code></blockquote>
37 *
38 * <code><listener></code> elemements can occur between
39 * <code><context-param></code> and <code><servlet></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, HttpSessionActivationListener, Serializable
55 {
56
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 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 event)
75 {
76 TurbineSession.removeSession(event.getSession());
77 }
78
79
80
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 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 event)
100 {
101 TurbineSession.removeSession(event.getSession());
102 }
103 }