- 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"
message = "Hello Joachim!"
How to Activate This Filter
Use any of the following techniques to create aValueResolvingFilter
and use it for config look-ups.- Programmatically:
- Invoke
ConfigFilters.valueResolving()
to get a builder for the filter. - Optionally, invoke the filter builder's
failOnMissingReference
method (see below). - Invoke the builder's
build
method to create the filter. - Then, on the
Config.Builder
being used to construct theConfig
instance, invokeConfig.Builder#addFilter
passing the just-created filter.
- Invoke
- Implicitly: Create or edit the file
io.helidon.config.ConfigFilter
on the application's runtime classpath to contain this line:io.helidon.config.ValueResolvingFilter
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.- If you use
ConfigFilters.valueResolving()
to get a builder for the filter, invoke thefailOnMissingReference
method on that builder before invoking the filter builder'sbuild
method. - If you use
ConfigFilters.ValueResolvingBuilder.create(io.helidon.config.Config)
to get the filter's builder, define this setting in theConfig
instance you pass to thefrom
method:"config.value-resolving-filter.fail-on-missing-reference" = true
orfalse
which is the default. This sets the behavior for the single filter created from that builder. - If you use the Java service loader mechanism to create
ValueResolvingFilter
s for everyConfig.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
orfalse
which is the default. This sets the behavior for everyValueResolvingFilter
created for which thefailOnMissingReference
value has not already been set, for example by invoking theConfigFilters.valueResolving().failOnMissingReference()
method.
-
-
Field Summary
-
Fields inherited from interface io.helidon.config.spi.ConfigFilter
PRIORITY
-
-
Constructor Summary
Constructors Constructor Description ValueResolvingFilter()
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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
apply(Config.Key key, String stringValue)
Filters an elementary config value before it is made available to the application via theConfig
API.void
init(Config config)
Initializes the filter using theConfig
instance which the filter will affect onceConfig.Builder.build
completes.
-
-
-
Constructor Detail
-
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 Detail
-
init
public void init(Config config)
Description copied from interface:ConfigFilter
Initializes the filter using theConfig
instance which the filter will affect onceConfig.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 interfaceConfigFilter
- 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 theConfig
API.- Specified by:
apply
in interfaceConfigFilter
- Parameters:
key
- configurationkey
associated with theConfig
nodestringValue
- original value to be filtered, nevernull
- Returns:
- original value or filtered (changed) value, never
null
-
-