    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.PropertiesConfiguration.IOFactory;
    022import org.apache.commons.configuration2.PropertiesConfigurationLayout;
    023
    024/**
    025 * <p>
    026 * A specialized parameter class for configuring {@code PropertiesConfiguration}
    027 * instances.
    028 * </p>
    029 * <p>
    030 * This class allows setting of some properties specific to properties
    031 * configuration, e.g. the layout object. By inheriting from
    032 * {@link FileBasedBuilderParametersImpl}, basic properties and properties
    033 * related to file-based configurations are available, too.
    034 * </p>
    035 * <p>
    036 * This class is not thread-safe. It is intended that an instance is constructed
    037 * and initialized by a single thread during configuration of a
    038 * {@code ConfigurationBuilder}.
    039 * </p>
    040 *
    041 * @since 2.0
    042 */
    043public class PropertiesBuilderParametersImpl extends
    044        FileBasedBuilderParametersImpl implements
    045        PropertiesBuilderProperties<PropertiesBuilderParametersImpl>
    046{
    047    /** The key for the includes allowed property. */
    048    private static final String PROP_INCLUDES_ALLOWED = "includesAllowed";
    049
    050    /** The key for the layout property. */
    051    private static final String PROP_LAYOUT = "layout";
    052
    053    /** The key for the IO factory property. */
    054    private static final String PROP_IO_FACTORY = "IOFactory";
    055
    056    @Override
    057    public PropertiesBuilderParametersImpl setIncludesAllowed(final boolean f)
    058    {
    059        storeProperty(PROP_INCLUDES_ALLOWED, Boolean.valueOf(f));
    060        return this;
    061    }
    062
    063    /**
    064     * {@inheritDoc} This implementation takes some more properties into account
    065     * that are defined in this class.
    066     */
    067    @Override
    068    public void inheritFrom(final Map<String, ?> source)
    069    {
    070        super.inheritFrom(source);
    071        copyPropertiesFrom(source, PROP_INCLUDES_ALLOWED, PROP_IO_FACTORY);
    072    }
    073
    074    @Override
    075    public PropertiesBuilderParametersImpl setLayout(
    076            final PropertiesConfigurationLayout layout)
    077    {
    078        storeProperty(PROP_LAYOUT, layout);
    079        return this;
    080    }
    081
    082    @Override
    083    public PropertiesBuilderParametersImpl setIOFactory(final IOFactory factory)
    084    {
    085        storeProperty(PROP_IO_FACTORY, factory);
    086        return this;
    087    }
    088}