Source code
Description: source: package: org.apache.commons.configuration2.builder, class: PropertiesBuilderParametersImpl

    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 *     https://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} instances.
    029 * </p>
    030 * <p>
    031 * This class allows setting of some properties specific to properties configuration, for example the layout object. By
    032 * inheriting from {@link FileBasedBuilderParametersImpl}, basic properties and properties related to file-based
    033 * configurations are available, too.
    034 * </p>
    035 * <p>
    036 * This class is not thread-safe. It is intended that an instance is constructed and initialized by a single thread
    037 * during configuration of a {@code ConfigurationBuilder}.
    038 * </p>
    039 *
    040 * @since 2.0
    041 */
    042public class PropertiesBuilderParametersImpl extends FileBasedBuilderParametersImpl implements PropertiesBuilderProperties<PropertiesBuilderParametersImpl> {
    043
    044    /** The key for the include listener property. */
    045    private static final String PROP_INCLUDE_LISTENER = "includeListener";
    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    /**
    057     * Constructs a new instance.
    058     */
    059    public PropertiesBuilderParametersImpl() {
    060        // empty
    061    }
    062
    063    /**
    064     * {@inheritDoc} This implementation takes some more properties into account that are defined in this class.
    065     */
    066    @Override
    067    public void inheritFrom(final Map<String, ?> source) {
    068        super.inheritFrom(source);
    069        copyPropertiesFrom(source, PROP_INCLUDES_ALLOWED, PROP_INCLUDE_LISTENER, PROP_IO_FACTORY);
    070    }
    071
    072    @Override
    073    public PropertiesBuilderParametersImpl setIncludeListener(final ConfigurationConsumer<ConfigurationException> includeListener) {
    074        storeProperty(PROP_INCLUDE_LISTENER, includeListener);
    075        return this;
    076    }
    077
    078    @Override
    079    public PropertiesBuilderParametersImpl setIncludesAllowed(final boolean f) {
    080        storeProperty(PROP_INCLUDES_ALLOWED, Boolean.valueOf(f));
    081        return this;
    082    }
    083
    084    @Override
    085    public PropertiesBuilderParametersImpl setIOFactory(final IOFactory factory) {
    086        storeProperty(PROP_IO_FACTORY, factory);
    087        return this;
    088    }
    089
    090    @Override
    091    public PropertiesBuilderParametersImpl setLayout(final PropertiesConfigurationLayout layout) {
    092        storeProperty(PROP_LAYOUT, layout);
    093        return this;
    094    }
    095}