KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > collections > BasePropertiesImpl


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// This file is
5
// Copyright (C) 2002-@year@ by Leo Mekenkamp. All rights reserved.
6
// $Id: BasePropertiesImpl.java,v 1.2 2003/11/20 23:18:41 per_nyfelt Exp $
7

8 package org.ozoneDB.collections;
9
10 import java.util.Enumeration JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.Map JavaDoc;
13 import java.util.Properties JavaDoc;
14 import org.ozoneDB.OzoneObject;
15
16 /**
17  * See the overall description on {@link org.ozoneDB.collections.OzoneCollection}.
18  * <br/>Although properties are technically not a <code>Collection</code>,
19  * there are enough similarities to justify placing one in this package.
20  *
21  * @author <a HREF="mailto:ozone-db.orgATmekenkampD0Tcom">Leo Mekenkamp (mind the anti-sp@m)</a>
22  */

23 public class BasePropertiesImpl extends OzoneObject implements OzoneProperties {
24
25     private static final long serialVersionUID = 1L;
26
27     protected OzoneTreeMap backingMap;
28
29     protected BasePropertiesImpl() {
30     }
31
32     public void load(Properties JavaDoc properties) {
33         for(Iterator JavaDoc i = properties.keySet().iterator(); i.hasNext(); ) {
34             String JavaDoc key = (String JavaDoc) i.next();
35             setProperty(key, properties.getProperty(key));
36         }
37     }
38
39     public String JavaDoc getProperty(String JavaDoc key) {
40         return (String JavaDoc) backingMap.get(key);
41     }
42
43     public String JavaDoc getProperty(String JavaDoc key, String JavaDoc defaultValue) {
44         String JavaDoc result = getProperty(key);
45         return result == null ? defaultValue : result;
46     }
47
48     public Enumeration JavaDoc propertyNames() {
49         return new IteratorEnumerationAdaptor(backingMap.keySet().iterator());
50     }
51
52     public String JavaDoc setProperty(String JavaDoc key, String JavaDoc value) {
53         return (String JavaDoc) backingMap.put(key, value);
54     }
55
56     public Properties JavaDoc getClientProperties() {
57         Properties JavaDoc result = new Properties JavaDoc();
58         for(Iterator JavaDoc i = backingMap.entrySet().iterator(); i.hasNext(); ) {
59             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) i.next();
60             result.setProperty((String JavaDoc) entry.getKey(), (String JavaDoc) entry.getValue());
61         }
62         return result;
63     }
64
65 }
66
Popular Tags