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
44 /** The key for the include listener property. */
45 private static final String PROP_INCLUDE_LISTENER = "includeListener";
46
47 /** The key for the includes allowed property. */
48 private static final String PROP_INCLUDES_ALLOWED = "includesAllowed";
49
50 /** The key for the layout property. */
51 private static final String PROP_LAYOUT = "layout";
52
53 /** The key for the IO factory property. */
54 private static final String PROP_IO_FACTORY = "IOFactory";
55
56 /**
57 * Constructs a new instance.
58 */
59 public PropertiesBuilderParametersImpl() {
60 // empty
61 }
62
63 /**
64 * {@inheritDoc} This implementation takes some more properties into account that are defined in this class.
65 */
66 @Override
67 public void inheritFrom(final Map<String, ?> source) {
68 super.inheritFrom(source);
69 copyPropertiesFrom(source, PROP_INCLUDES_ALLOWED, PROP_INCLUDE_LISTENER, PROP_IO_FACTORY);
70 }
71
72 @Override
73 public PropertiesBuilderParametersImpl setIncludeListener(final ConfigurationConsumer<ConfigurationException> includeListener) {
74 storeProperty(PROP_INCLUDE_LISTENER, includeListener);
75 return this;
76 }
77
78 @Override
79 public PropertiesBuilderParametersImpl setIncludesAllowed(final boolean f) {
80 storeProperty(PROP_INCLUDES_ALLOWED, Boolean.valueOf(f));
81 return this;
82 }
83
84 @Override
85 public PropertiesBuilderParametersImpl setIOFactory(final IOFactory factory) {
86 storeProperty(PROP_IO_FACTORY, factory);
87 return this;
88 }
89
90 @Override
91 public PropertiesBuilderParametersImpl setLayout(final PropertiesConfigurationLayout layout) {
92 storeProperty(PROP_LAYOUT, layout);
93 return this;
94 }
95 }