1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration;
18
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
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 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 map)
43 {
44 this.map = map;
45 }
46
47 /***
48 * Return the Map decorated by this configuration.
49 */
50 public Map getMap()
51 {
52 return map;
53 }
54
55 public Object getProperty(String key)
56 {
57 Object value = map.get(key);
58 if (value instanceof String)
59 {
60 List list = PropertyConverter.split((String) value, getDelimiter());
61 return list.size() > 1 ? list : value;
62 }
63 else
64 {
65 return value;
66 }
67 }
68
69 protected void addPropertyDirect(String key, Object 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 key)
80 {
81 return map.containsKey(key);
82 }
83
84 public void clearProperty(String key)
85 {
86 map.remove(key);
87 }
88
89 public Iterator getKeys()
90 {
91 return map.keySet().iterator();
92 }
93 }