PropertiesBuilderParametersImpl.java

  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.configuration2.builder;

  18. import java.util.Map;

  19. import org.apache.commons.configuration2.ConfigurationConsumer;
  20. import org.apache.commons.configuration2.PropertiesConfiguration.IOFactory;
  21. import org.apache.commons.configuration2.PropertiesConfigurationLayout;
  22. import org.apache.commons.configuration2.ex.ConfigurationException;

  23. /**
  24.  * <p>
  25.  * A specialized parameter class for configuring {@code PropertiesConfiguration} instances.
  26.  * </p>
  27.  * <p>
  28.  * This class allows setting of some properties specific to properties configuration, for example the layout object. By
  29.  * inheriting from {@link FileBasedBuilderParametersImpl}, basic properties and properties related to file-based
  30.  * configurations are available, too.
  31.  * </p>
  32.  * <p>
  33.  * This class is not thread-safe. It is intended that an instance is constructed and initialized by a single thread
  34.  * during configuration of a {@code ConfigurationBuilder}.
  35.  * </p>
  36.  *
  37.  * @since 2.0
  38.  */
  39. public class PropertiesBuilderParametersImpl extends FileBasedBuilderParametersImpl implements PropertiesBuilderProperties<PropertiesBuilderParametersImpl> {
  40.     /** The key for the include listener property. */
  41.     private static final String PROP_INCLUDE_LISTENER = "includeListener";

  42.     /** The key for the includes allowed property. */
  43.     private static final String PROP_INCLUDES_ALLOWED = "includesAllowed";

  44.     /** The key for the layout property. */
  45.     private static final String PROP_LAYOUT = "layout";

  46.     /** The key for the IO factory property. */
  47.     private static final String PROP_IO_FACTORY = "IOFactory";

  48.     /**
  49.      * {@inheritDoc} This implementation takes some more properties into account that are defined in this class.
  50.      */
  51.     @Override
  52.     public void inheritFrom(final Map<String, ?> source) {
  53.         super.inheritFrom(source);
  54.         copyPropertiesFrom(source, PROP_INCLUDES_ALLOWED, PROP_INCLUDE_LISTENER, PROP_IO_FACTORY);
  55.     }

  56.     @Override
  57.     public PropertiesBuilderParametersImpl setIncludeListener(final ConfigurationConsumer<ConfigurationException> includeListener) {
  58.         storeProperty(PROP_INCLUDE_LISTENER, includeListener);
  59.         return this;
  60.     }

  61.     @Override
  62.     public PropertiesBuilderParametersImpl setIncludesAllowed(final boolean f) {
  63.         storeProperty(PROP_INCLUDES_ALLOWED, Boolean.valueOf(f));
  64.         return this;
  65.     }

  66.     @Override
  67.     public PropertiesBuilderParametersImpl setIOFactory(final IOFactory factory) {
  68.         storeProperty(PROP_IO_FACTORY, factory);
  69.         return this;
  70.     }

  71.     @Override
  72.     public PropertiesBuilderParametersImpl setLayout(final PropertiesConfigurationLayout layout) {
  73.         storeProperty(PROP_LAYOUT, layout);
  74.         return this;
  75.     }
  76. }