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 org.apache.commons.configuration.AbstractConfiguration;
20
21 /***
22 * <p>
23 * An abstract base class for all web configurations.
24 * </p>
25 * <p>
26 * This class implements common functionality used by all web based
27 * configurations. E.g. some methods are not supported by configurations of this
28 * type, so they throw a <code>UnsupportedOperationException</code> exception.
29 * </p>
30 *
31 * @author Oliver Heger
32 * @version $Id: BaseWebConfiguration.java 439648 2006-09-02 20:42:10Z oheger $
33 * @since 1.2
34 */
35 abstract class BaseWebConfiguration extends AbstractConfiguration
36 {
37 /***
38 * Checks if this configuration is empty. This implementation makes use of
39 * the <code>getKeys()</code> method (which must be defined by concrete
40 * sub classes) to find out whether properties exist.
41 *
42 * @return a flag whether this configuration is empty
43 */
44 public boolean isEmpty()
45 {
46 return !getKeys().hasNext();
47 }
48
49 /***
50 * Checks whether the specified key is stored in this configuration.
51 *
52 * @param key the key
53 * @return a flag whether this key exists in this configuration
54 */
55 public boolean containsKey(String key)
56 {
57 return getProperty(key) != null;
58 }
59
60 /***
61 * Removes the property with the given key. <strong>This operation is not
62 * supported and will throw an UnsupportedOperationException.</strong>
63 *
64 * @param key the key of the property to be removed
65 * @throws UnsupportedOperationException because this operation is not
66 * allowed
67 */
68 public void clearProperty(String key)
69 {
70 throw new UnsupportedOperationException("Read only configuration");
71 }
72
73 /***
74 * Adds a property to this configuration. <strong>This operation is not
75 * supported and will throw an UnsupportedOperationException.</strong>
76 *
77 * @param key the key of the property
78 * @param obj the value to be added
79 * @throws UnsupportedOperationException because this operation is not
80 * allowed
81 */
82 protected void addPropertyDirect(String key, Object obj)
83 {
84 throw new UnsupportedOperationException("Read only configuration");
85 }
86 }