Class DefaultConfigSource

java.lang.Object
com.tccc.kos.commons.core.service.config.DefaultConfigSource
All Implemented Interfaces:
ConfigSource

public class DefaultConfigSource extends Object implements ConfigSource
ConfigSource that provides a sorted stack of sources. This is typically used to construct a stack of default values that come from various sources. This supports adding / removing sources as well as loading xml files as sources.
Version:
2022-05-23
  • Method Details

    • loadXmlConfigSource

      public void loadXmlConfigSource(String name, int rank, String file, ResourceLoader loader)
      Load an xml file as a ConfigSource and add the source to the stack with the specified name and rank.
      Parameters:
      name - name of the source
      rank - rank of the source
      file - the xml file to load
      loader - optional resource loader to use if FileResourceLoader isn't sufficient
    • loadXmlConfigSource

      public void loadXmlConfigSource(String name, int rank, String file, ResourceLoader loader, String basePath)
      Load an xml file as a ConfigSource and add the source to the stack with the specified name and rank.
      Parameters:
      name - name of the source
      rank - rank of the source
      file - the xml file to load
      loader - optional resource loader to use if FileResourceLoader isn't sufficient
      basePath - the base path to apply to all handle paths
    • addConfigSource

      public void addConfigSource(ConfigSource source)
      Add a config source.
      Parameters:
      source - the source to add
    • removeConfigSource

      public ConfigSource removeConfigSource(String name)
      Remove a config source by name.
      Parameters:
      name - name of the source to remove
    • getRank

      public int getRank()
      Description copied from interface: ConfigSource
      Returns the rank of the source, which is used to order sources. Sources with higher ranks override sources with lower ranks.
      Specified by:
      getRank in interface ConfigSource
    • gatherConfigPaths

      public void gatherConfigPaths(Set<String> paths)
      Description copied from interface: ConfigSource
      Put all available config bean handle paths into the supplied set.
      Specified by:
      gatherConfigPaths in interface ConfigSource
    • gatherConfigForPath

      public void gatherConfigForPath(String path, Map<String,String> config)
      Description copied from interface: ConfigSource
      Put all configuration data for the specified handle path into the supplied map. The keys in the map are bean attribute names in dotted notation, and the values are the corresponding values for the attributes.
      Specified by:
      gatherConfigForPath in interface ConfigSource
      Parameters:
      path - the handle path to return data for
      config - map to hold the resulting config data
    • getConfigValue

      public void getConfigValue(String path, String attr, ConfigValue value)
      Description copied from interface: ConfigSource
      Populate the specified value bean with the effective value of the specified attribute from this source.
      Specified by:
      getConfigValue in interface ConfigSource
      Parameters:
      path - the handle path to return data for
      attr - the attribute of the config to return
      value - the value to populate
    • gatherOptionsPaths

      public void gatherOptionsPaths(Set<String> paths)
      Description copied from interface: ConfigSource
      Put all available option bean handle paths into the supplied set. Most sources don't support this so by default it does nothing.
      Specified by:
      gatherOptionsPaths in interface ConfigSource
    • gatherOptionsForPath

      public void gatherOptionsForPath(String path, Map<String,String> options)
      Description copied from interface: ConfigSource
      Put all option data for the specified handle path into the supplied map. The keys in the map are bean attribute names in dotted notation, and the values are the corresponding options for the attributes. Map, list and array bean attributes will contain * wildcards as all values in the map, list or array are assumed to be the same type. Most sources don't suppor this so by default it does nothing.
      Specified by:
      gatherOptionsForPath in interface ConfigSource
      Parameters:
      path - the handle path to return data for
      options - map to put the options into