Search in sources :

Example 1 with DefaultConfigurationBuilder

use of org.apache.commons.configuration.DefaultConfigurationBuilder in project metron by apache.

the class ConfigurationManager method getConfiguration.

/**
 * Common method to load content of all configuration resources defined in
 * 'config-definition.xml'.
 *
 * @param configDefFilePath
 *          the config def file path
 * @return Configuration
 */
public static Configuration getConfiguration(String configDefFilePath) {
    if (configurationsCache.containsKey(configDefFilePath)) {
        return configurationsCache.get(configDefFilePath);
    }
    CombinedConfiguration configuration = null;
    synchronized (configurationsCache) {
        if (configurationsCache.containsKey(configDefFilePath)) {
            return configurationsCache.get(configDefFilePath);
        }
        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
        String filePath = getConfigDefFilePath(configDefFilePath);
        LOGGER.info("loading from 'configDefFilePath' : {}", filePath);
        builder.setFile(new File(filePath));
        try {
            configuration = builder.getConfiguration(true);
            configurationsCache.put(filePath, configuration);
        } catch (ConfigurationException | ConfigurationRuntimeException e) {
            LOGGER.info("Exception in loading property files.", e);
        }
    }
    return configuration;
}
Also used : DefaultConfigurationBuilder(org.apache.commons.configuration.DefaultConfigurationBuilder) ConfigurationRuntimeException(org.apache.commons.configuration.ConfigurationRuntimeException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) File(java.io.File)

Aggregations

File (java.io.File)1 CombinedConfiguration (org.apache.commons.configuration.CombinedConfiguration)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 ConfigurationRuntimeException (org.apache.commons.configuration.ConfigurationRuntimeException)1 DefaultConfigurationBuilder (org.apache.commons.configuration.DefaultConfigurationBuilder)1