1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kns.util; |
17 | |
|
18 | |
import java.util.HashMap; |
19 | |
import java.util.Map; |
20 | |
|
21 | |
import org.kuali.rice.kns.UserSession; |
22 | |
import org.kuali.rice.kns.web.struts.form.KualiForm; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | 0 | public class GlobalVariables { |
30 | |
|
31 | 0 | private static ThreadLocal<UserSession> userSessions = new ThreadLocal<UserSession>(); |
32 | 0 | private static ThreadLocal<String> hideSessionFromTestsMessage = new ThreadLocal<String>(); |
33 | 0 | private static ThreadLocal<KualiForm> kualiForms = new ThreadLocal<KualiForm>(); |
34 | |
|
35 | 0 | private static ThreadLocal<MessageMap> messageMaps = new ThreadLocal<MessageMap>() { |
36 | |
@Override |
37 | |
protected MessageMap initialValue() { |
38 | 0 | return new MessageMap(); |
39 | |
} |
40 | |
}; |
41 | |
|
42 | 0 | private static ThreadLocal<MessageList> messageLists = new ThreadLocal<MessageList>() { |
43 | |
@Override |
44 | |
protected MessageList initialValue() { |
45 | 0 | return new MessageList(); |
46 | |
} |
47 | |
}; |
48 | |
|
49 | 0 | private static ThreadLocal<HashMap<String, AuditCluster>> auditErrorMaps = new ThreadLocal<HashMap<String, AuditCluster>>() { |
50 | |
@Override |
51 | |
protected HashMap<String, AuditCluster> initialValue() { |
52 | 0 | return new HashMap<String, AuditCluster>(); |
53 | |
} |
54 | |
}; |
55 | |
|
56 | 0 | private static ThreadLocal<Map<String,Object>> requestCaches = new ThreadLocal<Map<String,Object>>() { |
57 | |
@Override |
58 | |
protected HashMap<String, Object> initialValue() { |
59 | 0 | return new HashMap<String, Object>(); |
60 | |
} |
61 | |
}; |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public static UserSession getUserSession() { |
68 | 0 | String message = hideSessionFromTestsMessage.get(); |
69 | 0 | if (message != null) { |
70 | 0 | throw new RuntimeException(message); |
71 | |
} |
72 | 0 | return userSessions.get(); |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public static void setHideSessionFromTestsMessage(String message) { |
82 | 0 | hideSessionFromTestsMessage.set(message); |
83 | 0 | } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public static void setUserSession(UserSession userSession) { |
91 | 0 | userSessions.set(userSession); |
92 | 0 | } |
93 | |
|
94 | |
public static MessageMap getMessageMap() { |
95 | 0 | return messageMaps.get(); |
96 | |
} |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public static void mergeErrorMap(MessageMap messageMap) { |
103 | 0 | getMessageMap().getErrorMessages().putAll(messageMap.getErrorMessages()); |
104 | 0 | getMessageMap().getWarningMessages().putAll(messageMap.getWarningMessages()); |
105 | 0 | getMessageMap().getInfoMessages().putAll(messageMap.getInfoMessages()); |
106 | 0 | } |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public static void setMessageMap(MessageMap messageMap) { |
114 | 0 | messageMaps.set(messageMap); |
115 | 0 | } |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
public static MessageList getMessageList() { |
121 | 0 | return messageLists.get(); |
122 | |
} |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public static void setMessageList(MessageList messageList) { |
130 | 0 | messageLists.set(messageList); |
131 | 0 | } |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
public static Map<String, AuditCluster> getAuditErrorMap() { |
137 | 0 | return auditErrorMaps.get(); |
138 | |
} |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
public static void setAuditErrorMap(HashMap<String, AuditCluster> errorMap) { |
146 | 0 | auditErrorMaps.set(errorMap); |
147 | 0 | } |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
public static KualiForm getKualiForm() { |
153 | 0 | return kualiForms.get(); |
154 | |
} |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
public static void setKualiForm(KualiForm kualiForm) { |
162 | 0 | kualiForms.set(kualiForm); |
163 | 0 | } |
164 | |
|
165 | |
public static Object getRequestCache( String cacheName ) { |
166 | 0 | return requestCaches.get().get(cacheName); |
167 | |
} |
168 | |
|
169 | |
public static void setRequestCache( String cacheName, Object cacheObject ) { |
170 | 0 | requestCaches.get().put(cacheName, cacheObject); |
171 | 0 | } |
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
public static void clear() { |
178 | 0 | messageMaps.set(new MessageMap()); |
179 | 0 | auditErrorMaps.set(new HashMap<String, AuditCluster>()); |
180 | 0 | messageLists.set(new MessageList()); |
181 | 0 | requestCaches.set(new HashMap<String,Object>() ); |
182 | 0 | kualiForms.set(null); |
183 | 0 | } |
184 | |
} |