1 2 package com.lutris.appserver.server.sessionContainerAdapter; 3 4 import java.io.Serializable ; 5 import java.util.Date ; 6 7 import javax.servlet.http.HttpSession ; 8 import javax.servlet.http.HttpSessionActivationListener ; 9 import javax.servlet.http.HttpSessionBindingListener ; 10 import javax.servlet.http.HttpSessionEvent ; 11 import javax.servlet.http.HttpSessionBindingEvent ; 12 13 14 import com.lutris.appserver.server.session.SessionData; 15 import com.lutris.appserver.server.session.SessionException; 16 import com.lutris.appserver.server.session.SessionManager; 17 import com.lutris.appserver.server.user.User; 18 23 public class ContainerAdapterSession 24 implements com.lutris.appserver.server.session.Session,HttpSessionActivationListener ,HttpSessionBindingListener , Serializable { 25 26 29 private User user; 30 34 private SerializableSessionData sessionData; 35 38 private SessionManager sessionManager; 39 40 private HttpSession httpSession; 41 42 45 public ContainerAdapterSession () { 46 } 47 48 53 public ContainerAdapterSession (ContainerAdapterSessionManager sessionManager, 54 HttpSession httpSession) { 55 56 this.sessionManager = sessionManager; 57 this.httpSession = httpSession; 58 sessionData = new SerializableSessionData(); 59 user = null; 60 } 61 62 65 public User getUser () { 66 return user; 67 } 68 69 74 public void setUser (User user) throws com.lutris.appserver.server.session.SessionException { 75 this.user = user; 76 } 77 78 82 public void clearUser () throws com.lutris.appserver.server.session.SessionException { 83 user = null; 84 } 85 86 90 public String getSessionKey () { 91 if(httpSession!=null) 92 return httpSession.getId(); 93 else 94 return null; 95 } 96 97 101 public long getTimeCreated() 102 { 103 if(httpSession!=null) 104 return httpSession.getCreationTime(); 105 else 106 return -1; 107 } 108 114 115 public long getTimeLastUsed() { 116 if(httpSession!=null) 117 return httpSession.getLastAccessedTime(); 118 else 119 return -1; 120 } 121 122 protected void setTimeCreated(long cTime) 123 { 124 } 125 126 127 134 public long getMaxIdleTime() { 135 if(httpSession!=null) 136 return httpSession.getMaxInactiveInterval(); 137 else 138 return -1; 139 } 140 141 149 public void setMaxIdleTime(int maxIdleTime) { 150 if(httpSession!=null) 151 httpSession.setMaxInactiveInterval(maxIdleTime); 152 } 153 154 155 159 public SessionManager getSessionManager () { 160 return sessionManager; 161 } 162 163 public void setSessionManager (SessionManager sessionManager) { 164 this.sessionManager=sessionManager; 165 } 166 170 public SessionData getSessionData () { 171 return sessionData; 172 } 173 174 178 public void setSessionData (SessionData sessionData) { 179 this.sessionData = (SerializableSessionData)sessionData; 180 } 181 182 183 public boolean isNew () { 184 if(httpSession!=null) 185 return (httpSession.getCreationTime() == httpSession.getLastAccessedTime()); 186 else 187 return true; 188 } 189 190 public String toString () { 191 192 StringBuffer result=new StringBuffer (); 193 Date ct = new Date (getTimeCreated()); 194 result.append("CreationTime:"); 195 result.append(" "); 196 result.append(ct.toString()); 197 198 if(getUser()!=null) 199 { 200 result.append("\n"); 201 result.append("User:"); 202 result.append(" "); 203 result.append(getUser().getName()); 204 205 } 206 String data=getSessionData().toString(); 207 if(data!=null) 208 { 209 result.append("\n"); 210 result.append("SessionData:"); 211 result.append(" "); 212 result.append(data); 213 } 214 return result.toString(); 215 216 } 217 218 public HttpSession getHttpSession () { 219 return httpSession; 220 } 221 222 public void valueBound(HttpSessionBindingEvent event) 223 { 224 } 225 226 public void valueUnbound(HttpSessionBindingEvent event) 227 { 228 if("session".equals(event.getName())) 229 { 230 sessionManager = null; 231 httpSession = null; 232 user = null; 233 sessionData = null; 234 } 235 } 236 237 public void sessionWillPassivate(HttpSessionEvent event) 238 { 239 sessionManager = null; 240 httpSession = null; 241 } 242 243 public void sessionDidActivate(HttpSessionEvent event) 244 { 245 httpSession = event.getSession(); 246 } 247 248 } 249 | Popular Tags |