1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration.web;
18
19 import java.util.List;
20
21 import org.apache.commons.configuration.AbstractConfiguration;
22 import org.apache.commons.configuration.PropertyConverter;
23
24 /***
25 * <p>
26 * An abstract base class for all web configurations.
27 * </p>
28 * <p>
29 * This class implements common functionality used by all web based
30 * configurations. E.g. some methods are not supported by configurations of this
31 * type, so they throw a <code>UnsupportedOperationException</code> exception.
32 * </p>
33 *
34 * @author Oliver Heger
35 * @version $Id: BaseWebConfiguration.java 515306 2007-03-06 21:15:00Z oheger $
36 * @since 1.2
37 */
38 abstract class BaseWebConfiguration extends AbstractConfiguration
39 {
40 /***
41 * Checks if this configuration is empty. This implementation makes use of
42 * the <code>getKeys()</code> method (which must be defined by concrete
43 * sub classes) to find out whether properties exist.
44 *
45 * @return a flag whether this configuration is empty
46 */
47 public boolean isEmpty()
48 {
49 return !getKeys().hasNext();
50 }
51
52 /***
53 * Checks whether the specified key is stored in this configuration.
54 *
55 * @param key the key
56 * @return a flag whether this key exists in this configuration
57 */
58 public boolean containsKey(String key)
59 {
60 return getProperty(key) != null;
61 }
62
63 /***
64 * Removes the property with the given key. <strong>This operation is not
65 * supported and will throw an UnsupportedOperationException.</strong>
66 *
67 * @param key the key of the property to be removed
68 * @throws UnsupportedOperationException because this operation is not
69 * allowed
70 */
71 public void clearProperty(String key)
72 {
73 throw new UnsupportedOperationException("Read only configuration");
74 }
75
76 /***
77 * Adds a property to this configuration. <strong>This operation is not
78 * supported and will throw an UnsupportedOperationException.</strong>
79 *
80 * @param key the key of the property
81 * @param obj the value to be added
82 * @throws UnsupportedOperationException because this operation is not
83 * allowed
84 */
85 protected void addPropertyDirect(String key, Object obj)
86 {
87 throw new UnsupportedOperationException("Read only configuration");
88 }
89
90 /***
91 * Takes care of list delimiters in property values. This method checks if
92 * delimiter parsing is enabled and the passed in value contains a delimiter
93 * character. If this is the case, a split operation is performed.
94 *
95 * @param value the property value to be examined
96 * @return the processed value
97 */
98 protected Object handleDelimiters(Object value)
99 {
100 if (!isDelimiterParsingDisabled() && value instanceof String)
101 {
102 List list = PropertyConverter.split((String) value,
103 getListDelimiter());
104 value = list.size() > 1 ? list : list.get(0);
105 }
106
107 return value;
108 }
109 }