01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Michael Danilov
19: * @version $Revision$
20: */package java.awt.datatransfer;
21:
22: import java.util.*;
23: import java.io.*;
24:
25: final class DuplicatedPropertiesResourceBundle extends ResourceBundle {
26:
27: private final Properties properties;
28:
29: public DuplicatedPropertiesResourceBundle(InputStream stream)
30: throws IOException {
31: properties = new Properties() {
32: private static final long serialVersionUID = -4869518800983843099L;
33:
34: @SuppressWarnings("unchecked")
35: @Override
36: public Object put(Object key, Object value) {
37: Object oldValue = get(key);
38:
39: if (oldValue == null) {
40: return super .put(key, value);
41: }
42: List<Object> list;
43:
44: if (oldValue instanceof String) {
45: list = new LinkedList<Object>();
46: list.add(oldValue);
47: } else {
48: list = (List<Object>) oldValue;
49: }
50: list.add(value);
51:
52: return super .put(key, list);
53: }
54: };
55: properties.load(stream);
56: }
57:
58: @Override
59: public Object handleGetObject(String key) {
60: return properties.get(key);
61: }
62:
63: @SuppressWarnings("unchecked")
64: @Override
65: public Enumeration<String> getKeys() {
66: Enumeration<String> result = (Enumeration<String>) properties
67: .propertyNames();
68:
69: if (parent == null) {
70: return result;
71: }
72:
73: ArrayList<String> keys = Collections.list(result);
74: Enumeration<String> e = parent.getKeys();
75:
76: while (e.hasMoreElements()) {
77: String key = e.nextElement();
78:
79: if (!keys.contains(key)) {
80: keys.add(key);
81: }
82: }
83:
84: return Collections.enumeration(keys);
85: }
86: }
|