001: package org.apache.turbine.services.session;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.io.Serializable;
023: import javax.servlet.http.HttpSessionActivationListener;
024: import javax.servlet.http.HttpSessionEvent;
025: import javax.servlet.http.HttpSessionListener;
026:
027: /**
028: * This class is a listener for both session creation and destruction,
029: * and for session activation and passivation. It must be configured
030: * via your web application's <code>web.xml</code> deployment
031: * descriptor as follows for the container to call it:
032: *
033: * <blockquote><code><pre>
034: * <listener>
035: * <listener-class>
036: * org.apache.turbine.session.SessionListener
037: * </listener-class>
038: * </listener>
039: * </pre></code></blockquote>
040: *
041: * <code><listener></code> elemements can occur between
042: * <code><context-param></code> and <code><servlet></code>
043: * elements in your deployment descriptor.
044: *
045: * The {@link #sessionCreated(HttpSessionEvent)} callback will
046: * automatically add an instance of this listener to any newly created
047: * <code>HttpSession</code> for detection of session passivation and
048: * re-activation.
049: *
050: * @since 2.3
051: * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
052: * @author <a href="mailto:dlr@apache.org">Daniel Rall</a>
053: * @version $Id: SessionListener.java 534527 2007-05-02 16:10:59Z tv $
054: * @see javax.servlet.http.HttpSessionListener
055: */
056: public class SessionListener implements HttpSessionListener,
057: HttpSessionActivationListener, Serializable {
058: /** Serial Version UID */
059: private static final long serialVersionUID = -8083730704842809870L;
060:
061: // ---- HttpSessionListener implementation -----------------------------
062:
063: /**
064: * Called by the servlet container when a new session is created
065: *
066: * @param event Session creation event.
067: */
068: public void sessionCreated(HttpSessionEvent event) {
069: TurbineSession.addSession(event.getSession());
070: event.getSession().setAttribute(getClass().getName(), this );
071: }
072:
073: /**
074: * Called by the servlet container when a session is destroyed
075: *
076: * @param event Session destruction event.
077: */
078: public void sessionDestroyed(HttpSessionEvent event) {
079: TurbineSession.removeSession(event.getSession());
080: }
081:
082: // ---- HttpSessionActivationListener implementation -------------------
083:
084: /**
085: * Called by the servlet container when an existing session is
086: * (re-)activated.
087: *
088: * @param event Session activation event.
089: */
090: public void sessionDidActivate(HttpSessionEvent event) {
091: TurbineSession.addSession(event.getSession());
092: }
093:
094: /**
095: * Called by the servlet container when a an existing session is
096: * passivated.
097: *
098: * @param event Session passivation event.
099: */
100: public void sessionWillPassivate(HttpSessionEvent event) {
101: TurbineSession.removeSession(event.getSession());
102: }
103: }
|