Example usage for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration

List of usage examples for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration.

Prototype

public CompositeConfiguration() 

Source Link

Document

Creates an empty CompositeConfiguration object which can then be added some other Configuration files

Usage

From source file:org.archfirst.common.config.BaseConfigurationService.java

protected BaseConfigurationService() {
    this.config = new CompositeConfiguration();
}

From source file:org.cesecore.config.ConfigurationHolder.java

public static synchronized Configuration instance() {
    if (config == null) {
        // Read in default values
        defaultValues = new CompositeConfiguration();
        final URL defaultConfigUrl = ConfigurationHolder.class.getResource(DEFAULT_CONFIG_FILE);
        try {//  w w w  .j  a  va2  s. com
            defaultValues.addConfiguration(new PropertiesConfiguration(defaultConfigUrl));
        } catch (ConfigurationException e) {
            log.error("Error encountered when loading default properties. Could not load configuration from "
                    + defaultConfigUrl, e);
        }

        // read cesecore.properties, from config file built into jar, and see if we allow configuration by external files
        boolean allowexternal = false;
        try {
            final URL url = ConfigurationHolder.class.getResource("/conf/" + CONFIG_FILES[0]);
            if (url != null) {
                final PropertiesConfiguration pc = new PropertiesConfiguration(url);
                allowexternal = "true".equalsIgnoreCase(pc.getString(CONFIGALLOWEXTERNAL, "false"));
                log.info("Allow external re-configuration: " + allowexternal);
            }
        } catch (ConfigurationException e) {
            log.error("Error intializing configuration: ", e);
        }
        config = new CompositeConfiguration();

        // Only add these config sources if we allow external configuration
        if (allowexternal) {
            // Override with system properties, this is prio 1 if it exists (java -Dscep.test=foo)
            config.addConfiguration(new SystemConfiguration());
            log.info("Added system properties to configuration source (java -Dfoo.prop=bar).");

            // Override with file in "application server home directory"/conf, this is prio 2
            for (int i = 0; i < CONFIG_FILES.length; i++) {
                File f = null;
                try {
                    f = new File("conf" + File.separator + CONFIG_FILES[i]);
                    final PropertiesConfiguration pc = new PropertiesConfiguration(f);
                    pc.setReloadingStrategy(new FileChangedReloadingStrategy());
                    config.addConfiguration(pc);
                    log.info("Added file to configuration source: " + f.getAbsolutePath());
                } catch (ConfigurationException e) {
                    log.error("Failed to load configuration from file " + f.getAbsolutePath());
                }
            }
            // Override with file in "/etc/cesecore/conf/, this is prio 3
            for (int i = 0; i < CONFIG_FILES.length; i++) {
                File f = null;
                try {
                    f = new File("/etc/cesecore/conf/" + CONFIG_FILES[i]);
                    final PropertiesConfiguration pc = new PropertiesConfiguration(f);
                    pc.setReloadingStrategy(new FileChangedReloadingStrategy());
                    config.addConfiguration(pc);
                    log.info("Added file to configuration source: " + f.getAbsolutePath());
                } catch (ConfigurationException e) {
                    log.error("Failed to load configuration from file " + f.getAbsolutePath());
                }
            }
        } // if (allowexternal)

        // Default values build into jar file, this is last prio used if no of the other sources override this
        for (int i = 0; i < CONFIG_FILES.length; i++) {
            addConfigurationResource("/conf/" + CONFIG_FILES[i]);
        }
        // Load internal.properties only from built in configuration file
        try {
            final URL url = ConfigurationHolder.class.getResource("/internal.properties");
            if (url != null) {
                final PropertiesConfiguration pc = new PropertiesConfiguration(url);
                config.addConfiguration(pc);
                log.debug("Added url to configuration source: " + url);
            }
        } catch (ConfigurationException e) {
            log.error("Failed to load configuration from resource internal.properties", e);
        }
    }
    return config;
}

From source file:org.cesecore.configuration.ConfigurationTestHolder.java

private ConfigurationTestHolder() {
    config = new CompositeConfiguration();
    init();
}

From source file:org.dataone.proto.trove.mn.dao.v1.SolrLogIndexer.java

/**
 * Include additional properties in the global configuration. Properties included in the given file will override
 * existing properties in the global configuration if they are present.
 *
 * @param addProperties/*  w w w.  j a v  a  2 s.c o m*/
 * @return Configuration
 * @throws ConfigurationException
 * @throws java.io.IOException
 */
