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 private GlobalVariables() {
31 throw new UnsupportedOperationException("do not call");
32 }
33
34 private static ThreadLocal<UserSession> userSessions = new ThreadLocal<UserSession>();
35 private static ThreadLocal<String> hideSessionFromTestsMessage = new ThreadLocal<String>();
36
37 private static ThreadLocal<MessageMap> messageMaps = new ThreadLocal<MessageMap>() {
38 @Override
39 protected MessageMap initialValue() {
40 return new MessageMap();
41 }
42 };
43
44 private static ThreadLocal<Map<String,Object>> requestCaches = new ThreadLocal<Map<String,Object>>() {
45 @Override
46 protected HashMap<String, Object> initialValue() {
47 return new HashMap<String, Object>();
48 }
49 };
50
51
52
53
54
55 public static UserSession getUserSession() {
56 String message = hideSessionFromTestsMessage.get();
57 if (message != null) {
58 throw new RuntimeException(message);
59 }
60 return userSessions.get();
61 }
62
63
64
65
66
67
68
69 public static void setHideSessionFromTestsMessage(String message) {
70 hideSessionFromTestsMessage.set(message);
71 }
72
73
74
75
76
77
78 public static void setUserSession(UserSession userSession) {
79 userSessions.set(userSession);
80 }
81
82 public static MessageMap getMessageMap() {
83 return messageMaps.get();
84 }
85
86
87
88
89
90 public static void mergeErrorMap(MessageMap messageMap) {
91 getMessageMap().getErrorMessages().putAll(messageMap.getErrorMessages());
92 getMessageMap().getWarningMessages().putAll(messageMap.getWarningMessages());
93 getMessageMap().getInfoMessages().putAll(messageMap.getInfoMessages());
94 }
95
96
97
98
99
100
101 public static void setMessageMap(MessageMap messageMap) {
102 messageMaps.set(messageMap);
103 }
104
105 public static Object getRequestCache( String cacheName ) {
106 return requestCaches.get().get(cacheName);
107 }
108
109 public static void setRequestCache( String cacheName, Object cacheObject ) {
110 requestCaches.get().put(cacheName, cacheObject);
111 }
112
113
114
115
116 public static void clear() {
117 messageMaps.set(new MessageMap());
118 requestCaches.set(new HashMap<String,Object>() );
119 }
120 }