Class ConfigTransformer
public class ConfigTransformer extends Object
ConfigProvider
instances and uses them to perform
transformations.
The default variable pattern is of the form ${provider:[path:]key}
,
where the provider
corresponds to a ConfigProvider
instance, as passed to
ConfigTransformer(Map)
. The pattern will extract a set
of paths (which are optional) and keys and then pass them to ConfigProvider.get(String, Set)
to obtain the
values with which to replace the variables.
For example, if a Map consisting of an entry with a provider name "file" and provider instance
FileConfigProvider
is passed to the ConfigTransformer(Map)
, and a Properties
file with contents
fileKey=someValueresides at the path "/tmp/properties.txt", then when a configuration Map which has an entry with a key "someKey" and a value "${file:/tmp/properties.txt:fileKey}" is passed to the
transform(Map)
method, then the transformed
Map will have an entry with key "someKey" and a value "someValue".
This class only depends on ConfigProvider.get(String, Set)
and does not depend on subscription support
in a ConfigProvider
, such as the ConfigProvider.subscribe(String, Set, ConfigChangeCallback)
and
ConfigProvider.unsubscribe(String, Set, ConfigChangeCallback)
methods.
-
Field Summary
Fields Modifier and Type Field Description static Pattern
DEFAULT_PATTERN
-
Constructor Summary
Constructors Constructor Description ConfigTransformer(Map<String,ConfigProvider> configProviders)
Creates a ConfigTransformer with the default pattern, of the form${provider:[path:]key}
. -
Method Summary
Modifier and Type Method Description ConfigTransformerResult
transform(Map<String,String> configs)
Transforms the given configuration data by using theConfigProvider
instances to look up values to replace the variables in the pattern.
-
Field Details
-
DEFAULT_PATTERN
-
-
Constructor Details
-
ConfigTransformer
Creates a ConfigTransformer with the default pattern, of the form${provider:[path:]key}
.- Parameters:
configProviders
- a Map of provider names andConfigProvider
instances.
-
-
Method Details
-
transform
Transforms the given configuration data by using theConfigProvider
instances to look up values to replace the variables in the pattern.- Parameters:
configs
- the configuration values to be transformed- Returns:
- an instance of
ConfigTransformerResult
-