Example usage for org.apache.commons.configuration Configuration getProperty

List of usage examples for org.apache.commons.configuration Configuration getProperty

Introduction

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

Prototype

Object getProperty(String key);

Source Link

Document

Gets a property from the configuration.

Usage

From source file:com.vmware.qe.framework.datadriven.config.DDConfig.java

/**
 * Overrides the properties that exist in original configuration with the properties specified
 * in new configuration, if they already exist. Otherwise, they are added.
 * //from  w w  w  . j  av a 2s  .  c  o m
 * @param orgConfig original configuration
 * @param newConfig new configuration
 */
private static Configuration overrideConfigProperties(Configuration orgConfig, Configuration newConfig) {
    if (newConfig == null) {
        return orgConfig;
    }
    if (orgConfig == null) {
        return newConfig;
    }
    Iterator<String> itr = newConfig.getKeys();
    while (itr.hasNext()) {
        String key = itr.next();
        orgConfig.setProperty(key, newConfig.getProperty(key));
    }
    return orgConfig;
}

From source file:com.comcast.viper.flume2storm.connection.parameters.SimpleConnectionParameters.java

/**
 * @param configuration//from ww w. j  a  v  a 2 s.  c  om
 *          The configuration to use
 * @return The newly built {@link SimpleConnectionParameters} based on the
 *         configuration specified
 * @throws F2SConfigurationException
 *           If the configuration is invalid
 */
public static SimpleConnectionParameters from(Configuration configuration) throws F2SConfigurationException {
    SimpleConnectionParameters result = new SimpleConnectionParameters();
    try {
        result.setHostname(configuration.getString(HOSTNAME, HOSTNAME_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(HOSTNAME, configuration.getProperty(HOSTNAME), e);
    }
    try {
        result.setPort(configuration.getInt(PORT, PORT_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(PORT, configuration.getProperty(PORT), e);
    }
    return result;
}

From source file:com.comcast.viper.flume2storm.spout.FlumeSpoutConfiguration.java

/**
 * @param configuration/*from   ww  w.j a va  2s  .c  o  m*/
 *          A configuration object
 * @return A map that contains the configuration key/values (in order to
 *         serialize it via Kryo)
 */
protected static Map<String, Object> getMapFromConfiguration(Configuration configuration) {
    Map<String, Object> result = new HashMap<String, Object>();
    Iterator<?> it = configuration.getKeys();
    while (it.hasNext()) {
        String key = it.next().toString();
        result.put(key, configuration.getProperty(key));
    }
    return result;
}

From source file:com.netflix.config.util.ConfigurationUtils.java

/**
 * Utility method to obtain <code>Properties</code> given an instance of <code>AbstractConfiguration</code>.
 * Returns an empty <code>Properties</code> object if the config has no properties or is null.
 * @param config Configuration to get the properties
 * @return properties extracted from the configuration
 *//*w  w  w. j  ava2s. c  o m*/
public static Properties getProperties(Configuration config) {
    Properties p = new Properties();
    if (config != null) {
        Iterator<String> it = config.getKeys();
        while (it.hasNext()) {
            String key = it.next();
            if (key != null) {
                Object value = config.getProperty(key);
                if (value != null) {
                    p.put(key, value);
                }
            }
        }
    }
    return p;
}

From source file:com.github.mbredel.commons.configuration.ConfigurationAssert.java

/**
 * Checks the content of a configuration.
 *
 * @param expected the expected properties
 * @param actual the configuration to check
 *///from w ww  .  j a  v a 2 s  .  c o  m
@SuppressWarnings("unused")
public static void assertEquals(Configuration expected, Configuration actual) {
    // check that the actual configuration contains all the properties of the expected configuration
    for (Iterator<String> it = expected.getKeys(); it.hasNext();) {
        String key = it.next();
        Assert.assertTrue("The actual configuration doesn't contain the expected key '" + key + "'",
                actual.containsKey(key));
        Assert.assertEquals("Value of the '" + key + "' property", expected.getProperty(key),
                actual.getProperty(key));
    }

    // check that the actual configuration has no extra properties
    for (Iterator<String> it = actual.getKeys(); it.hasNext();) {
        String key = it.next();
        Assert.assertTrue("The actual configuration contains an extra key '" + key + "'",
                expected.containsKey(key));
    }
}

From source file:com.netflix.config.ConcurrentCompositeConfiguration.java

/**
 * Adds the value of a property to the given list. This method is used by
 * {@code getList()} for gathering property values from the child
 * configurations.// w ww  . j  a  v a 2  s. c o  m
 *
 * @param dest the list for collecting the data
 * @param config the configuration to query
 * @param key the key of the property
 */
private static void appendListProperty(List<Object> dest, Configuration config, String key) {
    Object value = config.getProperty(key);
    if (value != null) {
        if (value instanceof Collection) {
            Collection<?> col = (Collection<?>) value;
            dest.addAll(col);
        } else {
            dest.add(value);
        }
    }
}

From source file:com.yahoo.pulsar.zookeeper.ZkIsolatedBookieEnsemblePlacementPolicy.java

@Override
public EnsemblePlacementPolicy initialize(Configuration conf) {
    if (conf.getProperty(ISOLATION_BOOKIE_GROUPS) != null) {
        String isolationGroupsString = (String) conf.getProperty(ISOLATION_BOOKIE_GROUPS);
        if (!isolationGroupsString.isEmpty()) {
            for (String isolationGroup : isolationGroupsString.split(",")) {
                isolationGroups.add(isolationGroup);
            }/* w w  w.  j  a  v a  2 s . c  o m*/
            bookieMappingCache = getAndSetZkCache(conf);
        }
    }
    super.initialize(conf);
    return this;
}

From source file:com.netflix.config.ConfigurationBasedDeploymentContext.java

private String getValueFromConfig(String name) {
    Configuration conf = ConfigurationManager.getConfigInstance();
    String value = (String) conf.getProperty(name);
    if (value != null) {
        return value;
    } else {/*  w w  w . ja v a 2s .co  m*/
        value = System.getProperty(name);
        if (value != null) {
            return value;
        }
    }
    return null;
}

From source file:com.flipkart.flux.MigrationUtil.MigrationsRunner.java

public void migrate(String dbName) {
    try {//  w  ww. ja  v  a2  s .c  o  m
        Configuration configuration = yamlConfiguration.subset(dbName + ".Hibernate");
        Properties properties = new Properties();
        properties.put("user", configuration.getProperty("hibernate.connection.username"));
        properties.put("password", configuration.getProperty("hibernate.connection.password"));
        String url = (String) configuration.getProperty("hibernate.connection.url");
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        java.sql.Connection connection = DriverManager.getConnection(url, properties);
        Database database = DatabaseFactory.getInstance()
                .findCorrectDatabaseImplementation(new JdbcConnection(connection));
        ClassLoader classLoader = getClass().getClassLoader();
        File file = new File(classLoader.getResource(dbName + "/migrations.xml").getFile());
        Liquibase liquibase = new Liquibase(file.getCanonicalPath(), new FileSystemResourceAccessor(),
                database);
        liquibase.update(new Contexts());
    } catch (Exception e) {
        System.err.println("Unable to perform database migration.");
        e.printStackTrace();
    }
}

From source file:net.krotscheck.jersey2.configuration.Jersey2ToolkitConfigTest.java

/**
 * Assert that a property may be read.//from   www . j  a va2  s  . co  m
 */
@Test
public void testReadFileProperty() {
    Configuration config = new Jersey2ToolkitConfig();
    Assert.assertEquals("value1", config.getProperty("property1"));
    Assert.assertEquals("value2", config.getProperty("property2"));
}