Example usage for org.apache.commons.configuration XMLConfiguration load

List of usage examples for org.apache.commons.configuration XMLConfiguration load

Introduction

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

Prototype

private void load(InputSource source) throws ConfigurationException 

Source Link

Document

Loads a configuration file from the specified input source.

Usage

From source file:at.gv.egiz.bku.spring.ConfigurationFactoryBean.java

protected Configuration getDefaultConfiguration() throws ConfigurationException, IOException {
    Resource resource = resourceLoader.getResource(DEFAULT_CONFIG);
    XMLConfiguration xmlConfiguration = new XMLConfiguration();
    xmlConfiguration.load(resource.getInputStream());
    xmlConfiguration.setURL(resource.getURL());
    return xmlConfiguration;
}

From source file:com.vaushell.superpipes.DaemonApp.java

@Override
public void init(final DaemonContext context) throws Exception {
    final String[] args = context.getArguments();

    // My config//from w  w  w.  j  a  va 2 s  .  c  om
    final XMLConfiguration config = new XMLConfiguration();
    config.setDelimiterParsingDisabled(true);

    final Path datas;
    switch (args.length) {
    case 1: {
        config.load(args[0]);
        datas = Paths.get("datas");
        break;
    }

    case 2: {
        config.load(args[0]);
        datas = Paths.get(args[1]);
        break;
    }

    default: {
        config.load("conf/configuration.xml");
        datas = Paths.get("datas");
        break;
    }
    }

    dispatcher.init(config, datas, new VC_FileFactory(datas));
}

From source file:elaborate.editor.config.Configuration.java

public XMLConfiguration load(Reader reader) {
    try {//from   w  w w .  ja  v a2s . c o  m
        messages = Maps.newTreeMap();
        AbstractConfiguration.setDefaultListDelimiter(',');
        XMLConfiguration config = new XMLConfiguration();
        config.clear();
        config.load(reader);
        processConfiguration(config);
        xmlConfig = config;
        return config;
    } catch (ConfigurationException e) {
        throw new RuntimeException("Failed to load configuration", e);
    }
}

From source file:edu.utexas.cs.tactex.core.BrokerPropertiesService.java

/**
 * Loads the properties from classpath, default config file,
 * and user-specified config file, just in case it's not already been
 * loaded. This is done when properties are first requested, to ensure
 * that the logger has been initialized. Because the CompositeConfiguration
 * treats its config sources in FIFO order, this should be called <i>after</i>
 * any user-specified config is loaded.//from w  ww. j  a va  2 s .c o  m
 */
void lazyInit() {
    // only do this once
    if (initialized)
        return;
    initialized = true;

    // find and load the default properties file
    log.debug("lazyInit");
    try {
        File defaultProps = new File("broker.properties");
        log.info("adding " + defaultProps.getName());
        config.addConfiguration(new PropertiesConfiguration(defaultProps));
    } catch (Exception e1) {
        log.warn("broker.properties not found: " + e1.toString());
    }

    // set up the classpath props
    try {
        Resource[] xmlResources = context.getResources("classpath*:config/properties.xml");
        for (Resource xml : xmlResources) {
            if (validXmlResource(xml)) {
                log.info("loading config from " + xml.getURI());
                XMLConfiguration xconfig = new XMLConfiguration();
                xconfig.load(xml.getInputStream());
                config.addConfiguration(xconfig);
            }
        }
        Resource[] propResources = context.getResources("classpath*:config/*.properties");
        for (Resource prop : propResources) {
            if (validPropResource(prop)) {
                if (null == prop) {
                    log.error("Null resource");
                }
                log.info("loading config from " + prop.getURI());
                PropertiesConfiguration pconfig = new PropertiesConfiguration();
                pconfig.load(prop.getInputStream());
                config.addConfiguration(pconfig);
            }
        }
    } catch (ConfigurationException e) {
        log.error("Problem loading configuration: " + e.toString());
    } catch (Exception e) {
        log.error("Error loading configuration: " + e.toString());
    }

    // set up the configurator
    configurator.setConfiguration(config);
}

From source file:com.bibisco.manager.ConfigManager.java

private XMLConfiguration getXMLConfiguration() {

    XMLConfiguration lXMLConfiguration = null;

    lXMLConfiguration = new XMLConfiguration();
    lXMLConfiguration.setEncoding(ENCODING);

    try {//from w  w  w. j av  a  2 s.  com
        lXMLConfiguration.setBasePath(CONFIG_DIR);
        lXMLConfiguration.load(CONFIG_FILENAME);
        lXMLConfiguration.setExpressionEngine(new XPathExpressionEngine());
    } catch (ConfigurationException e) {
        mLog.error(e, "Error while reading configuration from file ", CONFIG_FILENAME);
        throw new BibiscoException(e, "bibiscoException.configManager.errorWhileReadingConfiguration",
                CONFIG_FILENAME, e.getMessage());
    }
    return lXMLConfiguration;
}