public Configuration getApacheConfiguration(Properties addProperties)
        throws ConfigurationException, IOException {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    addProperties.store(baos, "hold your comments please");

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    PropertiesConfiguration propertyConfiguration = new PropertiesConfiguration();
    propertyConfiguration.load(bais);
    CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
    compositeConfiguration.addConfiguration(propertyConfiguration);
    return compositeConfiguration;

}

From source file:org.debux.webmotion.server.ConfigurationTest.java

@Test
public void testComposite() throws ConfigurationException {
    PropertiesConfiguration local = new PropertiesConfiguration();
    local.load(new StringReader("name=value"));

    PropertiesConfiguration file = new PropertiesConfiguration();
    file.load(new StringReader("name=other"));

    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(file);/*from   ww  w  .  jav a  2  s .c  o  m*/
    composite.addConfiguration(local);

    AssertJUnit.assertEquals("other", composite.getString("name"));
}

From source file:org.debux.webmotion.server.mapping.Properties.java

public Properties() {
    super(new CompositeConfiguration());
}

From source file:org.dspace.servicemanager.config.DSpaceConfigurationFactoryBean.java

/**
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 *//*  w  ww.  ja  va2  s .c  o m*/
public void afterPropertiesSet() throws Exception {
    if (configuration == null && (configurations == null || configurations.length == 0)
            && (locations == null || locations.length == 0))
        throw new IllegalArgumentException("no configuration object or location specified");

    if (configuration == null)
        configuration = new CompositeConfiguration();

    configuration.setThrowExceptionOnMissing(throwExceptionOnMissing);

    if (configurations != null) {
        for (int i = 0; i < configurations.length; i++) {
            configuration.addConfiguration(configurations[i]);
        }
    }

    if (locations != null) {
        for (int i = 0; i < locations.length; i++) {
            URL url = locations[i].getURL();
            Configuration props = new PropertiesConfiguration(url);
            configuration.addConfiguration(props);
        }
    }
}

From source file:org.eclipse.kapua.commons.setting.AbstractKapuaSetting.java

protected AbstractKapuaSetting(String configResourceName) {
    // env+properties configuration
    CompositeConfiguration compositeConfig = new CompositeConfiguration();
    compositeConfig.addConfiguration(new SystemConfiguration());
    try {//from ww w.ja  va2s .  c om
        URL configLocalUrl = ResourceUtils.getResource(configResourceName);
        compositeConfig.addConfiguration(new PropertiesConfiguration(configLocalUrl));
    } catch (Exception e) {
        s_logger.error("Error loading PropertiesConfiguration", e);
        throw new ExceptionInInitializerError(e);
    }

    this.config = new DataConfiguration(compositeConfig);
}

From source file:org.ejbca.config.ConfigurationHolder.java

public static Configuration instance() {
    if (config == null) {
        // read ejbca.properties, from config file built into jar, and see if we allow configuration by external files
        boolean allowexternal = false;
        try {//w  ww  .  ja v a 2  s.  c  o  m
            final URL url = ConfigurationHolder.class.getResource("/conf/" + CONFIG_FILES[0]);
            if (url != null) {
                final PropertiesConfiguration pc = new PropertiesConfiguration(url);
                allowexternal = "true".equalsIgnoreCase(pc.getString(CONFIGALLOWEXTERNAL, "false"));
                log.info("Allow external re-configuration: " + allowexternal);
            }
        } catch (ConfigurationException e) {
            log.error("Error intializing configuration: ", e);
        }
        config = new CompositeConfiguration();

        // Only add these config sources if we allow external configuration
        if (allowexternal) {
            // Override with system properties, this is prio 1 if it exists (java -Dscep.test=foo)
            config.addConfiguration(new SystemConfiguration());
            log.info("Added system properties to configuration source (java -Dfoo.prop=bar).");

            // Override with file in "application server home directory"/conf, this is prio 2
            for (int i = 0; i < CONFIG_FILES.length; i++) {
                File f = null;
                try {
                    f = new File("conf" + File.separator + CONFIG_FILES[i]);
                    final PropertiesConfiguration pc = new PropertiesConfiguration(f);
                    pc.setReloadingStrategy(new FileChangedReloadingStrategy());
                    config.addConfiguration(pc);
                    log.info("Added file to configuration source: " + f.getAbsolutePath());
                } catch (ConfigurationException e) {
                    log.error("Failed to load configuration from file " + f.getAbsolutePath());
                }
            }
            // Override with file in "/etc/ejbca/conf/, this is prio 3
            for (int i = 0; i < CONFIG_FILES.length; i++) {
                File f = null;
                try {
                    f = new File("/etc/ejbca/conf/" + CONFIG_FILES[i]);
                    final PropertiesConfiguration pc = new PropertiesConfiguration(f);
                    pc.setReloadingStrategy(new FileChangedReloadingStrategy());
                    config.addConfiguration(pc);
                    log.info("Added file to configuration source: " + f.getAbsolutePath());
                } catch (ConfigurationException e) {
                    log.error("Failed to load configuration from file " + f.getAbsolutePath());
                }
            }
        } // if (allowexternal)

        // Default values build into jar file, this is last prio used if no of the other sources override this
        for (int i = 0; i < CONFIG_FILES.length; i++) {
            addConfigurationResource(CONFIG_FILES[i]);
        }
        // Load internal.properties only from built in configuration file
        try {
            final URL url = ConfigurationHolder.class.getResource("/internal.properties");
            if (url != null) {
                final PropertiesConfiguration pc = new PropertiesConfiguration(url);
                config.addConfiguration(pc);
                log.debug("Added url to configuration source: " + url);
            }
        } catch (ConfigurationException e) {
            log.error("Failed to load configuration from resource internal.properties", e);
        }
    }
    return config;
}

