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
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
88 private static class UnmodifiableEntry<K, V> implements Entry<K, V> {
89
90
91 private final K key;
92
93
94 private final V value;
95
96
97
98
99
100
101
102
103
104 public UnmodifiableEntry(final K key, final V value) {
105 this.key = key;
106 this.value = value;
107 }
108
109
110
111
112 public K getKey() {
113 return key;
114 }
115
116
117
118
119 public V getValue() {
120 return value;
121 }
122
123
124
125
126
127
128
129 public V setValue(final Object value) {
130 throw new UnsupportedOperationException();
131 }
132
133 }
134
135 }