1 29 30 package nextapp.echo2.webrender; 31 32 import java.io.Serializable ; 33 34 import javax.servlet.http.HttpSession ; 35 import javax.servlet.http.HttpSessionActivationListener ; 36 import javax.servlet.http.HttpSessionBindingEvent ; 37 import javax.servlet.http.HttpSessionBindingListener ; 38 import javax.servlet.http.HttpSessionEvent ; 39 40 44 public abstract class UserInstance 45 implements HttpSessionActivationListener , HttpSessionBindingListener , Serializable { 46 47 public static final String PROPERTY_CLIENT_CONFIGURATION = "clientConfiguration"; 48 public static final String PROPERTY_SERVER_DELAY_MESSAGE = "serverDelayMessage"; 49 50 53 private String characterEncoding = "UTF-8"; 54 55 59 private ClientConfiguration clientConfiguration; 60 61 65 private ServerDelayMessage serverDelayMessage; 66 67 71 private ClientProperties clientProperties; 72 73 76 private String servletUri; 77 78 82 private transient HttpSession session; 83 84 87 private UserInstanceUpdateManager updateManager; 88 89 95 private long transactionId = 0; 96 97 103 public UserInstance(Connection conn) { 104 super(); 105 updateManager = new UserInstanceUpdateManager(); 106 conn.initUserInstance(this); 107 } 108 109 116 public String getCharacterEncoding() { 117 return characterEncoding; 118 } 119 120 127 public ClientConfiguration getClientConfiguration() { 128 return clientConfiguration; 129 } 130 131 137 public ClientProperties getClientProperties() { 138 return clientProperties; 139 } 140 141 146 public long getCurrentTransactionId() { 147 return transactionId; 148 } 149 150 155 public long getNextTransactionId() { 156 ++transactionId; 157 return transactionId; 158 } 159 160 166 public ServerDelayMessage getServerDelayMessage() { 167 return serverDelayMessage; 168 } 169 170 176 public String getServiceUri(Service service) { 177 return servletUri + "?serviceId=" + service.getId(); 178 } 179 180 196 public String getServiceUri(Service service, String [] parameterNames, String [] parameterValues) { 197 StringBuffer out = new StringBuffer (servletUri); 198 out.append("?serviceId="); 199 out.append(service.getId()); 200 for (int i = 0; i < parameterNames.length; ++i) { 201 out.append("&"); 202 out.append(parameterNames[i]); 203 if (parameterValues[i] != null) { 204 out.append("="); 205 out.append(parameterValues[i]); 206 } 207 } 208 return out.toString(); 209 } 210 211 216 public String getServletUri() { 217 return servletUri; 218 } 219 220 226 public UserInstanceUpdateManager getUserInstanceUpdateManager() { 227 return updateManager; 228 } 229 230 236 public HttpSession getSession() { 237 return session; 238 } 239 240 243 public void sessionDidActivate(HttpSessionEvent e) { 244 session = e.getSession(); 245 } 246 247 250 public void sessionWillPassivate(HttpSessionEvent e) { 251 session = null; 252 } 253 254 260 public void setClientConfiguration(ClientConfiguration clientConfiguration) { 261 this.clientConfiguration = clientConfiguration; 262 updateManager.processPropertyUpdate(PROPERTY_CLIENT_CONFIGURATION); 263 } 264 265 271 void setClientProperties(ClientProperties clientProperties) { 272 this.clientProperties = clientProperties; 273 } 274 275 281 public void setServerDelayMessage(ServerDelayMessage serverDelayMessage) { 282 this.serverDelayMessage = serverDelayMessage; 283 updateManager.processPropertyUpdate(PROPERTY_SERVER_DELAY_MESSAGE); 284 } 285 286 291 void setServletUri(String servletUri) { 292 this.servletUri = servletUri; 293 } 294 295 301 public void valueBound(HttpSessionBindingEvent e) { 302 session = e.getSession(); 303 } 304 305 311 public void valueUnbound(HttpSessionBindingEvent e) { 312 session = null; 313 } 314 } 315 | Popular Tags |