|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2002, 2008 Innoopract Informationssysteme GmbH. |
2 |
* Copyright (c) 2002, 2009 Innoopract Informationssysteme GmbH. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 7-12
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* Innoopract Informationssysteme GmbH - initial API and implementation |
9 |
* Innoopract Informationssysteme GmbH - initial API and implementation |
|
|
10 |
* EclipseSource - ongoing development |
| 10 |
******************************************************************************/ |
11 |
******************************************************************************/ |
| 11 |
package org.eclipse.rwt.internal.service; |
12 |
package org.eclipse.rwt.internal.service; |
| 12 |
|
13 |
|
|
Lines 26-34
Link Here
|
| 26 |
public static final String ID_SESSION_STORE |
27 |
public static final String ID_SESSION_STORE |
| 27 |
= SessionStoreImpl.class.getName(); |
28 |
= SessionStoreImpl.class.getName(); |
| 28 |
|
29 |
|
| 29 |
private final Map attributes = new HashMap(); |
30 |
private final Map attributes; |
| 30 |
private final Set listeners = new HashSet(); |
31 |
private final Set listeners; |
| 31 |
private final HttpSession session; |
32 |
private final HttpSession session; |
|
|
33 |
private final String id; |
| 32 |
private boolean bound; |
34 |
private boolean bound; |
| 33 |
private boolean aboutUnbound; |
35 |
private boolean aboutUnbound; |
| 34 |
private ISessionShutdownAdapter shutdownAdapter; |
36 |
private ISessionShutdownAdapter shutdownAdapter; |
|
Lines 36-41
Link Here
|
| 36 |
|
38 |
|
| 37 |
public SessionStoreImpl( final HttpSession session ) { |
39 |
public SessionStoreImpl( final HttpSession session ) { |
| 38 |
ParamCheck.notNull( session, "session" ); |
40 |
ParamCheck.notNull( session, "session" ); |
|
|
41 |
attributes = new HashMap(); |
| 42 |
listeners = new HashSet(); |
| 43 |
this.id = session.getId(); |
| 39 |
this.session = session; |
44 |
this.session = session; |
| 40 |
this.session.setAttribute( ID_SESSION_STORE, this ); |
45 |
this.session.setAttribute( ID_SESSION_STORE, this ); |
| 41 |
bound = true; |
46 |
bound = true; |
|
Lines 52-108
Link Here
|
| 52 |
} ); |
57 |
} ); |
| 53 |
} |
58 |
} |
| 54 |
} |
59 |
} |
| 55 |
|
|
|
| 56 |
|
60 |
|
| 57 |
////////////////////////// |
61 |
////////////////////////// |
| 58 |
// interface ISessionStore |
62 |
// interface ISessionStore |
| 59 |
|
63 |
|
| 60 |
public Object getAttribute( final String name ) { |
64 |
public Object getAttribute( final String name ) { |
| 61 |
checkBound(); |
65 |
Object result = null; |
| 62 |
synchronized( attributes ) { |
66 |
if( bound ) { |
| 63 |
return attributes.get( name ); |
67 |
synchronized( attributes ) { |
|
|
68 |
result = attributes.get( name ); |
| 69 |
} |
| 64 |
} |
70 |
} |
|
|
71 |
return result; |
| 65 |
} |
72 |
} |
| 66 |
|
73 |
|
| 67 |
public void setAttribute( final String name, final Object value ) { |
74 |
public boolean setAttribute( final String name, final Object value ) { |
| 68 |
checkBound(); |
75 |
boolean result = false; |
| 69 |
if( value == null ) { |
76 |
if( bound ) { |
| 70 |
removeAttribute( name ); |
77 |
result = true; |
| 71 |
} else { |
78 |
if( value == null ) { |
| 72 |
Object removed = null; |
79 |
removeAttribute( name ); |
| 73 |
synchronized( attributes ) { |
80 |
} else { |
| 74 |
if( attributes.containsKey( name ) ) { |
81 |
Object removed = null; |
| 75 |
removed = removeAttributeInternal( name ); |
82 |
synchronized( attributes ) { |
|
|
83 |
if( attributes.containsKey( name ) ) { |
| 84 |
removed = removeAttributeInternal( name ); |
| 85 |
} |
| 86 |
attributes.put( name, value ); |
| 76 |
} |
87 |
} |
| 77 |
attributes.put( name, value ); |
88 |
if( removed != null ) { |
| 78 |
} |
89 |
fireValueUnbound( name, removed ); |
| 79 |
if( removed != null ) { |
90 |
} |
| 80 |
fireValueUnbound( name, removed ); |
91 |
fireValueBound( name, value ); |
| 81 |
} |
92 |
} |
| 82 |
fireValueBound( name, value ); |
|
|
| 83 |
} |
93 |
} |
|
|
94 |
return result; |
| 84 |
} |
95 |
} |
| 85 |
|
96 |
|
| 86 |
public void removeAttribute( final String name ) { |
97 |
public boolean removeAttribute( final String name ) { |
| 87 |
checkBound(); |
98 |
boolean result = false; |
| 88 |
fireValueUnbound( name, removeAttributeInternal( name ) ); |
99 |
if( bound ) { |
|
|
100 |
result = true; |
| 101 |
fireValueUnbound( name, removeAttributeInternal( name ) ); |
| 102 |
} |
| 103 |
return result; |
| 89 |
} |
104 |
} |
| 90 |
|
105 |
|
| 91 |
public Enumeration getAttributeNames() { |
106 |
public Enumeration getAttributeNames() { |
| 92 |
checkBound(); |
107 |
Enumeration result = null; |
| 93 |
final Iterator iterator = attributes.keySet().iterator(); |
108 |
if( bound ) { |
| 94 |
return new Enumeration() { |
109 |
final Iterator iterator = attributes.keySet().iterator(); |
| 95 |
public boolean hasMoreElements() { |
110 |
result = new Enumeration() { |
| 96 |
return iterator.hasNext(); |
111 |
|
| 97 |
} |
112 |
public boolean hasMoreElements() { |
| 98 |
public Object nextElement() { |
113 |
return iterator.hasNext(); |
| 99 |
return iterator.next(); |
114 |
} |
| 100 |
} |
115 |
|
| 101 |
}; |
116 |
public Object nextElement() { |
|
|
117 |
return iterator.next(); |
| 118 |
} |
| 119 |
}; |
| 120 |
} |
| 121 |
return result; |
| 102 |
} |
122 |
} |
| 103 |
|
123 |
|
| 104 |
public String getId() { |
124 |
public String getId() { |
| 105 |
return session.getId(); |
125 |
return id; |
| 106 |
} |
126 |
} |
| 107 |
|
127 |
|
| 108 |
public HttpSession getHttpSession() { |
128 |
public HttpSession getHttpSession() { |
|
Lines 113-132
Link Here
|
| 113 |
return bound; |
133 |
return bound; |
| 114 |
} |
134 |
} |
| 115 |
|
135 |
|
| 116 |
public void addSessionStoreListener( final SessionStoreListener lsnr ) { |
136 |
public boolean addSessionStoreListener( final SessionStoreListener lsnr ) { |
| 117 |
checkAboutUnbound(); |
137 |
boolean result = false; |
| 118 |
checkBound(); |
138 |
if( bound && !aboutUnbound ) { |
| 119 |
synchronized( listeners ) { |
139 |
result = true; |
| 120 |
listeners.add( lsnr ); |
140 |
synchronized( listeners ) { |
|
|
141 |
listeners.add( lsnr ); |
| 142 |
} |
| 121 |
} |
143 |
} |
|
|
144 |
return result; |
| 122 |
} |
145 |
} |
| 123 |
|
146 |
|
| 124 |
public void removeSessionStoreListener( final SessionStoreListener lsnr ) { |
147 |
public boolean removeSessionStoreListener( final SessionStoreListener lsnr ) { |
| 125 |
checkAboutUnbound(); |
148 |
boolean result = false; |
| 126 |
checkBound(); |
149 |
if( bound && !aboutUnbound ) { |
| 127 |
synchronized( listeners ) { |
150 |
result = true; |
| 128 |
listeners.remove( lsnr ); |
151 |
synchronized( listeners ) { |
|
|
152 |
listeners.remove( lsnr ); |
| 153 |
} |
| 129 |
} |
154 |
} |
|
|
155 |
return result; |
| 130 |
} |
156 |
} |
| 131 |
|
157 |
|
| 132 |
|
158 |
|
|
Lines 239-257
Link Here
|
| 239 |
return result; |
265 |
return result; |
| 240 |
} |
266 |
} |
| 241 |
|
267 |
|
| 242 |
private void checkBound() { |
|
|
| 243 |
if( !bound ) { |
| 244 |
throw new IllegalStateException( "The session store has been unbound." ); |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
private void checkAboutUnbound() { |
| 249 |
if( aboutUnbound ) { |
| 250 |
String msg = "The session store is about to be unbound."; |
| 251 |
throw new IllegalStateException( msg ); |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
private void fireValueBound( final String name, final Object value ) { |
268 |
private void fireValueBound( final String name, final Object value ) { |
| 256 |
if( value instanceof HttpSessionBindingListener ) { |
269 |
if( value instanceof HttpSessionBindingListener ) { |
| 257 |
HttpSessionBindingListener listener |
270 |
HttpSessionBindingListener listener |