Search in sources :

Example 6 with ConfigSource

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

Example 7 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 8 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 9 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 10 with ConfigSource

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

Aggregations

ConfigSource (org.apache.deltaspike.core.spi.config.ConfigSource)11 ArrayList (java.util.ArrayList)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)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 ConfigFilter (org.apache.deltaspike.core.spi.config.ConfigFilter)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 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Bean (javax.enterprise.inject.spi.Bean)1 ProcessBean (javax.enterprise.inject.spi.ProcessBean)1 PropertyFileConfig (org.apache.deltaspike.core.api.config.PropertyFileConfig)1 ConfigSourceProvider (org.apache.deltaspike.core.spi.config.ConfigSourceProvider)1