001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.configuration2.builder;
018
019import java.util.Map;
020
021import org.apache.commons.configuration2.ConfigurationConsumer;
022import org.apache.commons.configuration2.PropertiesConfiguration.IOFactory;
023import org.apache.commons.configuration2.PropertiesConfigurationLayout;
024import org.apache.commons.configuration2.ex.ConfigurationException;
025
026/**
027 * <p>
028 * A specialized parameter class for configuring {@code PropertiesConfiguration}
029 * instances.
030 * </p>
031 * <p>
032 * This class allows setting of some properties specific to properties
033 * configuration, e.g. the layout object. By inheriting from
034 * {@link FileBasedBuilderParametersImpl}, basic properties and properties
035 * related to file-based configurations are available, too.
036 * </p>
037 * <p>
038 * This class is not thread-safe. It is intended that an instance is constructed
039 * and initialized by a single thread during configuration of a
040 * {@code ConfigurationBuilder}.
041 * </p>
042 *
043 * @since 2.0
044 */
045public class PropertiesBuilderParametersImpl extends
046        FileBasedBuilderParametersImpl implements
047        PropertiesBuilderProperties<PropertiesBuilderParametersImpl>
048{
049    /** The key for the include listener property. */
050    private static final String PROP_INCLUDE_LISTENER = "includeListener";
051
052    /** The key for the includes allowed property. */
053    private static final String PROP_INCLUDES_ALLOWED = "includesAllowed";
054
055    /** The key for the layout property. */
056    private static final String PROP_LAYOUT = "layout";
057
058    /** The key for the IO factory property. */
059    private static final String PROP_IO_FACTORY = "IOFactory";
060
061    @Override
062    public PropertiesBuilderParametersImpl setIncludeListener(
063            final ConfigurationConsumer<ConfigurationException> includeListener)
064    {
065        storeProperty(PROP_INCLUDE_LISTENER, includeListener);
066        return this;
067    }
068
069    @Override
070    public PropertiesBuilderParametersImpl setIncludesAllowed(final boolean f)
071    {
072        storeProperty(PROP_INCLUDES_ALLOWED, Boolean.valueOf(f));
073        return this;
074    }
075
076    /**
077     * {@inheritDoc} This implementation takes some more properties into account
078     * that are defined in this class.
079     */
080    @Override
081    public void inheritFrom(final Map<String, ?> source)
082    {
083        super.inheritFrom(source);
084        copyPropertiesFrom(source, PROP_INCLUDES_ALLOWED, PROP_INCLUDE_LISTENER, PROP_IO_FACTORY);
085    }
086
087    @Override
088    public PropertiesBuilderParametersImpl setLayout(
089            final PropertiesConfigurationLayout layout)
090    {
091        storeProperty(PROP_LAYOUT, layout);
092        return this;
093    }
094
095    @Override
096    public PropertiesBuilderParametersImpl setIOFactory(final IOFactory factory)
097    {
098        storeProperty(PROP_IO_FACTORY, factory);
099        return this;
100    }
101}