001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.container.session;
018:
019: import javax.servlet.http.HttpSession;
020: import javax.servlet.http.HttpSessionBindingEvent;
021: import javax.servlet.http.HttpSessionEvent;
022:
023: import org.apache.jetspeed.container.session.PortalSessionsManager;
024: import org.apache.jetspeed.container.session.PortletApplicationSessionMonitor;
025: import org.apache.jetspeed.services.JetspeedPortletServices;
026: import org.apache.jetspeed.services.PortletServices;
027:
028: /**
029: * PortletApplicationSessionMonitorImpl
030: *
031: * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
032: * @version $Id: $
033: */
034: public class PortletApplicationSessionMonitorImpl implements
035: PortletApplicationSessionMonitor {
036: private static final long serialVersionUID = -6729032046828426324L;
037:
038: private String contextPath;
039: private String portalSessionId;
040: private long portalSessionKey;
041: private transient HttpSession session;
042: private boolean forceInvalidate;
043:
044: public PortletApplicationSessionMonitorImpl(String contextPath,
045: String portalSessionId, long portalSessionKey) {
046: this (contextPath, portalSessionId, portalSessionKey, true);
047: }
048:
049: public PortletApplicationSessionMonitorImpl(String contextPath,
050: String portalSessionId, long portalSessionKey,
051: boolean forceInvalidate) {
052: this .contextPath = contextPath;
053: this .portalSessionId = portalSessionId;
054: this .portalSessionKey = portalSessionKey;
055: this .forceInvalidate = forceInvalidate;
056: }
057:
058: /* (non-Javadoc)
059: * @see org.apache.jetspeed.container.session.PortletApplicationSessionMonitor#getPortalSessionKey()
060: */
061: public long getPortalSessionKey() {
062: return portalSessionKey;
063: }
064:
065: /* (non-Javadoc)
066: * @see org.apache.jetspeed.container.session.PortletApplicationSessionMonitor#getPortalSessionId()
067: */
068: public String getPortalSessionId() {
069: return portalSessionId;
070: }
071:
072: public HttpSession getSession() {
073: return session;
074: }
075:
076: /* (non-Javadoc)
077: * @see org.apache.jetspeed.container.session.PortletApplicationSessionMonitor#getContextPath()
078: */
079: public String getContextPath() {
080: return contextPath;
081: }
082:
083: /* (non-Javadoc)
084: * @see org.apache.jetspeed.container.session.PortletApplicationSessionMonitor#invalidateSession()
085: */
086: public void invalidateSession() {
087: if (session != null) {
088: HttpSession this Session = session;
089: session = null;
090: if (forceInvalidate) {
091: try {
092: this Session.invalidate();
093: } catch (Exception ise) {
094: // ignore
095: }
096: }
097: }
098: }
099:
100: /* (non-Javadoc)
101: * @see javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet.http.HttpSessionBindingEvent)
102: */
103: public void valueBound(HttpSessionBindingEvent event) {
104: this .session = event.getSession();
105: }
106:
107: /* (non-Javadoc)
108: * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)
109: */
110: public void valueUnbound(HttpSessionBindingEvent event) {
111: if (session != null) {
112: PortalSessionsManager manager = getManager();
113: if (manager != null) {
114: manager.sessionDestroyed(this );
115: }
116: session = null;
117: }
118: }
119:
120: /* (non-Javadoc)
121: * @see javax.servlet.http.HttpSessionActivationListener#sessionDidActivate(javax.servlet.http.HttpSessionEvent)
122: */
123: public void sessionDidActivate(HttpSessionEvent event) {
124: this .session = event.getSession();
125: PortalSessionsManager manager = getManager();
126: if (manager != null) {
127: manager.sessionDidActivate(this );
128: }
129: }
130:
131: /* (non-Javadoc)
132: * @see javax.servlet.http.HttpSessionActivationListener#sessionWillPassivate(javax.servlet.http.HttpSessionEvent)
133: */
134: public void sessionWillPassivate(HttpSessionEvent event) {
135: PortalSessionsManager manager = getManager();
136: if (manager != null) {
137: manager.sessionWillPassivate(this );
138: }
139: session = null;
140: }
141:
142: private PortalSessionsManager getManager() {
143: PortletServices services = JetspeedPortletServices
144: .getSingleton();
145: if (services != null) {
146: return (PortalSessionsManager) services
147: .getService(PortalSessionsManager.SERVICE_NAME);
148: }
149: return null;
150: }
151: }
|