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 ConfigurationExtension method logConfiguration.
private void logConfiguration() {
Boolean logConfig = ConfigResolver.resolve(ConfigResolver.DELTASPIKE_LOG_CONFIG).as(Boolean.class).getValue();
if (logConfig != null && logConfig && LOG.isLoggable(Level.INFO)) {
StringBuilder sb = new StringBuilder(1 << 16);
// first log out the config sources in descendent ordinal order
sb.append("ConfigSources: ");
ConfigSource[] configSources = ConfigResolver.getConfigSources();
for (ConfigSource configSource : configSources) {
sb.append("\n\t").append(configSource.getOrdinal()).append(" - ").append(configSource.getConfigName());
}
// and all the entries in no guaranteed order
Map<String, String> allProperties = ConfigResolver.getAllProperties();
sb.append("\n\nConfigured Values:");
for (Map.Entry<String, String> entry : allProperties.entrySet()) {
sb.append("\n\t").append(entry.getKey()).append(" = ").append(ConfigResolver.filterConfigValueForLog(entry.getKey(), entry.getValue()));
}
LOG.info(sb.toString());
}
}
use of org.apache.deltaspike.core.spi.config.ConfigSource in project deltaspike by apache.
the class ConfigurationExtension method validateConfiguration.
public void validateConfiguration(@Observes AfterDeploymentValidation adv) {
List<ConfigSource> configSources = new ArrayList<ConfigSource>(cdiSources.size());
for (final Bean bean : cdiSources) {
configSources.add(BeanProvider.getContextualReference(ConfigSource.class, bean));
}
ConfigResolver.addConfigSources(configSources);
for (final Bean bean : cdiFilters) {
ConfigResolver.addConfigFilter(BeanProvider.getContextualReference(ConfigFilter.class, bean));
}
processConfigurationValidation(adv);
}
Aggregations