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