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