@Override public void contextInitialized(ServletContextEvent sce) { ConfigSource[] configSources = ConfigResolver.getConfigSources(); for (ConfigSource configSource : configSources) { if (configSource instanceof ServletConfigSource) { setServletConfig((ServletConfigSource) configSource, sce); return; } } }
public static Map<String, String> getAllProperties() { List<ConfigSource> appConfigSources = sortAscending(new ArrayList<ConfigSource>(Arrays.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); }
/** * This method can be used for programmatically adding {@link ConfigSource}s. * It is not needed for normal 'usage' by end users, but only for Extension Developers! * * @param configSourcesToAdd the ConfigSources to add */ public static synchronized void addConfigSources(List<ConfigSource> configSourcesToAdd) { // we first pickup all pre-configured ConfigSources... getConfigSources(); // and now we can easily add our own ClassLoader currentClassLoader = ClassUtils.getClassLoader(null); ConfigSource[] configuredConfigSources = configSources.get(currentClassLoader); List<ConfigSource> allConfigSources = new ArrayList<ConfigSource>(); allConfigSources.addAll(Arrays.asList(configuredConfigSources)); allConfigSources.addAll(configSourcesToAdd); // finally put all the configSources back into the map configSources.put(currentClassLoader, sortDescending(allConfigSources)); }
@Override public String[] getConfigSourcesAsString() { ClassLoader originalCl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(appConfigClassLoader); ConfigSource[] configSources = ConfigResolver.getConfigSources(); List<String> configSourceInfo = new ArrayList<String>(); for (ConfigSource configSource : configSources) { configSourceInfo.add(Integer.toString(configSource.getOrdinal()) + " - " + configSource.getConfigName()); } return configSourceInfo.toArray(new String[configSourceInfo.size()]); } finally { // set back the original TCCL Thread.currentThread().setContextClassLoader(originalCl); } }
private List<ConfigEntry> calculateConfigEntries() { Map<String, String> allProperties = ConfigResolver.getAllProperties(); List<ConfigEntry> configEntries = new ArrayList<ConfigEntry>(allProperties.size()); ConfigSource[] configSources = ConfigResolver.getConfigSources(); for (Map.Entry<String, String> configEntry : allProperties.entrySet()) { String key = configEntry.getKey(); String value = ConfigResolver.filterConfigValueForLog(key, ConfigResolver.getProjectStageAwarePropertyValue(key)); String fromConfigSource = getFromConfigSource(configSources, key); configEntries.add(new ConfigEntry(key, value, fromConfigSource)); } return configEntries; }
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()); } }
/** * Resolve all values for the given key, from all registered ConfigSources ordered by their * ordinal value in ascending ways. If more {@link ConfigSource}s have the same ordinal, their * order is undefined. * * @param key under which configuration is stored * @return List with all found property values, sorted in ascending order of their ordinal. * @see org.apache.deltaspike.core.spi.config.ConfigSource#getOrdinal() */ public static List<String> getAllPropertyValues(String key) { List<ConfigSource> appConfigSources = sortAscending(new ArrayList<ConfigSource>(Arrays.asList(getConfigSources()))); List<String> result = new ArrayList<String>(); String value; for (ConfigSource configSource : appConfigSources) { value = configSource.getPropertyValue(key); if (value != null) { value = filterConfigValue(key, value); if (!result.contains(value)) { result.add(value); } } } return result; }
TabularDataSupport configSourceInfo = new TabularDataSupport(type); ConfigSource[] configSources = ConfigResolver.getConfigSources(); for (ConfigSource configSource : configSources)
for (ConfigSource configSource : ConfigResolver.getConfigSources())
TabularDataSupport configEntryInfo = new TabularDataSupport(type); ConfigSource[] configSources = ConfigResolver.getConfigSources(); for (ConfigEntry configEntry : configEntries)
/** * Resolve the property value by going through the list of configured {@link ConfigSource}s * and use the one with the highest priority. * * @param key the property key. * @return the configured property value from the {@link ConfigSource} with the highest ordinal or * null if there is no configured value for it. */ public static String getPropertyValue(String key) { 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()}); return filterConfigValue(key, value); } LOG.log(Level.FINER, "NO value found for key {0} in ConfigSource {1}.", new Object[]{key, configSource.getConfigName()}); } return null; }
private void setTestConfigSourceValue(String key, String value) { ConfigSource[] configSources = ConfigResolver.getConfigSources(); for (ConfigSource configSource : configSources) { if (configSource instanceof TestConfigSource) { if (value == null) { configSource.getProperties().remove(key); } else { configSource.getProperties().put(key, value); } break; } } }