1 | /* |
2 | |
3 | Derby - Class com.ihost.cs.DoubleProperties |
4 | |
5 | Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.iapi.util; |
22 | |
23 | import java.util.Properties; |
24 | import java.util.Enumeration; |
25 | |
26 | /** |
27 | A properties object that links two independent |
28 | properties together. The read property set is always |
29 | searched first, with the write property set being |
30 | second. But any put() calls are always made directly to |
31 | the write object. |
32 | |
33 | Only the put(), keys() and getProperty() methods are supported |
34 | by this class. |
35 | */ |
36 | |
37 | public final class DoubleProperties extends Properties { |
38 | |
39 | private final Properties read; |
40 | private final Properties write; |
41 | |
42 | public DoubleProperties(Properties read, Properties write) { |
43 | this.read = read; |
44 | this.write = write; |
45 | } |
46 | |
47 | public Object put(Object key, Object value) { |
48 | return write.put(key, value); |
49 | } |
50 | |
51 | public String getProperty(String key) { |
52 | |
53 | return read.getProperty(key, write.getProperty(key)); |
54 | } |
55 | |
56 | public String getProperty(String key, String defaultValue) { |
57 | return read.getProperty(key, write.getProperty(key, defaultValue)); |
58 | |
59 | } |
60 | |
61 | public Enumeration propertyNames() { |
62 | |
63 | Properties p = new Properties(); |
64 | |
65 | if (write != null) { |
66 | |
67 | for (Enumeration e = write.propertyNames(); e.hasMoreElements(); ) { |
68 | String key = (String) e.nextElement(); |
69 | p.put(key, write.getProperty(key)); |
70 | } |
71 | } |
72 | |
73 | if (read != null) { |
74 | for (Enumeration e = read.propertyNames(); e.hasMoreElements(); ) { |
75 | String key = (String) e.nextElement(); |
76 | p.put(key, read.getProperty(key)); |
77 | } |
78 | } |
79 | return p.keys(); |
80 | } |
81 | } |