Package com.helger.config.source
Class MultiConfigurationValueProvider
java.lang.Object
com.helger.config.source.MultiConfigurationValueProvider
- All Implemented Interfaces:
com.helger.base.clone.ICloneable<MultiConfigurationValueProvider>,IConfigurationValueProvider
public class MultiConfigurationValueProvider
extends Object
implements IConfigurationValueProvider, com.helger.base.clone.ICloneable<MultiConfigurationValueProvider>
An implementation of
IConfigurationValueProvider that supports multiple sources, ordered
by priority, descending.- Author:
- Philip Helger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final boolean -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor without any configuration source.MultiConfigurationValueProvider(IConfigurationSource... aSources) Constructor with an array of existing configuration sources.MultiConfigurationValueProvider(List<? extends IConfigurationSource> aSources) Constructor with a list of existing configuration sources. -
Method Summary
Modifier and TypeMethodDescriptionAdd a configuration source.addConfigurationSource(IConfigurationValueProvider aCVP, int nPriority) Add a configuration value provider and a priority.createForAllOccurrances(ClassLoader aClassLoader, String sPathName, Function<URL, IConfigurationSource> aLoader, boolean bCheckForFile) Load all classpath elements and files with the same name.createForClassPath(ClassLoader aClassLoader, String sClassPathElement, Function<URL, IConfigurationSource> aLoader) Load all classpath elements with the same name.voidScan through all added configuration sources and invoke the callback.getClone()Return a deep clone of thisMultiConfigurationValueProvider.final intgetConfigurationValue(String sKey) Get the configuration value with the provided key.final booleansetUseOnlyInitializedConfigSources(boolean bUseOnlyInitializedConfigSources) Enable or disable the usage of only initialized configuration sources.toString()
-
Field Details
-
DEFAULT_USE_ONLY_INTIIALIZED_CONFIG_SOURCES
public static final boolean DEFAULT_USE_ONLY_INTIIALIZED_CONFIG_SOURCES- See Also:
-
-
Constructor Details
-
MultiConfigurationValueProvider
public MultiConfigurationValueProvider()Default constructor without any configuration source. -
MultiConfigurationValueProvider
Constructor with a list of existing configuration sources.- Parameters:
aSources- The list of existing sources to be added. The order will be maintained. May benullbut may not containnullvalues.- See Also:
-
MultiConfigurationValueProvider
Constructor with an array of existing configuration sources.- Parameters:
aSources- The array of existing sources to be added. The order will be maintained. May benullbut may not containnullvalues.- See Also:
-
-
Method Details
-
isUseOnlyInitializedConfigSources
public final boolean isUseOnlyInitializedConfigSources()- Returns:
trueif this multi value provider accepts only configuration sources that were initialized and are usable. The default is true.- See Also:
-
setUseOnlyInitializedConfigSources
@Nonnull public final MultiConfigurationValueProvider setUseOnlyInitializedConfigSources(boolean bUseOnlyInitializedConfigSources) Enable or disable the usage of only initialized configuration sources.- Parameters:
bUseOnlyInitializedConfigSources-trueto only allow the usage of initialized configuration sources.- Returns:
- this for chaining
-
addConfigurationSource
@Nonnull public final MultiConfigurationValueProvider addConfigurationSource(@Nonnull IConfigurationSource aSource) Add a configuration source. The priority of the configuration source is used.- Parameters:
aSource- The source to be added. May not benull.- Returns:
- this for chaining
-
addConfigurationSource
@Nonnull public final MultiConfigurationValueProvider addConfigurationSource(@Nullable IConfigurationValueProvider aCVP, int nPriority) Add a configuration value provider and a priority. The passed priority overwrites the priority contained in the value provider. This method sorts the internal list of sources based on the registered priorities.- Parameters:
aCVP- The configuration value provider to be added. May benull.nPriority- The priority to be used.- Returns:
- this for chaining
-
getConfigurationSourceCount
@Nonnegative public final int getConfigurationSourceCount()- Returns:
- The number of contained configuration sources. Always ≥ 0.
-
getConfigurationValue
Description copied from interface:IConfigurationValueProviderGet the configuration value with the provided key.- Specified by:
getConfigurationValuein interfaceIConfigurationValueProvider- Parameters:
sKey- The key to be retrieved. May neither benullnor empty.- Returns:
nullif no such value is available.
-
forEachConfigurationValueProvider
public void forEachConfigurationValueProvider(@Nonnull IConfigurationValueProviderWithPriorityCallback aCallback) Scan through all added configuration sources and invoke the callback.- Parameters:
aCallback- The callback to be invoked. May not benull.
-
getClone
Return a deep clone of thisMultiConfigurationValueProvider. If the containedIConfigurationValueProviderimplementsICloneableit is cloned as well.- Specified by:
getClonein interfacecom.helger.base.clone.ICloneable<MultiConfigurationValueProvider>
-
toString
-
createForClassPath
@Nullable public static MultiConfigurationValueProvider createForClassPath(@Nonnull ClassLoader aClassLoader, @Nonnull String sClassPathElement, @Nonnull Function<URL, IConfigurationSource> aLoader) Load all classpath elements with the same name.- Parameters:
aClassLoader- The class loader to be used. May not benull.sClassPathElement- The name of the class path element(s) to load. May not benull.aLoader- The loader that converts all matching URLs toIConfigurationSourceobjects. With this implementation you can differentiate the type of the content.- Returns:
- May be
nullif no resource was found.
-
createForAllOccurrances
@Nullable public static MultiConfigurationValueProvider createForAllOccurrances(@Nonnull ClassLoader aClassLoader, @Nonnull String sPathName, @Nonnull Function<URL, IConfigurationSource> aLoader, boolean bCheckForFile) Load all classpath elements and files with the same name.- Parameters:
aClassLoader- The class loader to be used. May not benull.sPathName- The name of the class path element(s) to load. May not benull.aLoader- The loader that converts all matching URLs toIConfigurationSourceobjects. With this implementation you can differentiate the type of the content.bCheckForFile-trueto also check for a file with the same name.- Returns:
- May be
nullif no resource was found.
-