1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.internal.util;
17
18 import java.util.AbstractMap;
19 import java.util.Collections;
20 import java.util.Enumeration;
21 import java.util.LinkedHashSet;
22 import java.util.ResourceBundle;
23 import java.util.Set;
24
25
26
27
28
29
30 public class ResourceBundleMap extends AbstractMap<String, Object> {
31
32
33 private final ResourceBundle resourceBundle;
34
35
36 private Set<Entry<String, Object>> entrySet;
37
38
39
40
41
42
43
44 public ResourceBundleMap(final ResourceBundle resourceBundle) {
45 this.resourceBundle = resourceBundle;
46 }
47
48
49
50
51 @Override
52 public Object get(final Object key) {
53 return resourceBundle.getString((String) key);
54 }
55
56
57
58
59 @Override
60 public Set<Entry<String, Object>> entrySet() {
61 if (this.entrySet == null) {
62 final Set<Entry<String, Object>> entrySet = new LinkedHashSet<Entry<String, Object>>();
63 final Enumeration<String> keys = resourceBundle.getKeys();
64 while (keys.hasMoreElements()) {
65 final String key = keys.nextElement();
66 final Object value = resourceBundle.getObject(key);
67 final Entry<String, Object> entry = new UnmodifiableEntry<String, Object>(
68 key, value);
69 entrySet.add(entry);
70 }
71 this.entrySet = Collections.unmodifiableSet(entrySet);
72 }
73 return entrySet;
74 }
75
76
77
78
79
80
81
82
83
84
85
86 private static class UnmodifiableEntry<K, V> implements Entry<K, V> {
87
88
89 private final K key;
90
91
92 private final V value;
93
94
95
96
97
98
99
100
101
102 public UnmodifiableEntry(final K key, final V value) {
103 this.key = key;
104 this.value = value;
105 }
106
107
108
109
110 public K getKey() {
111 return key;
112 }
113
114
115
116
117 public V getValue() {
118 return value;
119 }
120
121
122
123
124
125
126
127 public V setValue(final Object value) {
128 throw new UnsupportedOperationException();
129 }
130
131 }
132
133 }