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