@Typed public final class ConfigResolver extends Object
Resolve the configuration via their well defined ordinals.
You can provide your own lookup paths by implementing
and registering additional PropertyFileConfig or
ConfigSource or ConfigSourceProvider implementations.
| Modifier and Type | Method and Description |
|---|---|
static void |
addConfigFilter(ConfigFilter configFilter)
Add a
ConfigFilter to the ConfigResolver. |
static void |
addConfigSources(List<ConfigSource> configSourcesToAdd)
This method can be used for programmatically adding
ConfigSources. |
static void |
freeConfigSources()
Clear all ConfigSources for the current ClassLoader
|
static Map<String,String> |
getAllProperties() |
static List<String> |
getAllPropertyValues(String key)
Resolve all values for the given key, from all registered ConfigSources ordered by their
ordinal value in ascending ways.
|
static List<ConfigFilter> |
getConfigFilters() |
static String |
getProjectStageAwarePropertyValue(String key)
Search for the configured value in all
ConfigSources and take the
current ProjectStage
into account. |
static String |
getProjectStageAwarePropertyValue(String key,
String defaultValue)
getProjectStageAwarePropertyValue(String) which returns the defaultValue
if the property is null or empty. |
static String |
getPropertyAwarePropertyValue(String key,
String property)
Search for the configured value in all
ConfigSources and take the
current ProjectStage
and the value configured for the given property into account. |
static String |
getPropertyAwarePropertyValue(String key,
String property,
String defaultValue) |
static String |
getPropertyValue(String key)
Resolve the property value by going through the list of configured
ConfigSources
and use the one with the highest priority. |
static String |
getPropertyValue(String key,
String defaultValue)
Resolve the property value by going through the list of configured
ConfigSources
and use the one with the highest priority. |
public static void addConfigSources(List<ConfigSource> configSourcesToAdd)
ConfigSources.
It is not needed for normal 'usage' by end users, but only for Extension Developers!configSourcesToAdd - the ConfigSources to addpublic static void freeConfigSources()
public static void addConfigFilter(ConfigFilter configFilter)
ConfigFilter to the ConfigResolver.
This will only affect the current WebApp
(or more precisely the current ClassLoader and it's children).configFilter - public static List<ConfigFilter> getConfigFilters()
ConfigFilters for the current application.public static String getPropertyValue(String key, String defaultValue)
ConfigSources
and use the one with the highest priority. If no configured value has been found that
way we will use the defaultValue.key - the property key.defaultValue - will be used if no configured value for the key could be found.ConfigSource with the highest ordinal or
the defaultValue if there is no value explicitly configured.public static String getPropertyValue(String key)
ConfigSources
and use the one with the highest priority.key - the property key.ConfigSource with the highest ordinal or
null if there is no configured value for it.public static String getProjectStageAwarePropertyValue(String key)
Search for the configured value in all ConfigSources and take the
current ProjectStage
into account.
It first will search if there is a configured value of the given key prefixed with the current ProjectStage (e.g. 'myproject.myconfig.Production') and if this didn't find anything it will lookup the given key without any prefix.
Attention This method must only be used after all ConfigSources got registered and it also must not be used to determine the ProjectStage itself.
key - public static String getProjectStageAwarePropertyValue(String key, String defaultValue)
getProjectStageAwarePropertyValue(String) which returns the defaultValue
if the property is null or empty.key - defaultValue - public static String getPropertyAwarePropertyValue(String key, String property)
Search for the configured value in all ConfigSources and take the
current ProjectStage
and the value configured for the given property into account.
The first step is to resolve the value of the given property. This will take the current ProjectStage into account. E.g. given the property is 'dbvendor' and the ProjectStage is 'UnitTest', the first lookup is
If a value was found for the given property (e.g. dbvendor = 'mysql' then we will use this value to lookup in the following order until we found a non-null value. If there was no value found for the property we will only do the key+ProjectStage and key lookup. In the following sample 'dataSource' is used as key parameter:
Attention This method must only be used after all ConfigSources got registered and it also must not be used to determine the ProjectStage itself.
key - property - the property to look up firstpublic static String getPropertyAwarePropertyValue(String key, String property, String defaultValue)
public static List<String> getAllPropertyValues(String key)
ConfigSources have the same ordinal, their
order is undefined.key - under which configuration is storedConfigSource.getOrdinal()Copyright © 2011-2013 The Apache Software Foundation. All Rights Reserved.