2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
package org.apache.commons.configuration.web;
19
import java.util.List;
21
import org.apache.commons.configuration.AbstractConfiguration;
22
import org.apache.commons.configuration.PropertyConverter;
26
* An abstract base class for all web configurations.
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} exception.
35
* href="http://commons.apache.org/configuration/team-list.html">Commons
36
* Configuration team</a>
37
* @version $Id: BaseWebConfiguration.java 1211122 2011-12-06 20:55:45Z oheger $
40
abstract class BaseWebConfiguration extends AbstractConfiguration
43
* Checks if this configuration is empty. This implementation makes use of
44
* the {@code getKeys()} method (which must be defined by concrete
45
* sub classes) to find out whether properties exist.
47
* @return a flag whether this configuration is empty
49
public boolean isEmpty()
51
return !getKeys().hasNext();
55
* Checks whether the specified key is stored in this configuration.
58
* @return a flag whether this key exists in this configuration
60
public boolean containsKey(String key)
62
return getProperty(key) != null;
66
* Removes the property with the given key. <strong>This operation is not
67
* supported and will throw an UnsupportedOperationException.</strong>
69
* @param key the key of the property to be removed
70
* @throws UnsupportedOperationException because this operation is not
74
public void clearProperty(String key)
76
throw new UnsupportedOperationException("Read only configuration");
80
* Adds a property to this configuration. <strong>This operation is not
81
* supported and will throw an UnsupportedOperationException.</strong>
83
* @param key the key of the property
84
* @param obj the value to be added
85
* @throws UnsupportedOperationException because this operation is not
89
protected void addPropertyDirect(String key, Object obj)
91
throw new UnsupportedOperationException("Read only configuration");
95
* Takes care of list delimiters in property values. This method checks if
96
* delimiter parsing is enabled and the passed in value contains a delimiter
97
* character. If this is the case, a split operation is performed.
99
* @param value the property value to be examined
100
* @return the processed value
102
protected Object handleDelimiters(Object value)
104
if (!isDelimiterParsingDisabled() && value instanceof String)
106
List<String> list = PropertyConverter.split((String) value,
108
value = list.size() > 1 ? list : list.get(0);