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.configuration2.builder;
18  
19  import java.util.Map;
20  
21  import org.apache.commons.configuration2.ConfigurationConsumer;
22  import org.apache.commons.configuration2.PropertiesConfiguration.IOFactory;
23  import org.apache.commons.configuration2.PropertiesConfigurationLayout;
24  import org.apache.commons.configuration2.ex.ConfigurationException;
25  
26  /**
27   * <p>
28   * A specialized parameter class for configuring {@code PropertiesConfiguration} instances.
29   * </p>
30   * <p>
31   * This class allows setting of some properties specific to properties configuration, e.g. the layout object. By
32   * inheriting from {@link FileBasedBuilderParametersImpl}, basic properties and properties related to file-based
33   * configurations are available, too.
34   * </p>
35   * <p>
36   * This class is not thread-safe. It is intended that an instance is constructed and initialized by a single thread
37   * during configuration of a {@code ConfigurationBuilder}.
38   * </p>
39   *
40   * @since 2.0
41   */
42  public class PropertiesBuilderParametersImpl extends FileBasedBuilderParametersImpl implements PropertiesBuilderProperties<PropertiesBuilderParametersImpl> {
43      /** The key for the include listener property. */
44      private static final String PROP_INCLUDE_LISTENER = "includeListener";
45  
46      /** The key for the includes allowed property. */
47      private static final String PROP_INCLUDES_ALLOWED = "includesAllowed";
48  
49      /** The key for the layout property. */
50      private static final String PROP_LAYOUT = "layout";
51  
52      /** The key for the IO factory property. */
53      private static final String PROP_IO_FACTORY = "IOFactory";
54  
55      @Override
56      public PropertiesBuilderParametersImpl setIncludeListener(final ConfigurationConsumer<ConfigurationException> includeListener) {
57          storeProperty(PROP_INCLUDE_LISTENER, includeListener);
58          return this;
59      }
60  
61      @Override
62      public PropertiesBuilderParametersImpl setIncludesAllowed(final boolean f) {
63          storeProperty(PROP_INCLUDES_ALLOWED, Boolean.valueOf(f));
64          return this;
65      }
66  
67      /**
68       * {@inheritDoc} This implementation takes some more properties into account that are defined in this class.
69       */
70      @Override
71      public void inheritFrom(final Map<String, ?> source) {
72          super.inheritFrom(source);
73          copyPropertiesFrom(source, PROP_INCLUDES_ALLOWED, PROP_INCLUDE_LISTENER, PROP_IO_FACTORY);
74      }
75  
76      @Override
77      public PropertiesBuilderParametersImpl setLayout(final PropertiesConfigurationLayout layout) {
78          storeProperty(PROP_LAYOUT, layout);
79          return this;
80      }
81  
82      @Override
83      public PropertiesBuilderParametersImpl setIOFactory(final IOFactory factory) {
84          storeProperty(PROP_IO_FACTORY, factory);
85          return this;
86      }
87  }