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.
| Modifier and Type | Field and Description |
|---|---|
static Pattern | DEFAULT_PATTERN |
| Constructor and Description |
|---|
ConfigTransformer(Map<String,ConfigProvider> configProviders)Creates a ConfigTransformer with the default pattern, of the form ${provider:[path:]key}. |
| Modifier and Type | Method and Description |
|---|---|
ConfigTransformerResult | transform(Map<String,String> configs)Transforms the given configuration data by using the ConfigProvider instances to look up values to replace the variables in the pattern. |
public static final Pattern DEFAULT_PATTERN
public ConfigTransformer(Map<String,ConfigProvider> configProviders)
${provider:[path:]key}.configProviders - a Map of provider names and ConfigProvider instances.public ConfigTransformerResult transform(Map<String,String> configs)
ConfigProvider instances to look up values to replace the variables in the pattern.configs - the configuration values to be transformedConfigTransformerResult