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 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

      public MultiConfigurationValueProvider(@Nullable List<? extends IConfigurationSource> aSources)
      Constructor with a list of existing configuration sources.
      Parameters:
      aSources - The list of existing sources to be added. The order will be maintained. May be null but may not contain null values.
      See Also:
    • MultiConfigurationValueProvider

      public MultiConfigurationValueProvider(@Nullable IConfigurationSource... aSources)
      Constructor with an array of existing configuration sources.
      Parameters:
      aSources - The array of existing sources to be added. The order will be maintained. May be null but may not contain null values.
      See Also:
  • Method Details

    • isUseOnlyInitializedConfigSources

      public final boolean isUseOnlyInitializedConfigSources()
      Returns:
      true if 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 - true to 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 be null.
      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 be null.
      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

      @Nullable public ConfiguredValue getConfigurationValue(@Nonnull @Nonempty String sKey)
      Description copied from interface: IConfigurationValueProvider
      Get the configuration value with the provided key.
      Specified by:
      getConfigurationValue in interface IConfigurationValueProvider
      Parameters:
      sKey - The key to be retrieved. May neither be null nor empty.
      Returns:
      null if 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 be null.
    • getClone

      @Nonnull @ReturnsMutableCopy public MultiConfigurationValueProvider getClone()
      Return a deep clone of this MultiConfigurationValueProvider. If the contained IConfigurationValueProvider implements ICloneable it is cloned as well.
      Specified by:
      getClone in interface com.helger.base.clone.ICloneable<MultiConfigurationValueProvider>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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 be null.
      sClassPathElement - The name of the class path element(s) to load. May not be null.
      aLoader - The loader that converts all matching URLs to IConfigurationSource objects. With this implementation you can differentiate the type of the content.
      Returns:
      May be null if 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 be null.
      sPathName - The name of the class path element(s) to load. May not be null.
      aLoader - The loader that converts all matching URLs to IConfigurationSource objects. With this implementation you can differentiate the type of the content.
      bCheckForFile - true to also check for a file with the same name.
      Returns:
      May be null if no resource was found.