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     * Registers a {@code DefaultParametersHandler} for child configuration sources. With this method an arbitrary number of
044     * handler objects can be set. When creating builders for child configuration sources their parameters are initialized
045     * by invoking all matching {@code DefaultParametersHandler}s on them. So, basically the same mechanism is used for the
046     * initialization of parameters for child configuration sources as for normal parameter objects.
047     *
048     * @param <D> the type of the handler to be registered
049     * @param paramClass the parameter class supported by the handler
050     * @param handler the {@code DefaultParametersHandler} to be registered
051     * @return a reference to this object for method chaining
052     * @see DefaultParametersManager#registerDefaultsHandler(Class, DefaultParametersHandler)
053     */
054    <D> T registerChildDefaultsHandler(Class<D> paramClass, DefaultParametersHandler<? super D> handler);
055
056    /**
057     * Registers a {@code DefaultParametersHandler} for child configuration sources derived from the given start class. This
058     * method works like the overloaded variant, but limits the application of the defaults handler to specific child
059     * configuration sources.
060     *
061     * @param <D> the type of the handler to be registered
062     * @param paramClass the parameter class supported by the handler
063     * @param handler the {@code DefaultParametersHandler} to be registered
064     * @param startClass an optional start class in the hierarchy of parameter objects for which this handler should be
065     *        applied
066     * @return a reference to this object for method chaining
067     * @see DefaultParametersManager#registerDefaultsHandler(Class, DefaultParametersHandler, Class)
068     */
069    <D> T registerChildDefaultsHandler(Class<D> paramClass, DefaultParametersHandler<? super D> handler, Class<?> startClass);
070
071    /**
072     * Registers the given {@code ConfigurationBuilderProvider} for the specified tag name. This means that whenever this
073     * tag is encountered in a configuration definition file, the corresponding builder provider is invoked.
074     *
075     * @param tagName the name of the tag (must not be <b>null</b>)
076     * @param provider the {@code ConfigurationBuilderProvider} (must not be <b>null</b>)
077     * @return a reference to this object for method chaining
078     * @throws IllegalArgumentException if a required parameter is missing
079     */
080    T registerProvider(String tagName, ConfigurationBuilderProvider provider);
081
082    /**
083     * Sets the base path for this combined configuration builder. Normally it it not necessary to set the base path
084     * explicitly. Per default, relative file names of configuration sources are resolved based on the location of the
085     * definition file. If this is not desired or if the definition configuration is loaded by a different means, the base
086     * path for relative file names can be specified using this method.
087     *
088     * @param path the base path for resolving relative file names
089     * @return a reference to this object for method chaining
090     */
091    T setBasePath(String path);
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     * Sets the {@code ConfigurationBuilder} for the definition configuration. This is the configuration which contains the
110     * configuration sources that form the combined configuration.
111     *
112     * @param builder the definition {@code ConfigurationBuilder}
113     * @return a reference to this object for method chaining
114     */
115    T setDefinitionBuilder(ConfigurationBuilder<? extends HierarchicalConfiguration<?>> builder);
116
117    /**
118     * Sets the parameters object for the definition configuration builder. This property is evaluated only if the
119     * definition configuration builder is not set explicitly (using the {@link #setDefinitionBuilder(ConfigurationBuilder)}
120     * method). In this case, a builder for an XML configuration is created and configured with this parameters object.
121     *
122     * @param params the parameters object for the definition configuration builder
123     * @return a reference to this object for method chaining
124     */
125    T setDefinitionBuilderParameters(BuilderParameters params);
126
127    /**
128     * Sets a flag whether the child configurations created by a {@code CombinedConfigurationBuilder} should inherit the
129     * settings defined for the builder. This is typically useful because for configurations coming from homogeneous sources
130     * often similar conventions are used. Therefore, this flag is <b>true</b> per default.
131     *
132     * @param f the flag whether settings should be inherited by child configurations
133     * @return a reference to this object for method chaining
134     */
135    T setInheritSettings(boolean f);
136}