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

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

Introduction

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

Prototype

public void addConfiguration(Configuration config) 

Source Link

Document

Add a configuration.

Usage

From source file:com.cloudera.whirr.cm.CmServerClusterInstance.java

public synchronized static Configuration getConfiguration(ClusterSpec clusterSpec) throws IOException {
    try {/*from  w  w  w .jav a2  s.com*/
        CompositeConfiguration configuration = new CompositeConfiguration();
        if (clusterSpec != null) {
            configuration.addConfiguration(clusterSpec.getConfiguration());
        }
        configuration.addConfiguration(new PropertiesConfiguration(
                CmServerClusterInstance.class.getClassLoader().getResource(CONFIG_WHIRR_DEFAULT_FILE)));
        return configuration;
    } catch (ConfigurationException e) {
        throw new IOException("Error loading " + CONFIG_WHIRR_DEFAULT_FILE, e);
    }
}

From source file:ffx.utilities.Keyword.java

/**
 * This method sets up configuration properties in the following precedence
 * * order:/*w  w w .ja  va  2 s.  c o m*/
 *
 * 1.) Structure specific properties (for example pdbname.properties)
 *
 * 2.) Java system properties a.) -Dkey=value from the Java command line b.)
 * System.setProperty("key","value") within Java code.
 *
 * 3.) User specific properties (~/.ffx/ffx.properties)
 *
 * 4.) System wide properties (file defined by environment variable
 * FFX_PROPERTIES)
 *
 * 5.) Internal force field definition.
 *
 * @since 1.0
 * @param file a {@link java.io.File} object.
 * @return a {@link org.apache.commons.configuration.CompositeConfiguration}
 * object.
 */
public static CompositeConfiguration loadProperties(File file) {
    /**
     * Command line options take precedence.
     */
    CompositeConfiguration properties = new CompositeConfiguration();

    /**
     * Structure specific options are first.
     */
    if (file != null) {
        String filename = file.getAbsolutePath();
        filename = org.apache.commons.io.FilenameUtils.removeExtension(filename);
        String propertyFilename = filename + ".properties";
        File structurePropFile = new File(propertyFilename);
        if (structurePropFile.exists() && structurePropFile.canRead()) {
            try {
                properties.addConfiguration(new PropertiesConfiguration(structurePropFile));
                properties.addProperty("propertyFile", structurePropFile.getCanonicalPath());
            } catch (ConfigurationException | IOException e) {
                logger.log(Level.INFO, " Error loading {0}.", filename);
            }
        } else {
            propertyFilename = filename + ".key";
            structurePropFile = new File(propertyFilename);
            if (structurePropFile.exists() && structurePropFile.canRead()) {
                try {
                    properties.addConfiguration(new PropertiesConfiguration(structurePropFile));
                    properties.addProperty("propertyFile", structurePropFile.getCanonicalPath());
                } catch (ConfigurationException | IOException e) {
                    logger.log(Level.INFO, " Error loading {0}.", filename);
                }
            }
        }
    }

    /**
     * Java system properties
     *
     * a.) -Dkey=value from the Java command line
     *
     * b.) System.setProperty("key","value") within Java code.
     */
    properties.addConfiguration(new SystemConfiguration());

    /**
     * User specific options are 3rd.
     */
    String filename = System.getProperty("user.home") + File.separator + ".ffx/ffx.properties";
    File userPropFile = new File(filename);
    if (userPropFile.exists() && userPropFile.canRead()) {
        try {
            properties.addConfiguration(new PropertiesConfiguration(userPropFile));
        } catch (ConfigurationException e) {
            logger.log(Level.INFO, " Error loading {0}.", filename);
        }
    }

    /**
     * System wide options are 2nd to last.
     */
    filename = System.getenv("FFX_PROPERTIES");
    if (filename != null) {
        File systemPropFile = new File(filename);
        if (systemPropFile.exists() && systemPropFile.canRead()) {
            try {
                properties.addConfiguration(new PropertiesConfiguration(systemPropFile));
            } catch (ConfigurationException e) {
                logger.log(Level.INFO, " Error loading {0}.", filename);
            }
        }
    }

    /**
     * Echo the interpolated configuration.
     */
    if (logger.isLoggable(Level.FINE)) {
        //Configuration config = properties.interpolatedConfiguration();
        Iterator<String> i = properties.getKeys();
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("\n %-30s %s\n", "Property", "Value"));
        while (i.hasNext()) {
            String s = i.next();
            //sb.append(String.format(" %-30s %s\n", s, Arrays.toString(config.getList(s).toArray())));
            sb.append(String.format(" %-30s %s\n", s, Arrays.toString(properties.getList(s).toArray())));
        }
        logger.fine(sb.toString());
    }

    return properties;
}

From source file:com.strandls.alchemy.webservices.client.ClientInitModule.java

/**
 * @return configuration for the client.
 *//*from  w  w  w .  ja  v  a 2 s. c  om*/
