|
@@ -1,54 +1,44 @@ |
1 |
1 |
|
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
2 |
|
package org.litesoft.GWT.server; |
3 |
3 |
|
|
4 |
|
- |
import java.io.*; |
5 |
|
- |
import javax.servlet.http.*; |
6 |
|
- |
|
7 |
4 |
|
import org.litesoft.bo.views.caching.*; |
8 |
5 |
|
import org.litesoft.core.*; |
9 |
6 |
|
|
10 |
|
- |
public class ServletSessionHelper |
11 |
|
- |
{ |
12 |
|
- |
public static ContextID callInit( HttpSession pHttpSession ) |
13 |
|
- |
{ |
|
7 |
+ |
import javax.servlet.http.*; |
|
8 |
+ |
import java.io.*; |
|
9 |
+ |
|
|
10 |
+ |
public class ServletSessionHelper { |
|
11 |
+ |
public static ContextID callInit( HttpSession pHttpSession ) { |
14 |
12 |
|
ContextID zContextID = getContextID( pHttpSession ); |
15 |
13 |
|
new ServerContext( zContextID, new OurServerSession( pHttpSession ) ).set(); |
16 |
14 |
|
return zContextID; |
17 |
15 |
|
} |
18 |
16 |
|
|
19 |
|
- |
public static void callFini() |
20 |
|
- |
{ |
|
17 |
+ |
public static void callFini() { |
21 |
18 |
|
ServerContext.clear(); |
22 |
19 |
|
} |
23 |
20 |
|
|
24 |
|
- |
public static void chkInitialized() |
25 |
|
- |
{ |
26 |
|
- |
if ( sCacheManager == null ) |
27 |
|
- |
{ |
|
21 |
+ |
public static void chkInitialized() { |
|
22 |
+ |
if ( sCacheManager == null ) { |
28 |
23 |
|
throw new IllegalStateException( "App Not Initialized" ); |
29 |
24 |
|
} |
30 |
25 |
|
} |
31 |
26 |
|
|
32 |
|
- |
public static void initialize( VoCacheManager pCacheManager ) |
33 |
|
- |
{ |
|
27 |
+ |
public static void initialize( VoCacheManager pCacheManager ) { |
34 |
28 |
|
sCacheManager = (pCacheManager != null) ? pCacheManager : VoCacheManager.NULL; |
35 |
29 |
|
} |
36 |
30 |
|
|
37 |
31 |
|
private static volatile VoCacheManager sCacheManager = null; // In Theory this should be non-static, but the UserID needs to access it! |
38 |
32 |
|
|
39 |
|
- |
public static VoCacheManager getCacheManager() |
40 |
|
- |
{ |
|
33 |
+ |
public static VoCacheManager getCacheManager() { |
41 |
34 |
|
return sCacheManager; |
42 |
35 |
|
} |
43 |
36 |
|
|
44 |
37 |
|
@SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter"}) |
45 |
|
- |
private static ContextID getContextID( HttpSession pHttpSession ) |
46 |
|
- |
{ |
|
38 |
+ |
private static ContextID getContextID( HttpSession pHttpSession ) { |
47 |
39 |
|
WrapperForContextID zWrapper; |
48 |
|
- |
synchronized ( pHttpSession ) |
49 |
|
- |
{ |
50 |
|
- |
if ( null == (zWrapper = (WrapperForContextID) pHttpSession.getAttribute( WrapperForContextID.SESSION_KEY )) ) |
51 |
|
- |
{ |
|
40 |
+ |
synchronized ( pHttpSession ) { |
|
41 |
+ |
if ( null == (zWrapper = (WrapperForContextID) pHttpSession.getAttribute( WrapperForContextID.SESSION_KEY )) ) { |
52 |
42 |
|
pHttpSession.setAttribute( WrapperForContextID.SESSION_KEY, // |
53 |
43 |
|
zWrapper = new WrapperForContextID( new ContextID( "HttpSession", pHttpSession.getId() ) ) ); |
54 |
44 |
|
} |
|
@@ -57,65 +47,54 @@ |
57 |
47 |
|
} |
58 |
48 |
|
|
59 |
49 |
|
private static final class WrapperForContextID implements Serializable, |
60 |
|
- |
HttpSessionBindingListener |
61 |
|
- |
{ |
|
50 |
+ |
HttpSessionBindingListener { |
62 |
51 |
|
private static final long serialVersionUID = 1L; |
63 |
52 |
|
|
64 |
53 |
|
public static final String SESSION_KEY = WrapperForContextID.class.getName(); |
65 |
54 |
|
|
66 |
55 |
|
private ContextID mContextID; |
67 |
56 |
|
|
68 |
|
- |
private WrapperForContextID( ContextID pContextID ) |
69 |
|
- |
{ |
|
57 |
+ |
private WrapperForContextID( ContextID pContextID ) { |
70 |
58 |
|
mContextID = pContextID; |
71 |
59 |
|
} |
72 |
60 |
|
|
73 |
|
- |
public ContextID getContextID() |
74 |
|
- |
{ |
|
61 |
+ |
public ContextID getContextID() { |
75 |
62 |
|
return mContextID; |
76 |
63 |
|
} |
77 |
64 |
|
|
78 |
65 |
|
@Override |
79 |
|
- |
public void valueBound( HttpSessionBindingEvent event ) |
80 |
|
- |
{ |
|
66 |
+ |
public void valueBound( HttpSessionBindingEvent event ) { |
81 |
67 |
|
} |
82 |
68 |
|
|
83 |
69 |
|
@Override |
84 |
|
- |
public void valueUnbound( HttpSessionBindingEvent event ) |
85 |
|
- |
{ |
|
70 |
+ |
public void valueUnbound( HttpSessionBindingEvent event ) { |
86 |
71 |
|
ServerContext.clearServerStore( mContextID ); |
87 |
72 |
|
VoCacheManager zCacheManager = sCacheManager; |
88 |
|
- |
if ( zCacheManager != null ) |
89 |
|
- |
{ |
|
73 |
+ |
if ( zCacheManager != null ) { |
90 |
74 |
|
zCacheManager.drop( mContextID ); |
91 |
75 |
|
} |
92 |
76 |
|
} |
93 |
77 |
|
} |
94 |
78 |
|
|
95 |
|
- |
private static class OurServerSession extends ServerSession |
96 |
|
- |
{ |
|
79 |
+ |
private static class OurServerSession extends ServerSession { |
97 |
80 |
|
private HttpSession mSession; |
98 |
81 |
|
|
99 |
|
- |
private OurServerSession( HttpSession pSession ) |
100 |
|
- |
{ |
|
82 |
+ |
private OurServerSession( HttpSession pSession ) { |
101 |
83 |
|
mSession = pSession; |
102 |
84 |
|
} |
103 |
85 |
|
|
104 |
86 |
|
@Override |
105 |
|
- |
protected Serializable LLgetAttribute( String pName ) |
106 |
|
- |
{ |
|
87 |
+ |
protected Serializable LLgetAttribute( String pName ) { |
107 |
88 |
|
return (Serializable) mSession.getAttribute( pName ); |
108 |
89 |
|
} |
109 |
90 |
|
|
110 |
91 |
|
@Override |
111 |
|
- |
protected void LLsetAttribute( String pName, Serializable pInstance ) |
112 |
|
- |
{ |
|
92 |
+ |
protected void LLsetAttribute( String pName, Serializable pInstance ) { |
113 |
93 |
|
mSession.setAttribute( pName, pInstance ); |
114 |
94 |
|
} |
115 |
95 |
|
|
116 |
96 |
|
@Override |
117 |
|
- |
protected void LLremoveAttribute( String pName ) |
118 |
|
- |
{ |
|
97 |
+ |
protected void LLremoveAttribute( String pName ) { |
119 |
98 |
|
mSession.removeAttribute( pName ); |
120 |
99 |
|
} |
121 |
100 |
|
} |