1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.util; |
17 | |
|
18 | |
import org.kuali.rice.krad.UserSession; |
19 | |
|
20 | |
import java.util.HashMap; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public final class GlobalVariables { |
29 | |
|
30 | 0 | private GlobalVariables() { |
31 | 0 | throw new UnsupportedOperationException("do not call"); |
32 | |
} |
33 | |
|
34 | 0 | private static ThreadLocal<UserSession> userSessions = new ThreadLocal<UserSession>(); |
35 | 0 | private static ThreadLocal<String> hideSessionFromTestsMessage = new ThreadLocal<String>(); |
36 | |
|
37 | 0 | private static ThreadLocal<MessageMap> messageMaps = new ThreadLocal<MessageMap>() { |
38 | |
@Override |
39 | |
protected MessageMap initialValue() { |
40 | 0 | return new MessageMap(); |
41 | |
} |
42 | |
}; |
43 | |
|
44 | 0 | private static ThreadLocal<Map<String,Object>> requestCaches = new ThreadLocal<Map<String,Object>>() { |
45 | |
@Override |
46 | |
protected HashMap<String, Object> initialValue() { |
47 | 0 | return new HashMap<String, Object>(); |
48 | |
} |
49 | |
}; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public static UserSession getUserSession() { |
56 | 0 | String message = hideSessionFromTestsMessage.get(); |
57 | 0 | if (message != null) { |
58 | 0 | throw new RuntimeException(message); |
59 | |
} |
60 | 0 | return userSessions.get(); |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public static void setHideSessionFromTestsMessage(String message) { |
70 | 0 | hideSessionFromTestsMessage.set(message); |
71 | 0 | } |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public static void setUserSession(UserSession userSession) { |
79 | 0 | userSessions.set(userSession); |
80 | 0 | } |
81 | |
|
82 | |
public static MessageMap getMessageMap() { |
83 | 0 | return messageMaps.get(); |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public static void mergeErrorMap(MessageMap messageMap) { |
91 | 0 | getMessageMap().getErrorMessages().putAll(messageMap.getErrorMessages()); |
92 | 0 | getMessageMap().getWarningMessages().putAll(messageMap.getWarningMessages()); |
93 | 0 | getMessageMap().getInfoMessages().putAll(messageMap.getInfoMessages()); |
94 | 0 | } |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public static void setMessageMap(MessageMap messageMap) { |
102 | 0 | messageMaps.set(messageMap); |
103 | 0 | } |
104 | |
|
105 | |
public static Object getRequestCache( String cacheName ) { |
106 | 0 | return requestCaches.get().get(cacheName); |
107 | |
} |
108 | |
|
109 | |
public static void setRequestCache( String cacheName, Object cacheObject ) { |
110 | 0 | requestCaches.get().put(cacheName, cacheObject); |
111 | 0 | } |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
public static void clear() { |
117 | 0 | messageMaps.set(new MessageMap()); |
118 | 0 | requestCaches.set(new HashMap<String,Object>() ); |
119 | 0 | } |
120 | |
} |