    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.combined;
    018
    019import org.apache.commons.configuration2.HierarchicalConfiguration;
    020import org.apache.commons.configuration2.builder.BuilderParameters;
    021import org.apache.commons.configuration2.builder.ConfigurationBuilder;
    022import org.apache.commons.configuration2.builder.DefaultParametersHandler;
    023import org.apache.commons.configuration2.builder.DefaultParametersManager;
    024
    025/**
    026 * <p>
    027 * Definition of a properties interface for the parameters of a combined configuration builder.
    028 * </p>
    029 * <p>
    030 * This interface defines a number of properties for adapting the construction of a combined configuration based on a
    031 * definition configuration. Properties can be set in a fluent style.
    032 * </p>
    033 * <p>
    034 * <strong>Important note:</strong> This interface is not intended to be implemented by client code! It defines a set of
    035 * available properties and may be extended even in minor releases.
    036 * </p>
    037 *
    038 * @since 2.0
    039 * @param <T> the return type of all methods for allowing method chaining
    040 */
    041public interface CombinedBuilderProperties<T> {
    042    /**
    043     * Sets a flag whether the child configurations created by a {@code CombinedConfigurationBuilder} should inherit the
    044     * settings defined for the builder. This is typically useful because for configurations coming from homogeneous sources
    045     * often similar conventions are used. Therefore, this flag is <b>true</b> per default.
    046     *
    047     * @param f the flag whether settings should be inherited by child configurations
    048     * @return a reference to this object for method chaining
    049     */
    050    T setInheritSettings(boolean f);
    051
    052    /**
    053     * Sets the {@code ConfigurationBuilder} for the definition configuration. This is the configuration which contains the
    054     * configuration sources that form the combined configuration.
    055     *
    056     * @param builder the definition {@code ConfigurationBuilder}
    057     * @return a reference to this object for method chaining
    058     */
    059    T setDefinitionBuilder(ConfigurationBuilder<? extends HierarchicalConfiguration<?>> builder);
    060
    061    /**
    062     * Registers the given {@code ConfigurationBuilderProvider} for the specified tag name. This means that whenever this
    063     * tag is encountered in a configuration definition file, the corresponding builder provider is invoked.
    064     *
    065     * @param tagName the name of the tag (must not be <b>null</b>)
    066     * @param provider the {@code ConfigurationBuilderProvider} (must not be <b>null</b>)
    067     * @return a reference to this object for method chaining
    068     * @throws IllegalArgumentException if a required parameter is missing
    069     */
    070    T registerProvider(String tagName, ConfigurationBuilderProvider provider);
    071
    072    /**
    073     * Sets the base path for this combined configuration builder. Normally it it not necessary to set the base path
    074     * explicitly. Per default, relative file names of configuration sources are resolved based on the location of the
    075     * definition file. If this is not desired or if the definition configuration is loaded by a different means, the base
    076     * path for relative file names can be specified using this method.
    077     *
    078     * @param path the base path for resolving relative file names
    079     * @return a reference to this object for method chaining
    080     */
    081    T setBasePath(String path);
    082
    083    /**
    084     * Sets the parameters object for the definition configuration builder. This property is evaluated only if the
    085     * definition configuration builder is not set explicitly (using the {@link #setDefinitionBuilder(ConfigurationBuilder)}
    086     * method). In this case, a builder for an XML configuration is created and configured with this parameters object.
    087     *
    088     * @param params the parameters object for the definition configuration builder
    089     * @return a reference to this object for method chaining
    090     */
    091    T setDefinitionBuilderParameters(BuilderParameters params);
    092
    093    /**
    094     * Sets a {@code DefaultParametersManager} object responsible for managing the default parameter handlers to be applied
    095     * on child configuration sources. When creating builders for child configuration sources their parameters are
    096     * initialized using this {@code DefaultParametersManager} instance. This way, meaningful defaults can be set. Note that
    097     * calling this method overrides all {@code DefaultParametersHandler} objects previously set by one of the
    098     * {@code registerChildDefaultsHandler()} methods! So either use this method if a pre-configured manager object is to be
    099     * set or call the {@code registerChildDefaultHandler()} methods with the handlers to be registered (in the latter case,
    100     * it is not necessary to set a {@code DefaultParametersManager} explicitly; a default one is created behind the
    101     * scenes).
    102     *
    103     * @param manager the {@code DefaultParametersManager}
    104     * @return a reference to this object for method chaining
    105     */
    106    T setChildDefaultParametersManager(DefaultParametersManager manager);
    107
    108    /**
    109     * Registers a {@code DefaultParametersHandler} for child configuration sources. With this method an arbitrary number of
    110     * handler objects can be set. When creating builders for child configuration sources their parameters are initialized
    111     * by invoking all matching {@code DefaultParametersHandler}s on them. So, basically the same mechanism is used for the
    112     * initialization of parameters for child configuration sources as for normal parameter objects.
    113     *
    114     * @param <D> the type of the handler to be registered
    115     * @param paramClass the parameter class supported by the handler
    116     * @param handler the {@code DefaultParametersHandler} to be registered
    117     * @return a reference to this object for method chaining
    118     * @see DefaultParametersManager#registerDefaultsHandler(Class, DefaultParametersHandler)
    119     */
    120    <D> T registerChildDefaultsHandler(Class<D> paramClass, DefaultParametersHandler<? super D> handler);
    121
    122    /**
    123     * Registers a {@code DefaultParametersHandler} for child configuration sources derived from the given start class. This
    124     * method works like the overloaded variant, but limits the application of the defaults handler to specific child
    125     * configuration sources.
    126     *
    127     * @param <D> the type of the handler to be registered
    128     * @param paramClass the parameter class supported by the handler
    129     * @param handler the {@code DefaultParametersHandler} to be registered
    130     * @param startClass an optional start class in the hierarchy of parameter objects for which this handler should be
    131     *        applied
    132     * @return a reference to this object for method chaining
    133     * @see DefaultParametersManager#registerDefaultsHandler(Class, DefaultParametersHandler, Class)
    134     */
    135    <D> T registerChildDefaultsHandler(Class<D> paramClass, DefaultParametersHandler<? super D> handler, Class<?> startClass);
    136}