KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > util > DoubleProperties


1 /*
2
3    Derby - Class com.ihost.cs.DoubleProperties
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (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 JavaDoc;
25 import java.util.Enumeration JavaDoc;
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 JavaDoc {
39
40     private final Properties JavaDoc read;
41     private final Properties JavaDoc write;
42
43     public DoubleProperties(Properties JavaDoc read, Properties JavaDoc write) {
44         this.read = read;
45         this.write = write;
46     }
47
48     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
49         return write.put(key, value);
50     }
51
52     public String JavaDoc getProperty(String JavaDoc key) {
53
54         return read.getProperty(key, write.getProperty(key));
55     }
56
57     public String JavaDoc getProperty(String JavaDoc key, String JavaDoc defaultValue) {
58         return read.getProperty(key, write.getProperty(key, defaultValue));
59
60     }
61
62     public Enumeration JavaDoc propertyNames() {
63
64         Properties JavaDoc p = new Properties JavaDoc();
65
66         if (write != null) {
67
68             for (Enumeration JavaDoc e = write.propertyNames(); e.hasMoreElements(); ) {
69                 String JavaDoc key = (String JavaDoc) e.nextElement();
70                 p.put(key, write.getProperty(key));
71             }
72         }
73
74         if (read != null) {
75             for (Enumeration JavaDoc e = read.propertyNames(); e.hasMoreElements(); ) {
76                 String JavaDoc key = (String JavaDoc) e.nextElement();
77                 p.put(key, read.getProperty(key));
78             }
79         }
80         return p.keys();
81     }
82 }
83
Popular Tags