1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.teeda.core.application.navigation; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collections; |
20 | |
import java.util.HashMap; |
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class NavigationResource { |
28 | |
|
29 | 2 | private static final String NAVIGATON_CONTEXTS = NavigationResource.class |
30 | |
.getName() |
31 | |
+ "_NAVIGATION_CONTEXTS"; |
32 | |
|
33 | 1 | private static final String WILDCARD_NAVIGATION_CONTEXTS = NavigationResource.class |
34 | |
.getName() |
35 | |
+ "_WILDCARD_NAVIGATION_CONTEXTS"; |
36 | |
|
37 | 1 | private static final String DEFAULT_NAVIGATION_CONTEXTS = NavigationResource.class |
38 | |
.getName() |
39 | |
+ "_DEFAULT_NAVIGATION_CONTEXTS"; |
40 | |
|
41 | 1 | private static Map cache = new HashMap(); |
42 | |
|
43 | 0 | private NavigationResource() { |
44 | 0 | } |
45 | |
|
46 | |
public static void addNavigationContext(NavigationContext navigationContext) { |
47 | 18 | if (navigationContext == null) { |
48 | 1 | throw new IllegalArgumentException("navigationContext"); |
49 | |
} |
50 | 17 | String fromViewId = navigationContext.getFromViewId(); |
51 | 17 | if (navigationContext.isWildCardMatch()) { |
52 | |
|
53 | 5 | if (NavigationContext.WILDCARD.equals(fromViewId)) { |
54 | 3 | storeNavigationContext(fromViewId, navigationContext, |
55 | |
DEFAULT_NAVIGATION_CONTEXTS); |
56 | |
} else { |
57 | 2 | storeNavigationContext(fromViewId, navigationContext, |
58 | |
WILDCARD_NAVIGATION_CONTEXTS); |
59 | |
} |
60 | |
|
61 | |
} else { |
62 | 12 | storeNavigationContext(fromViewId, navigationContext, |
63 | |
NAVIGATON_CONTEXTS); |
64 | |
} |
65 | 17 | } |
66 | |
|
67 | |
public static void removeNavigationContext(String fromViewId) { |
68 | 1 | if (fromViewId == null) { |
69 | 0 | throw new IllegalArgumentException(fromViewId); |
70 | |
} |
71 | 1 | Map navContextsMap = (Map) cache.get(NAVIGATON_CONTEXTS); |
72 | 1 | if (navContextsMap == null) { |
73 | 0 | return; |
74 | |
} |
75 | 1 | navContextsMap.remove(fromViewId); |
76 | 1 | } |
77 | |
|
78 | |
public static Map getNavigationContexts() { |
79 | 15 | return (Map) cache.get(NAVIGATON_CONTEXTS); |
80 | |
} |
81 | |
|
82 | |
public static Map getWildCardMatchNavigationContexts() { |
83 | 4 | return (Map) cache.get(WILDCARD_NAVIGATION_CONTEXTS); |
84 | |
} |
85 | |
|
86 | |
public static Map getDefaultMatchNavigationContexts() { |
87 | 3 | return (Map) cache.get(DEFAULT_NAVIGATION_CONTEXTS); |
88 | |
} |
89 | |
|
90 | |
public static void removeAll() { |
91 | 1343 | cache.clear(); |
92 | 1343 | } |
93 | |
|
94 | |
protected static void storeNavigationContext(String fromViewId, |
95 | |
NavigationContext navContext, String applicationKey) { |
96 | 17 | Map navContextsMap = (Map) cache.get(applicationKey); |
97 | 17 | if (navContextsMap == null) { |
98 | 17 | navContextsMap = Collections.synchronizedMap(new HashMap()); |
99 | 17 | cache.put(applicationKey, navContextsMap); |
100 | |
} |
101 | 17 | List navContextList = (List) navContextsMap.get(fromViewId); |
102 | 17 | if (navContextList == null) { |
103 | 17 | navContextList = new ArrayList(); |
104 | |
} |
105 | 17 | navContextList.add(navContext); |
106 | 17 | navContextsMap.put(fromViewId, navContextList); |
107 | 17 | } |
108 | |
|
109 | |
} |