Class ValueResolvingFilter

java.lang.Object
io.helidon.config.ValueResolvingFilter
All Implemented Interfaces:
ConfigFilter

public class ValueResolvingFilter extends Object implements ConfigFilter
A config filter that replaces all placeholders in a config value String with their corresponding values looked up from the config.

For example:

 message = "Hello ${name}!"
 name = "Joachim"
will be resolved as:
 message = "Hello Joachim!"

How to Activate This Filter

Use any of the following techniques to create a ValueResolvingFilter and use it for config look-ups.
  1. Programmatically:
    1. Invoke ConfigFilters.valueResolving() to get a builder for the filter.
    2. Optionally, invoke the filter builder's failOnMissingReference method (see below).
    3. Invoke the builder's build method to create the filter.
    4. Then, on the Config.Builder being used to construct the Config instance, invoke Config.Builder#addFilter passing the just-created filter.
  2. Implicitly: Create or edit the file io.helidon.config.ConfigFilter on the application's runtime classpath to contain this line:
     io.helidon.config.ValueResolvingFilter
    The config system will then use the Java service loader mechanism to create and add this filter to every Config.Builder automatically.

Handling Missing References

By default, references to tokens that are not present do not cause retrievals to fail. You can customize this behavior in several ways.
  1. If you use ConfigFilters.valueResolving() to get a builder for the filter, invoke the failOnMissingReference method on that builder before invoking the filter builder's build method.
  2. If you use ConfigFilters.ValueResolvingBuilder.create(io.helidon.config.Config) to get the filter's builder, define this setting in the Config instance you pass to the from method:
     "config.value-resolving-filter.fail-on-missing-reference" = true
    or false which is the default. This sets the behavior for the single filter created from that builder.
  3. If you use the Java service loader mechanism to create ValueResolvingFilters for every Config.Builder, specify the following config setting in one of the config sources that composes the default config:
     "config.value-resolving-filter.fail-on-missing-reference" = true
    or false which is the default. This sets the behavior for every ValueResolvingFilter created for which the failOnMissingReference value has not already been set, for example by invoking the ConfigFilters.valueResolving().failOnMissingReference() method.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of the filter with no explicit failOnMissing behavior set.
    ValueResolvingFilter(boolean failOnMissingReference)
    Creates an instance of filter with the specified behavior on missing references.
  • Method Summary

    Modifier and Type
    Method
    Description
    apply(Config.Key key, String stringValue)
    Filters an elementary config value before it is made available to the application via the Config API.
    void
    init(Config config)
    Initializes the filter using the Config instance which the filter will affect once Config.Builder.build completes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.helidon.config.spi.ConfigFilter

    apply
  • Constructor Details

    • ValueResolvingFilter

      public ValueResolvingFilter(boolean failOnMissingReference)
      Creates an instance of filter with the specified behavior on missing references.
      Parameters:
      failOnMissingReference - whether to fail when a referenced key is missing
    • ValueResolvingFilter

      public ValueResolvingFilter()
      Creates an instance of the filter with no explicit failOnMissing behavior set.
  • Method Details

    • init

      public void init(Config config)
      Description copied from interface: ConfigFilter
      Initializes the filter using the Config instance which the filter will affect once Config.Builder.build completes.

      The config system propagates any thrown exception to the application so its invocation of Config.Builder#build fails.

      Specified by:
      init in interface ConfigFilter
      Parameters:
      config - Config instance under construction
    • apply

      public String apply(Config.Key key, String stringValue)
      Description copied from interface: ConfigFilter
      Filters an elementary config value before it is made available to the application via the Config API.
      Specified by:
      apply in interface ConfigFilter
      Parameters:
      key - configuration key associated with the Config node
      stringValue - original value to be filtered, never null
      Returns:
      original value or filtered (changed) value, never null