Search in sources :

Example 1 with ConfigSource

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;
}
Also used : ConfigSource(org.apache.deltaspike.core.spi.config.ConfigSource)

Example 2 with ConfigSource

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;
}
Also used : ConfigSource(org.apache.deltaspike.core.spi.config.ConfigSource) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 3 with ConfigSource

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;
}
Also used : ConfigSource(org.apache.deltaspike.core.spi.config.ConfigSource)

Example 4 with ConfigSource

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());
    }
}
Also used : ConfigSource(org.apache.deltaspike.core.spi.config.ConfigSource) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with ConfigSource

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);
}
Also used : ConfigSource(org.apache.deltaspike.core.spi.config.ConfigSource) ArrayList(java.util.ArrayList) ProcessBean(javax.enterprise.inject.spi.ProcessBean) Bean(javax.enterprise.inject.spi.Bean) ConfigFilter(org.apache.deltaspike.core.spi.config.ConfigFilter)

Aggregations

ConfigSource (org.apache.deltaspike.core.spi.config.ConfigSource)15 ArrayList (java.util.ArrayList)5 ConfigFilter (org.apache.deltaspike.core.spi.config.ConfigFilter)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Bean (javax.enterprise.inject.spi.Bean)2 ProcessBean (javax.enterprise.inject.spi.ProcessBean)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 CompositeType (javax.management.openmbean.CompositeType)2 OpenDataException (javax.management.openmbean.OpenDataException)2 OpenType (javax.management.openmbean.OpenType)2 TabularDataSupport (javax.management.openmbean.TabularDataSupport)2 TabularType (javax.management.openmbean.TabularType)2 ConfigSourceProvider (org.apache.deltaspike.core.spi.config.ConfigSourceProvider)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PropertyFileConfig (org.apache.deltaspike.core.api.config.PropertyFileConfig)1