Class ValueResolvingFilter

  • All Implemented Interfaces:

    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:
      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:
       "" = 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:
       "" = 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 Detail

      • ValueResolvingFilter

        public ValueResolvingFilter​(boolean failOnMissingReference)
        Creates an instance of filter with the specified behavior on missing references.
        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 Detail

      • init

        public void init​(Config config)
        Description copied from interface: ConfigFilter
        Initializes the filter using the Config instance which the filter will affect once 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
        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
        key - configuration key associated with the Config node
        stringValue - original value to be filtered, never null
        original value or filtered (changed) value, never null