%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.container.session.PortalSessionMonitorImpl |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.jetspeed.container.session; |
|
18 | ||
19 | import javax.servlet.http.HttpSession; |
|
20 | import javax.servlet.http.HttpSessionBindingEvent; |
|
21 | import javax.servlet.http.HttpSessionEvent; |
|
22 | ||
23 | import org.apache.jetspeed.services.JetspeedPortletServices; |
|
24 | import org.apache.jetspeed.services.PortletServices; |
|
25 | ||
26 | /** |
|
27 | * PortalSessionMonitorImpl |
|
28 | * |
|
29 | * @author <a href="mailto:ate@douma.nu">Ate Douma</a> |
|
30 | * @version $Id: $ |
|
31 | */ |
|
32 | public class PortalSessionMonitorImpl implements PortalSessionMonitor |
|
33 | { |
|
34 | private static final long serialVersionUID = 1239564779524373742L; |
|
35 | ||
36 | private long sessionKey; |
|
37 | private transient String sessionId; |
|
38 | private transient HttpSession session; |
|
39 | private boolean forceInvalidate; |
|
40 | ||
41 | public PortalSessionMonitorImpl(long sessionKey) |
|
42 | { |
|
43 | 0 | this(sessionKey,true); |
44 | 0 | } |
45 | ||
46 | public PortalSessionMonitorImpl(long sessionKey, boolean forceInvalidate) |
|
47 | 0 | { |
48 | 0 | this.sessionKey = sessionKey; |
49 | 0 | this.forceInvalidate = forceInvalidate; |
50 | 0 | } |
51 | ||
52 | /* (non-Javadoc) |
|
53 | * @see org.apache.jetspeed.container.session.PortalSessionMonitor#getSessionId() |
|
54 | */ |
|
55 | public String getSessionId() |
|
56 | { |
|
57 | 0 | return sessionId; |
58 | } |
|
59 | ||
60 | /* (non-Javadoc) |
|
61 | * @see org.apache.jetspeed.container.session.PortalSessionMonitor#getSessionKey() |
|
62 | */ |
|
63 | public long getSessionKey() |
|
64 | { |
|
65 | 0 | return sessionKey; |
66 | } |
|
67 | ||
68 | public HttpSession getSession() |
|
69 | { |
|
70 | 0 | return session; |
71 | } |
|
72 | ||
73 | ||
74 | /* (non-Javadoc) |
|
75 | * @see org.apache.jetspeed.container.session.PortalSessionMonitor#invalidateSession() |
|
76 | */ |
|
77 | public void invalidateSession() |
|
78 | { |
|
79 | 0 | HttpSession thisSession = session; |
80 | 0 | if ( thisSession != null ) |
81 | { |
|
82 | 0 | session = null; |
83 | 0 | if (forceInvalidate) |
84 | { |
|
85 | try |
|
86 | { |
|
87 | 0 | thisSession.invalidate(); |
88 | } |
|
89 | 0 | catch (Exception ise) |
90 | { |
|
91 | // ignore |
|
92 | 0 | } |
93 | } |
|
94 | } |
|
95 | 0 | } |
96 | ||
97 | /* (non-Javadoc) |
|
98 | * @see javax.servlet.http.HttpSessionBindingListener#valueBound(javax.servlet.http.HttpSessionBindingEvent) |
|
99 | */ |
|
100 | public void valueBound(HttpSessionBindingEvent event) |
|
101 | { |
|
102 | 0 | this.session = event.getSession(); |
103 | 0 | this.sessionId = session.getId(); |
104 | 0 | } |
105 | ||
106 | /* (non-Javadoc) |
|
107 | * @see javax.servlet.http.HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent) |
|
108 | */ |
|
109 | public void valueUnbound(HttpSessionBindingEvent event) |
|
110 | { |
|
111 | 0 | if ( session != null ) |
112 | { |
|
113 | 0 | PortalSessionsManager manager = getManager(); |
114 | 0 | if (manager != null) |
115 | { |
|
116 | 0 | manager.portalSessionDestroyed(this); |
117 | } |
|
118 | 0 | session = null; |
119 | } |
|
120 | 0 | } |
121 | ||
122 | /* (non-Javadoc) |
|
123 | * @see javax.servlet.http.HttpSessionActivationListener#sessionDidActivate(javax.servlet.http.HttpSessionEvent) |
|
124 | */ |
|
125 | public void sessionDidActivate(HttpSessionEvent event) |
|
126 | { |
|
127 | 0 | session = event.getSession(); |
128 | 0 | sessionId = session.getId(); |
129 | 0 | PortalSessionsManager manager = getManager(); |
130 | 0 | if (manager != null) |
131 | { |
|
132 | 0 | manager.portalSessionDidActivate(this); |
133 | } |
|
134 | 0 | } |
135 | ||
136 | /* (non-Javadoc) |
|
137 | * @see javax.servlet.http.HttpSessionActivationListener#sessionWillPassivate(javax.servlet.http.HttpSessionEvent) |
|
138 | */ |
|
139 | public void sessionWillPassivate(HttpSessionEvent event) |
|
140 | { |
|
141 | 0 | PortalSessionsManager manager = getManager(); |
142 | 0 | if (manager != null) |
143 | { |
|
144 | 0 | manager.portalSessionWillPassivate(this); |
145 | } |
|
146 | 0 | session = null; |
147 | 0 | } |
148 | ||
149 | private PortalSessionsManager getManager() |
|
150 | { |
|
151 | 0 | PortletServices services = JetspeedPortletServices.getSingleton(); |
152 | 0 | if (services != null) |
153 | { |
|
154 | 0 | return (PortalSessionsManager)services.getService(PortalSessionsManager.SERVICE_NAME); |
155 | } |
|
156 | 0 | return null; |
157 | } |
|
158 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |