| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| BaseWebConfiguration |
|
| 1.6;1,6 |
| 1 | /* | |
| 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 | |
| 8 | * | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 | * | |
| 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. | |
| 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 | 51 | 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 | 10 | 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 | 10 | 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 | 5 | 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 | 5 | 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 | 43 | if (!isDelimiterParsingDisabled() && value instanceof String) |
| 101 | { | |
| 102 | 35 | List list = PropertyConverter.split((String) value, |
| 103 | getListDelimiter()); | |
| 104 | 35 | value = list.size() > 1 ? list : list.get(0); |
| 105 | } | |
| 106 | ||
| 107 | 43 | return value; |
| 108 | } | |
| 109 | } |