View Javadoc

    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 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  }