Class ConfigBuilderSupport

java.lang.Object
io.helidon.config.ConfigBuilderSupport

public final class ConfigBuilderSupport extends Object
Methods used from generated code in builders when Prototype.Configured is used.
  • Method Details

    • validateProviderConfig

      public static void validateProviderConfig(Config config, String configKey, Option.Provider.Identity identity, Option.Provider.ConfigForm configForm)
      Validate the configured provider container before generated builder code maps or discovers provider values.
      Parameters:
      config - configuration located at the parent of the provider option
      configKey - configuration key of the provider option
      identity - configured provider identity
      configForm - configured provider outer container form
    • discoverServices

      public static <S extends NamedService, T extends ConfiguredProvider<S>> List<S> discoverServices(Config config, String configKey, Optional<ServiceRegistry> serviceRegistry, Class<T> providerType, Class<S> configType, boolean allFromRegistry, List<S> existingValues)
      Used to discover services from ServiceRegistry for builder options annotated with Option.Provider, if the blueprint is annotated with Prototype.RegistrySupport.
      Type Parameters:
      S - type of the service
      T - type of the service provider (contract)
      Parameters:
      config - configuration of the option
      configKey - configuration key associated with this option
      serviceRegistry - service registry instance
      providerType - type of the service provider (contract)
      configType - type of the configuration
      allFromRegistry - whether to use all services from the registry
      existingValues - existing values that was explicitly configured by the user
      Returns:
      instances from the user augmented with instances from the registry
    • discoverServices

      public static <S extends NamedService, T extends ConfiguredProvider<S>> List<S> discoverServices(Config config, String configKey, Optional<ServiceRegistry> serviceRegistry, Class<T> providerType, Class<S> configType, ConfigBuilderSupport.ProviderSettings settings, List<S> existingValues)
      Used by generated configured builders to discover services from ServiceRegistry after the configured provider identity and outer container form have been validated.
      Type Parameters:
      S - type of the service
      T - type of the service provider (contract)
      Parameters:
      config - configuration of the option
      configKey - configuration key associated with this option
      serviceRegistry - service registry instance
      providerType - type of the service provider (contract)
      configType - type of the configuration
      settings - provider identity, outer container form, and discovery settings
      existingValues - values explicitly configured by the user
      Returns:
      user instances augmented with instances from the registry
    • discoverService

      public static <S extends NamedService, T extends ConfiguredProvider<S>> Optional<S> discoverService(Config config, String configKey, Optional<ServiceRegistry> serviceRegistry, Class<T> providerType, Class<S> configType, boolean discoverServices, Optional<S> existingValue)
      Used to discover service from ServiceRegistry for builder options annotated with Option.Provider, if the blueprint is annotated with Prototype.RegistrySupport.
      Type Parameters:
      S - type of the service
      T - type of the service provider (contract)
      Parameters:
      config - configuration of the option
      configKey - configuration key associated with this option
      serviceRegistry - service registry instance
      providerType - type of the service provider (contract)
      configType - type of the configuration
      discoverServices - whether to discover services from registry
      existingValue - existing value that was explicitly configured by the user
      Returns:
      an instance, if available in the registry, or if provided by the user (user's value wins)
    • discoverService

      public static <S extends NamedService, T extends ConfiguredProvider<S>> Optional<S> discoverService(Config config, String configKey, Optional<ServiceRegistry> serviceRegistry, Class<T> providerType, Class<S> configType, ConfigBuilderSupport.ProviderSettings settings, Optional<S> existingValue)
      Used by generated configured builders to discover one service from ServiceRegistry, validating the configured provider identity and outer container form when configuration is consulted.
      Type Parameters:
      S - type of the service
      T - type of the service provider (contract)
      Parameters:
      config - configuration of the option
      configKey - configuration key associated with this option
      serviceRegistry - service registry instance
      providerType - type of the service provider (contract)
      configType - type of the configuration
      settings - provider identity, outer container form, and discovery settings
      existingValue - value explicitly configured by the user
      Returns:
      the configured or discovered service, if available
    • discoverServices

      public static <S extends NamedService, T extends ConfiguredProvider<S>> List<S> discoverServices(Config config, String configKey, Class<T> providerType, Class<S> configType, boolean allFromServiceLoader, List<S> existingInstances)
      Discover services from configuration. If already configured instances contain a service of the same type and name that would be added from configuration, the configuration would be ignored (e.g. the user must make a choice whether to configure, or set using an API).
      Type Parameters:
      S - type of the expected service
      T - type of the service provider (contract)
      Parameters:
      config - configuration located at the parent node of the service providers
      configKey - configuration key of the provider list (either a list node, or object, where each child is one service)
      providerType - type of the service provider interface, used to lookup from ServiceLoader
      configType - type of the configured service
      allFromServiceLoader - whether all services from service loader should be used, or only the ones with configured node
      existingInstances - already configured instances
      Returns:
      list of discovered services, ordered by Weight (highest weight is first in the list)
    • discoverServices

      public static <S extends NamedService, T extends ConfiguredProvider<S>> List<S> discoverServices(Config config, String configKey, Class<T> providerType, Class<S> configType, ConfigBuilderSupport.ProviderSettings settings, List<S> existingInstances)
      Used by generated configured builders to discover services using ServiceLoader after the configured provider identity and outer container form have been validated.
      Type Parameters:
      S - type of the expected service
      T - type of the service provider
      Parameters:
      config - configuration located at the parent node of the service providers
      configKey - configuration key of the provider collection
      providerType - service provider interface used for discovery
      configType - configured service type
      settings - provider identity, outer container form, and discovery settings
      existingInstances - explicitly configured instances
      Returns:
      discovered services ordered by weight
    • discoverService

      public static <S extends NamedService, T extends ConfiguredProvider<S>> Optional<S> discoverService(Config config, String configKey, Class<T> providerType, Class<S> configType, boolean allFromServiceLoader, Optional<S> existingValue)
      Discover service from configuration. If an instance is already configured using a builder, it will not be discovered from configuration (e.g. the user must make a choice whether to configure, or set using API).
      Type Parameters:
      S - type of the expected service
      T - type of the service provider (contract)
      Parameters:
      config - configuration located at the parent node of the service providers
      configKey - configuration key of the provider list (either a list node, or object, where each child is one service - this method requires * zero to one configured services)
      providerType - type of the service provider interface, used to lookup from ServiceLoader
      configType - type of the configured service
      allFromServiceLoader - whether all services from service loader should be used, or only the ones with configured node
      existingValue - value already configured, if the name is same as discovered from configuration
      Returns:
      the first service (ordered by Weight that is discovered, or empty optional if none is found
    • discoverService

      public static <S extends NamedService, T extends ConfiguredProvider<S>> Optional<S> discoverService(Config config, String configKey, Class<T> providerType, Class<S> configType, ConfigBuilderSupport.ProviderSettings settings, Optional<S> existingValue)
      Used by generated configured builders to discover one service using ServiceLoader, validating the configured provider identity and outer container form when configuration is consulted.
      Type Parameters:
      S - type of the expected service
      T - type of the service provider
      Parameters:
      config - configuration located at the parent node of the service provider
      configKey - configuration key of the provider collection
      providerType - service provider interface used for discovery
      configType - configured service type
      settings - provider identity, outer container form, and discovery settings
      existingValue - explicitly configured value
      Returns:
      the configured or discovered service, if available
    • resolveExpression

      public static String resolveExpression(Config config, String expression)
      Resolves an expression that may contain references to configuration values with possible default values. Nested expression are not allowed.
      Parameters:
      config - configuration instance
      expression - expression to resolve, such as
      ${service.scheme:http}://${service.host:localhost}:${service.port}
      , where service.scheme has a default value of http, service.host has a default value of localhost, and service.port does not have a default value, and will fail if not configured
      Returns:
      expression value with values retrieved from the config instance
    • resolveSetExpressions

      public static Set<String> resolveSetExpressions(Config config, Collection<String> expressions)
      Resolve expressions from a set of values. This is mostly used from annotations (generated code), where the expressions is either a single string, that resolved to a configured value (with comma separated defaults), or multiple strings, each representing a value.
      Parameters:
      config - configuration to obtain values for expression
      expressions - expressions to use to get actual values
      Returns:
      a set of values to be used by an application