From source file:org.ejbca.config.EjbcaConfigurationHolder.java

public static Configuration instance() {
    if (config == null) {
        // read ejbca.properties, from config file built into jar, and see if we allow configuration by external files
        boolean allowexternal = false;
        try {/*from  w ww  .  j  av  a2 s . c  om*/
            final URL url = EjbcaConfigurationHolder.class.getResource("/conf/" + CONFIG_FILES[0]);
            if (url != null) {
                final PropertiesConfiguration pc = new PropertiesConfiguration(url);
                allowexternal = "true".equalsIgnoreCase(pc.getString(CONFIGALLOWEXTERNAL, "false"));
                if (allowexternal) {
                    log.info("Allow external re-configuration: " + allowexternal);
                }
            }
        } catch (ConfigurationException e) {
            log.error("Error intializing configuration: ", e);
        }
        config = new CompositeConfiguration();

        // Only add these config sources if we allow external configuration
        if (allowexternal) {
            // Override with system properties, this is prio 1 if it exists (java -Dscep.test=foo)
            config.addConfiguration(new SystemConfiguration());
            log.info("Added system properties to configuration source (java -Dfoo.prop=bar).");

            // Override with file in "application server home directory"/conf, this is prio 2
            for (int i = 0; i < CONFIG_FILES.length; i++) {
                File f = null;
                try {
                    f = new File("conf" + File.separator + CONFIG_FILES[i]);
                    final PropertiesConfiguration pc = new PropertiesConfiguration(f);
                    pc.setReloadingStrategy(new FileChangedReloadingStrategy());
                    config.addConfiguration(pc);
                    log.info("Added file to configuration source: " + f.getAbsolutePath());
                } catch (ConfigurationException e) {
                    log.error("Failed to load configuration from file " + f.getAbsolutePath());
                }
            }
            // Override with file in "/etc/ejbca/conf/, this is prio 3
            for (int i = 0; i < CONFIG_FILES.length; i++) {
                File f = null;
                try {
                    f = new File("/etc/ejbca/conf/" + CONFIG_FILES[i]);
                    final PropertiesConfiguration pc = new PropertiesConfiguration(f);
                    pc.setReloadingStrategy(new FileChangedReloadingStrategy());
                    config.addConfiguration(pc);
                    log.info("Added file to configuration source: " + f.getAbsolutePath());
                } catch (ConfigurationException e) {
                    log.error("Failed to load configuration from file " + f.getAbsolutePath());
                }
            }
        } // if (allowexternal)

        // Default values build into jar file, this is last prio used if no of the other sources override this
        for (int i = 0; i < CONFIG_FILES.length; i++) {
            addConfigurationResource(CONFIG_FILES[i]);
        }
        // Load internal.properties only from built in configuration file
        try {
            final URL url = EjbcaConfigurationHolder.class.getResource("/internal.properties");
            if (url != null) {
                final PropertiesConfiguration pc = new PropertiesConfiguration(url);
                config.addConfiguration(pc);
                log.debug("Added url to configuration source: " + url);
            }
        } catch (ConfigurationException e) {
            log.error("Failed to load configuration from resource internal.properties", e);
        }
    }
    return config;
}