From source file:com.gs.obevo.db.api.factory.DbEnvironmentXmlEnricher.java

private HierarchicalConfiguration getConfig(FileObject checkoutFolder) {
    XMLConfiguration config;
    try {//from w  ww .ja  v a 2  s.  c om
        config = new XMLConfiguration();
        config.load(getEnvFileToRead(checkoutFolder).getURLDa());
        return config;
    } catch (ConfigurationException exc) {
        throw new DeployerRuntimeException(exc);
    }
}

From source file:edu.cornell.med.icb.R.TestRConnectionPool.java

/**
 * Validates that an attempt to return an invalid connection to the pool throws an error.
 * @throws ConfigurationException if there is a problem setting up the default test connection
 *///w  w w  .j a va2  s  .c  o  m
@Test(expected = NullPointerException.class)
public void returnNullConnection() throws ConfigurationException {
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.load(new StringReader(POOL_CONFIGURATION_XML));
    pool = new RConnectionPool(configuration);
    pool.returnConnection(null);
}

From source file:edu.cornell.med.icb.R.TestRConnectionPool.java

/**
 * Validates that the pool can be shut down properly and also that attempting to
 * get a connection after the pool has been shutdown throws an error.
 * @throws ConfigurationException if there is a problem setting up the default test connection
 * @throws RserveException if there is an issue connecting with an Rserver
 *//* www .  j  ava  2s.  c om*/
@Test(expected = IllegalStateException.class)
public void borrowConnectionAfterShutdown() throws ConfigurationException, RserveException {
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.load(new StringReader(POOL_CONFIGURATION_XML));
    pool = new RConnectionPool(configuration);
    assertNotNull("Connection pool should never be null", pool);
    assertFalse("Everybody in - the pool should be open!", pool.isClosed());

    pool.close();
    assertNotNull("Connection pool should never be null", pool);
    assertTrue("Everybody out of the pool!", pool.isClosed());

    assertEquals("There should be no connections", 0, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("No connections should be idle", 0, pool.getNumberOfIdleConnections());

    pool.borrowConnection();
}

From source file:edu.cornell.med.icb.R.TestRConnectionPool.java

/**
 * Validates that the pool can be shut down properly and also that attempting to
 * return a connection after the pool has been shutdown throws an error.
 * @throws ConfigurationException if there is a problem setting up the default test connection
 * @throws RserveException if there is a problem with the connection to the Rserve process
 *///w w  w .j av  a 2  s. c  o  m
@Test(expected = IllegalStateException.class)
public void returnConnectionAfterShutdown() throws ConfigurationException, RserveException {
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.load(new StringReader(POOL_CONFIGURATION_XML));
    pool = new RConnectionPool(configuration);

    final RConnection connection = pool.borrowConnection();
    assertNotNull("Connection should not be null", connection);
    assertTrue("The connection should be connected to the server", connection.isConnected());

    pool.close();
    assertNotNull("Connection pool should never be null", pool);
    assertTrue("Everybody out of the pool!", pool.isClosed());

    assertEquals("There should be no connections", 0, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("No connections should be idle", 0, pool.getNumberOfIdleConnections());

    assertNotNull("Connection should not be null", connection);
    assertFalse("The connection should not be connected to the server", connection.isConnected());

    pool.returnConnection(connection);
}

From source file:edu.cornell.med.icb.R.TestRConnectionPool.java

/**
 * Validates that a pool can be reopened after it has been closed.
 * @throws ConfigurationException if there is a problem setting up the default test connection
 *//*w w  w  . jav  a2s  .  c o  m*/
@Test
public void closeAndReopen() throws ConfigurationException {
    final XMLConfiguration configuration = new XMLConfiguration();
    configuration.load(new StringReader(POOL_CONFIGURATION_XML));
    pool = new RConnectionPool(configuration);

    assertFalse("The pool should be open", pool.isClosed());
    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("The connections should be idle", 1, pool.getNumberOfIdleConnections());

    pool.close();

    assertEquals("There should be no connections", 0, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("No connections should be idle", 0, pool.getNumberOfIdleConnections());
    assertTrue("The pool should be closed", pool.isClosed());

    pool.reopen();

    assertFalse("The pool should be open", pool.isClosed());
    assertEquals("There should be one connection", 1, pool.getNumberOfConnections());
    assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections());
    assertEquals("The connections should be idle", 1, pool.getNumberOfIdleConnections());
}