KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > configuration > MapConfiguration


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License")
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.configuration;
18
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22
23 /**
24  * A Map based Configuration.
25  *
26  * @author Emmanuel Bourg
27  * @version $Revision: 155408 $, $Date: 2005-02-26 13:56:39 +0100 (Sa, 26 Feb 2005) $
28  * @since 1.1
29  */

30 public class MapConfiguration extends AbstractConfiguration
31 {
32     /** The Map decorated by this configuration. */
33     protected Map JavaDoc map;
34
35     /**
36      * Create a Configuration decorator around the specified Map. The map is
37      * used to store the configuration properties, any change will also affect
38      * the Map.
39      *
40      * @param map
41      */

42     public MapConfiguration(Map JavaDoc map)
43     {
44         this.map = map;
45     }
46
47     /**
48      * Return the Map decorated by this configuration.
49      */

50     public Map JavaDoc getMap()
51     {
52         return map;
53     }
54
55     public Object JavaDoc getProperty(String JavaDoc key)
56     {
57         Object JavaDoc value = map.get(key);
58         if (value instanceof String JavaDoc)
59         {
60             List JavaDoc list = PropertyConverter.split((String JavaDoc) value, getDelimiter());
61             return list.size() > 1 ? list : value;
62         }
63         else
64         {
65             return value;
66         }
67     }
68
69     protected void addPropertyDirect(String JavaDoc key, Object JavaDoc obj)
70     {
71         map.put(key, obj);
72     }
73
74     public boolean isEmpty()
75     {
76         return map.isEmpty();
77     }
78
79     public boolean containsKey(String JavaDoc key)
80     {
81         return map.containsKey(key);
82     }
83
84     public void clearProperty(String JavaDoc key)
85     {
86         map.remove(key);
87     }
88
89     public Iterator JavaDoc getKeys()
90     {
91         return map.keySet().iterator();
92     }
93 }
94
Popular Tags