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.Collection;
020import java.util.Map;
021
022import org.apache.commons.configuration2.ConfigurationDecoder;
023import org.apache.commons.configuration2.beanutils.BeanHelper;
024import org.apache.commons.configuration2.convert.ConversionHandler;
025import org.apache.commons.configuration2.convert.ListDelimiterHandler;
026import org.apache.commons.configuration2.interpol.ConfigurationInterpolator;
027import org.apache.commons.configuration2.interpol.Lookup;
028import org.apache.commons.configuration2.io.ConfigurationLogger;
029import org.apache.commons.configuration2.sync.Synchronizer;
030
031/**
032 * <p>
033 * Definition of a properties interface for basic parameters which are supported by all {@link ConfigurationBuilder}
034 * implementations derived from {@link BasicConfigurationBuilder}.
035 * </p>
036 * <p>
037 * This interface defines the single properties supported by a parameters object. Properties can be set using a fluent
038 * API making it convenient for client code to specify concrete property values in a single statement.
039 * </p>
040 * <p>
041 * <strong>Important note:</strong> This interface is not intended to be implemented by client code! It defines a set of
042 * available properties and may be extended even in minor releases.
043 * </p>
044 *
045 * @since 2.0
046 * @param <T> the type of the result of all set methods for method chaining
047 */
048public interface BasicBuilderProperties<T> {
049    /**
050     * Sets a {@code BeanHelper} object to be used by the configuration builder. The {@code BeanHelper} is used to create
051     * the managed configuration instance dynamically. It is not a property of the configuration as most other properties
052     * defined by this interface. By setting an alternative {@code BeanHelper} the process of creating configuration
053     * instances via reflection can be adapted. (Some specialized configuration builder implementations also use a
054     * {@code BeanHelper} to create complex helper objects during construction of their result object.
055     * {@code CombinedConfigurationBuilder} for instance supports a complex configuration definition format which may
056     * contain several specialized bean declarations.) If no specific {@code BeanHelper} is set, the builder uses the
057     * default instance.
058     *
059     * @param beanHelper the {@code BeanHelper} to be used by the builder
060     * @return a reference to this object for method chaining
061     */
062    T setBeanHelper(BeanHelper beanHelper);
063
064    /**
065     * Sets the {@code ConfigurationDecoder} object for this configuration. This object is called when encoded properties
066     * are queried using the {@code getEncodedString()} method.
067     *
068     * @param decoder the {@code ConfigurationDecoder} to be used
069     * @return a reference to this object for method chaining
070     */
071    T setConfigurationDecoder(ConfigurationDecoder decoder);
072
073    /**
074     * Sets the {@code ConversionHandler} object for this configuration. This object is responsible for all data type
075     * conversions required for accessing configuration properties in a specific target type. If this property is not set, a
076     * default {@code ConversionHandler} is used.
077     *
078     * @param handler the {@code ConversionHandler} to be used
079     * @return a reference to this object for method chaining
080     */
081    T setConversionHandler(ConversionHandler handler);
082
083    /**
084     * Adds additional default {@code Lookup} objects (i.e. lookups which are not associated with a specific prefix) to this
085     * configuration object. Note: This method only takes effect if no {@code ConfigurationInterpolator} is set using the
086     * {@link #setInterpolator(ConfigurationInterpolator)} method.
087     *
088     * @param lookups a collection with {@code Lookup} objects to be added as default lookups at the configuration's
089     *        {@code ConfigurationInterpolator}
090     * @return a reference to this object for method chaining
091     * @see ConfigurationInterpolator#addDefaultLookups(Collection)
092     */
093    T setDefaultLookups(Collection<? extends Lookup> lookups);
094
095    /**
096     * Sets the {@code ConfigurationInterpolator} to be used for this configuration. Using this method a custom
097     * {@code ConfigurationInterpolator} can be set which can be freely configured. Alternatively, it is possible to add
098     * custom {@code Lookup} objects using other methods provided by this interface.
099     *
100     * @param ci the {@code ConfigurationInterpolator} for this configuration
101     * @return a reference to this object for method chaining
102     */
103    T setInterpolator(ConfigurationInterpolator ci);
104
105    /**
106     * Sets the value of the <em>listDelimiterHandler</em> property. This property defines the object responsible for
107     * dealing with list delimiter and escaping characters. Note:
108     * {@link org.apache.commons.configuration2.AbstractConfiguration AbstractConfiguration} does not allow setting this
109     * property to <b>null</b>. If the default {@code ListDelimiterHandler} is to be used, do not call this method.
110     *
111     * @param handler the {@code ListDelimiterHandler}
112     * @return a reference to this object for method chaining
113     */
114    T setListDelimiterHandler(ListDelimiterHandler handler);
115
116    /**
117     * Sets the <em>logger</em> property. With this property a concrete {@code ConfigurationLogger} object can be set for
118     * the configuration. Thus logging behavior can be controlled.
119     *
120     * @param log the {@code Log} for the configuration produced by this builder
121     * @return a reference to this object for method chaining
122     */
123    T setLogger(ConfigurationLogger log);
124
125    /**
126     * Sets the parent {@code ConfigurationInterpolator} for this configuration's {@code ConfigurationInterpolator}. Setting
127     * a parent {@code ConfigurationInterpolator} can be used for defining a default behavior for variables which cannot be
128     * resolved.
129     *
130     * @param parent the new parent {@code ConfigurationInterpolator}
131     * @return a reference to this object for method chaining
132     * @see ConfigurationInterpolator#setParentInterpolator(ConfigurationInterpolator)
133     */
134    T setParentInterpolator(ConfigurationInterpolator parent);
135
136    /**
137     * Sets additional {@code Lookup} objects for specific prefixes for this configuration object. All {@code Lookup}
138     * objects contained in the given map are added to the configuration's {@code ConfigurationInterpolator}. Note: This
139     * method only takes effect if no {@code ConfigurationInterpolator} is set using the
140     * {@link #setInterpolator(ConfigurationInterpolator)} method.
141     *
142     * @param lookups a map with {@code Lookup} objects and their associated prefixes
143     * @return a reference to this object for method chaining
144     * @see ConfigurationInterpolator#registerLookups(Map)
145     */
146    T setPrefixLookups(Map<String, ? extends Lookup> lookups);
147
148    /**
149     * Sets the {@code Synchronizer} object for this configuration. This object is used to protect this configuration
150     * instance against concurrent access. The concrete {@code Synchronizer} implementation used determines whether a
151     * configuration instance is thread-safe or not.
152     *
153     * @param sync the {@code Synchronizer} to be used (a value of <b>null</b> means that a default {@code Synchronizer} is
154     *        used)
155     * @return a reference to this object for method chaining
156     */
157    T setSynchronizer(Synchronizer sync);
158
159    /**
160     * Sets the value of the <em>throwExceptionOnMissing</em> property. This property controls the configuration's behavior
161     * if missing properties are queried: a value of <b>true</b> causes the configuration to throw an exception, for a value
162     * of <b>false</b> it will return <b>null</b> values. (Note: Methods returning a primitive data type will always throw
163     * an exception if the property is not defined.)
164     *
165     * @param b the value of the property
166     * @return a reference to this object for method chaining
167     */
168    T setThrowExceptionOnMissing(boolean b);
169}