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 | 0 | public class GlobalVariables { |
33 | |
|
34 | 0 | private static ThreadLocal<UserSession> userSessions = new ThreadLocal<UserSession>(); |
35 | 0 | private static ThreadLocal<String> hideSessionFromTestsMessage = new ThreadLocal<String>(); |
36 | 0 | private static ThreadLocal<KualiForm> kualiForms = new ThreadLocal<KualiForm>(); |
37 | |
|
38 | 0 | private static ThreadLocal<MessageMap> messageMaps = new ThreadLocal<MessageMap>() { |
39 | |
protected MessageMap initialValue() { |
40 | 0 | return new MessageMap(); |
41 | |
} |
42 | |
}; |
43 | |
|
44 | |
|
45 | 0 | private static ThreadLocal<MessageList> messageLists = new ThreadLocal<MessageList>() { |
46 | |
protected MessageList initialValue() { |
47 | 0 | return new MessageList(); |
48 | |
} |
49 | |
}; |
50 | |
|
51 | 0 | private static ThreadLocal<HashMap> auditErrorMaps = new ThreadLocal<HashMap>() { |
52 | |
protected HashMap initialValue() { |
53 | 0 | return new HashMap(); |
54 | |
} |
55 | |
}; |
56 | |
|
57 | 0 | private static ThreadLocal<Map<String,Object>> requestCaches = new ThreadLocal<Map<String,Object>>() { |
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 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
@Deprecated |
100 | |
public static ErrorMap getErrorMap() { |
101 | 0 | return new ErrorMap(getMessageMap()); |
102 | |
} |
103 | |
|
104 | |
public static MessageMap getMessageMap() { |
105 | 0 | return messageMaps.get(); |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public static void mergeErrorMap(MessageMap messageMap) { |
113 | 0 | getMessageMap().getErrorMessages().putAll(messageMap.getErrorMessages()); |
114 | 0 | getMessageMap().getWarningMessages().putAll(messageMap.getWarningMessages()); |
115 | 0 | getMessageMap().getInfoMessages().putAll(messageMap.getInfoMessages()); |
116 | 0 | } |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
public static void setMessageMap(MessageMap messageMap) { |
124 | 0 | messageMaps.set(messageMap); |
125 | 0 | } |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
@Deprecated |
135 | |
public static void setErrorMap(ErrorMap errorMap) { |
136 | 0 | setMessageMap(errorMap); |
137 | 0 | } |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
public static MessageList getMessageList() { |
143 | 0 | return messageLists.get(); |
144 | |
} |
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
public static void setMessageList(MessageList messageList) { |
152 | 0 | messageLists.set(messageList); |
153 | 0 | } |
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
public static HashMap getAuditErrorMap() { |
159 | 0 | return auditErrorMaps.get(); |
160 | |
} |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
public static void setAuditErrorMap(HashMap errorMap) { |
168 | 0 | auditErrorMaps.set(errorMap); |
169 | 0 | } |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
public static KualiForm getKualiForm() { |
175 | 0 | return kualiForms.get(); |
176 | |
} |
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
|
183 | |
public static void setKualiForm(KualiForm kualiForm) { |
184 | 0 | kualiForms.set(kualiForm); |
185 | 0 | } |
186 | |
|
187 | |
public static Object getRequestCache( String cacheName ) { |
188 | 0 | return requestCaches.get().get(cacheName); |
189 | |
} |
190 | |
|
191 | |
public static void setRequestCache( String cacheName, Object cacheObject ) { |
192 | 0 | requestCaches.get().put(cacheName, cacheObject); |
193 | 0 | } |
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
public static void clear() { |
200 | 0 | messageMaps.set(new MessageMap()); |
201 | 0 | auditErrorMaps.set(new HashMap()); |
202 | 0 | messageLists.set(new MessageList()); |
203 | 0 | requestCaches.set(new HashMap<String,Object>() ); |
204 | 0 | kualiForms.set(null); |
205 | 0 | } |
206 | |
} |