use of org.apache.deltaspike.core.spi.config.ConfigSource in project deltaspike by apache.
the class ConfigResolver method getAllProperties.
/**
* Returns a Map of all properties from all scannable config sources. The values of the properties reflect the
* values that would be obtained by a call to {@link #getPropertyValue(java.lang.String)}, that is, the value of the
* property from the ConfigSource with the highest ordinal.
*
* @see ConfigSource#isScannable()
*/
public static Map<String, String> getAllProperties() {
// must use a new list because Arrays.asList() is resistant to sorting on some JVMs:
List<ConfigSource> appConfigSources = sortAscending(new ArrayList<ConfigSource>(Arrays.<ConfigSource>asList(getConfigSources())));
Map<String, String> result = new HashMap<String, String>();
for (ConfigSource configSource : appConfigSources) {
if (configSource.isScannable()) {
result.putAll(configSource.getProperties());
}
}
return Collections.unmodifiableMap(result);
}
use of org.apache.deltaspike.core.spi.config.ConfigSource in project deltaspike by apache.
the class ConfigResolver method getPropertyValue.
private static String getPropertyValue(String key, ConfigResolverContext configResolverContext) {
ConfigSource[] appConfigSources = getConfigSources();
String value;
for (ConfigSource configSource : appConfigSources) {
value = configSource.getPropertyValue(key);
if (value != null) {
LOG.log(Level.FINE, "found value {0} for key {1} in ConfigSource {2}.", new Object[] { filterConfigValueForLog(key, value), key, configSource.getConfigName() });
if (configResolverContext.isEvaluateVariables()) {
value = resolveVariables(value, configResolverContext);
}
return filterConfigValue(key, value);
}
LOG.log(Level.FINER, "NO value found for key {0} in ConfigSource {1}.", new Object[] { key, configSource.getConfigName() });
}
return null;
}
use of org.apache.deltaspike.core.spi.config.ConfigSource in project deltaspike by apache.
the class ConfigResolver method getAllPropertyValues.
/**
* Resolve all values for the given key.
*
* @param key
*
* @return a List of all found property values, sorted by their ordinal in ascending order
*
* @see org.apache.deltaspike.core.spi.config.ConfigSource#getOrdinal()
*/
public static List<String> getAllPropertyValues(String key) {
// must use a new list because Arrays.asList() is resistant to sorting on some JVMs:
List<ConfigSource> appConfigSources = sortAscending(new ArrayList<ConfigSource>(Arrays.<ConfigSource>asList(getConfigSources())));
List<String> result = new ArrayList<String>();
for (ConfigSource configSource : appConfigSources) {
String value = configSource.getPropertyValue(key);
if (value != null) {
value = filterConfigValue(key, value);
if (!result.contains(value)) {
result.add(value);
}
}
}
return result;
}
use of org.apache.deltaspike.core.spi.config.ConfigSource in project deltaspike by apache.
the class ConfigResolver method getConfigSources.
public static synchronized ConfigSource[] getConfigSources() {
ClassLoader currentClassLoader = ClassUtils.getClassLoader(null);
ConfigSource[] appConfigSources = configSources.get(currentClassLoader);
if (appConfigSources == null) {
appConfigSources = sortDescending(resolveConfigSources());
if (LOG.isLoggable(Level.FINE)) {
for (ConfigSource cs : appConfigSources) {
LOG.log(Level.FINE, "Adding ordinal {0} ConfigSource {1}", new Object[] { cs.getOrdinal(), cs.getConfigName() });
}
}
configSources.put(currentClassLoader, appConfigSources);
}
return appConfigSources;
}
use of org.apache.deltaspike.core.spi.config.ConfigSource in project deltaspike by apache.
the class ConfigResolver method resolveConfigSources.
private static List<ConfigSource> resolveConfigSources() {
List<ConfigSource> appConfigSources = ServiceUtils.loadServiceImplementations(ConfigSource.class);
List<ConfigSourceProvider> configSourceProviderServiceLoader = ServiceUtils.loadServiceImplementations(ConfigSourceProvider.class);
for (ConfigSourceProvider configSourceProvider : configSourceProviderServiceLoader) {
appConfigSources.addAll(configSourceProvider.getConfigSources());
}
List<? extends ConfigFilter> configFilters = ServiceUtils.loadServiceImplementations(ConfigFilter.class);
for (ConfigFilter configFilter : configFilters) {
addConfigFilter(configFilter);
}
return appConfigSources;
}
Aggregations