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