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    *     https://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, for example 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      /**
56       * Constructs a new instance.
57       */
58      public PropertiesBuilderParametersImpl() {
59          // empty
60      }
61  
62      /**
63       * {@inheritDoc} This implementation takes some more properties into account that are defined in this class.
64       */
65      @Override
66      public void inheritFrom(final Map<String, ?> source) {
67          super.inheritFrom(source);
68          copyPropertiesFrom(source, PROP_INCLUDES_ALLOWED, PROP_INCLUDE_LISTENER, PROP_IO_FACTORY);
69      }
70  
71      @Override
72      public PropertiesBuilderParametersImpl setIncludeListener(final ConfigurationConsumer<ConfigurationException> includeListener) {
73          storeProperty(PROP_INCLUDE_LISTENER, includeListener);
74          return this;
75      }
76  
77      @Override
78      public PropertiesBuilderParametersImpl setIncludesAllowed(final boolean f) {
79          storeProperty(PROP_INCLUDES_ALLOWED, Boolean.valueOf(f));
80          return this;
81      }
82  
83      @Override
84      public PropertiesBuilderParametersImpl setIOFactory(final IOFactory factory) {
85          storeProperty(PROP_IO_FACTORY, factory);
86          return this;
87      }
88  
89      @Override
90      public PropertiesBuilderParametersImpl setLayout(final PropertiesConfigurationLayout layout) {
91          storeProperty(PROP_LAYOUT, layout);
92          return this;
93      }
94  }