private Configuration getConfiguration() {
    final CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {
        config.addConfiguration(new PropertiesConfiguration(CLIENT_PROPERTIES));
    } catch (final ConfigurationException e) {
        throw new RuntimeException(e);
    }
    return config;
}

From source file:br.com.ingenieux.mojo.jbake.GenerateMojo.java

protected CompositeConfiguration createConfiguration() throws ConfigurationException {
    final CompositeConfiguration config = new CompositeConfiguration();

    config.addConfiguration(ConfigUtil.load(inputDirectory));

    config.addConfiguration(new MapConfiguration(this.project.getProperties()));

    return config;
}

From source file:com.dattack.naming.loader.factory.DataSourceFactory.java

@Override
public DataSource getObjectInstance(final Properties properties, final Collection<File> extraClasspath)
        throws NamingException {

    final CompositeConfiguration configuration = new CompositeConfiguration();
    configuration.addConfiguration(new SystemConfiguration());
    configuration.addConfiguration(new EnvironmentConfiguration());
    configuration.addConfiguration(new MapConfiguration(properties));

    final String driver = configuration.getString(DRIVER_KEY);
    if (driver == null) {
        throw new ConfigurationException(String.format("Missing property '%s'", DRIVER_KEY));
    }/*from w  w w . j a  va 2  s .  c om*/

    final String url = configuration.getString(URL_KEY);
    if (url == null) {
        throw new ConfigurationException(String.format("Missing property '%s'", URL_KEY));
    }

    final String user = configuration.getString(USERNAME_KEY);
    final String password = configuration.getString(PASSWORD_KEY);

    DataSource dataSource = null;
    try {
        final Properties props = ConfigurationConverter.getProperties(configuration);
        dataSource = BasicDataSourceFactory.createDataSource(props);
    } catch (final Exception e) { // NOPMD by cvarela on 8/02/16 22:28
        // we will use a DataSource without a connection pool
        LOGGER.info(e.getMessage());
        dataSource = new SimpleDataSource(driver, url, user, password);
    }

    return new DataSourceClasspathDecorator(dataSource, extraClasspath);
}

From source file:com.strandls.alchemy.inject.AlchemyModuleFilterConfiguration.java

/**
 * @return configuration read from the config file.
 *//*  www  .  j  a  v  a2 s .c  om*/
private Configuration readConfiguration() {
    final CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {
        config.addConfiguration(new HierarchicalINIConfiguration(MODULE_CONFIGURATION_NAME));
    } catch (final ConfigurationException e) {
        // ignore if the configuration file is missing. This means no
        // filtering intended.
        log.warn("Error loading configuration file {}", e);
    }
    return config;
}

From source file:com.runwaysdk.configuration.CommonsConfigurationTest.java

@Test
public void testCommonsConfigOverride() {
    BaseConfiguration bc = new BaseConfiguration();
    BaseConfiguration bc2 = new BaseConfiguration();

    bc2.addProperty("test.prop", 52);

    CompositeConfiguration cconfig = new CompositeConfiguration();
    cconfig.addConfiguration(bc);
    cconfig.addConfiguration(bc2);//from   ww  w  .j av a2s .c om

    bc.addProperty("test.prop", 112);

    Assert.assertEquals(112, cconfig.getInt("test.prop"));
}

From source file:com.runwaysdk.configuration.CommonsConfigurationTest.java

@Test
public void testCommonsConfigOverrideSetVsAdd() {
    BaseConfiguration bc = new BaseConfiguration();
    BaseConfiguration bc2 = new BaseConfiguration();

    bc2.addProperty("test.prop", 52);

    CompositeConfiguration cconfig = new CompositeConfiguration();
    cconfig.addConfiguration(bc);
    cconfig.addConfiguration(bc2);//from   w w  w. j  a v  a  2 s  . c  o m

    bc.setProperty("test.prop", 112);

    Assert.assertEquals(112, cconfig.getInt("test.prop"));
}

From source file:com.intel.mtwilson.fs.ConfigurableFilesystem.java

/**
 * First priority is the configuration that is passed in.
 * Second is the java system properties specified on command line like -Dfs.name
 * Third is exported environment variables like FS_NAME
 * /*w  ww . j a  v a2  s  .  c o  m*/
 * @param configuration 
 */
public ConfigurableFilesystem(Configuration configuration) {
    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(configuration);
    SystemConfiguration system = new SystemConfiguration();
    composite.addConfiguration(system);
    EnvironmentConfiguration env = new EnvironmentConfiguration();
    composite.addConfiguration(env);
    AllCapsEnvironmentConfiguration envAllCaps = new AllCapsEnvironmentConfiguration();
    composite.addConfiguration(envAllCaps);
    this.configuration = composite;
}

From source file:com.runwaysdk.configuration.CommonsConfigurationResolver.java

public ConfigurationReaderIF getReader(ConfigGroupIF configGroup, String config) {
    CompositeConfiguration _cconfig = new CompositeConfiguration();
    _cconfig.addConfiguration(this.cconfig);

    return new CommonsConfigurationReader(configGroup, config, _cconfig);
}