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