001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.configuration.web;
018:
019: import java.util.List;
020:
021: import org.apache.commons.configuration.AbstractConfiguration;
022: import org.apache.commons.configuration.PropertyConverter;
023:
024: /**
025: * <p>
026: * An abstract base class for all web configurations.
027: * </p>
028: * <p>
029: * This class implements common functionality used by all web based
030: * configurations. E.g. some methods are not supported by configurations of this
031: * type, so they throw a <code>UnsupportedOperationException</code> exception.
032: * </p>
033: *
034: * @author Oliver Heger
035: * @version $Id: BaseWebConfiguration.java 515306 2007-03-06 21:15:00Z oheger $
036: * @since 1.2
037: */
038: abstract class BaseWebConfiguration extends AbstractConfiguration {
039: /**
040: * Checks if this configuration is empty. This implementation makes use of
041: * the <code>getKeys()</code> method (which must be defined by concrete
042: * sub classes) to find out whether properties exist.
043: *
044: * @return a flag whether this configuration is empty
045: */
046: public boolean isEmpty() {
047: return !getKeys().hasNext();
048: }
049:
050: /**
051: * Checks whether the specified key is stored in this configuration.
052: *
053: * @param key the key
054: * @return a flag whether this key exists in this configuration
055: */
056: public boolean containsKey(String key) {
057: return getProperty(key) != null;
058: }
059:
060: /**
061: * Removes the property with the given key. <strong>This operation is not
062: * supported and will throw an UnsupportedOperationException.</strong>
063: *
064: * @param key the key of the property to be removed
065: * @throws UnsupportedOperationException because this operation is not
066: * allowed
067: */
068: public void clearProperty(String key) {
069: throw new UnsupportedOperationException(
070: "Read only configuration");
071: }
072:
073: /**
074: * Adds a property to this configuration. <strong>This operation is not
075: * supported and will throw an UnsupportedOperationException.</strong>
076: *
077: * @param key the key of the property
078: * @param obj the value to be added
079: * @throws UnsupportedOperationException because this operation is not
080: * allowed
081: */
082: protected void addPropertyDirect(String key, Object obj) {
083: throw new UnsupportedOperationException(
084: "Read only configuration");
085: }
086:
087: /**
088: * Takes care of list delimiters in property values. This method checks if
089: * delimiter parsing is enabled and the passed in value contains a delimiter
090: * character. If this is the case, a split operation is performed.
091: *
092: * @param value the property value to be examined
093: * @return the processed value
094: */
095: protected Object handleDelimiters(Object value) {
096: if (!isDelimiterParsingDisabled() && value instanceof String) {
097: List list = PropertyConverter.split((String) value,
098: getListDelimiter());
099: value = list.size() > 1 ? list : list.get(0);
100: }
101:
102: return value;
103: }
104: }
|