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

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

Introduction

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

Prototype

public XMLConfiguration() 

Source Link

Document

Creates a new instance of XMLConfiguration.

Usage

From source file:logica.EstacionMet.java

@Override
public Stack<PaqueteDatos> actualizar() {
    // Informacion para PaqueteDatos()
    Integer[] sensoresID = new Integer[redSensores.length];
    String[] tipo = new String[redSensores.length];
    String[] medicion = new String[redSensores.length];

    // Cargo el resumen de la estacion si es que existe.
    // Instancio el manejador de XML
    XMLConfiguration registro = new XMLConfiguration();
    registro.setFileName(String.format("resumenes/%d.xml", ID));

    try {//from   www  .j  a v a 2  s. c  o  m
        // Cargo si existe el registro
        registro.load();
    } catch (ConfigurationException ex) {
        // Si no existe, simplemente seteo el nombre del elemento base
        registro.setRootElementName("resumen");
        // Y creo el archivo
        try {
            registro.save();
        } catch (ConfigurationException ex1) {
            LOGGER.log(Level.SEVERE, null, ex1);
        }
    }

    // Datos de las sub-estaciones
    medidasPila = super.actualizar();

    // Busco y guardo las mediciones de los sensores.
    int largo = redSensores.length;
    for (int i = 0; i < largo; i++) {
        if (redSensores[i] != null) {
            sensoresID[i] = redSensores[i].getID();
            tipo[i] = redSensores[i].getClass().getSimpleName();
            medicion[i] = redSensores[i].getMedicion();
            resumenSave(registro, sensoresID[i], tipo[i], medicion[i]);
        }
    }

    // Agrego el los datos de esta estacion al final de los datos de las sub-estaciones
    medidasPila.push(new PaqueteDatos(ID, getHora(), sensoresID, tipo, medicion));

    return medidasPila;
}

From source file:com.intuit.tank.vm.settings.BaseCommonsXmlConfigCpTest.java

/**
 * Run the File getSourceConfigFile() method test.
 * //w w  w.j  ava 2s .  c o m
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/3/14 3:44 PM
 */
@Test
public void testGetSourceConfigFile_1() throws Exception {
    MailMessageConfig fixture = new MailMessageConfig();
    fixture.config = new XMLConfiguration();
    fixture.configFile = new File("");

    File result = fixture.getSourceConfigFile();

    // An unexpected exception was thrown in user code while executing this test:
    // java.lang.SecurityException: Cannot write to files while generating test cases
    // at
    // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490)
    // at
    // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204)
    // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63)
    // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71)
    assertNotNull(result);
}

From source file:com.evolveum.midpoint.init.StartupConfiguration.java

private void createXmlConfiguration(DocumentBuilder documentBuilder, String filename)
        throws ConfigurationException {
    XMLConfiguration xmlConfig = new XMLConfiguration();
    xmlConfig.setDocumentBuilder(documentBuilder);
    xmlConfig.setFileName(filename);//from w w  w. j  a va2 s.  c  om
    xmlConfig.load();
    config.addConfiguration(xmlConfig);

    xmlConfigAsDocument = DOMUtil.parseFile(filename);
}

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
 *//*from   ww w.ja v  a 2 s  .  c o  m*/
@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
 *///from  ww w  .j  ava 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:com.intuit.tank.vm.settings.BaseCommonsXmlConfigCpTest.java

/**
 * Run the boolean needsReload() method test.
 * //from   ww w. j a va2 s. co m
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/3/14 3:44 PM
 */
@Test
public void testNeedsReload_2() throws Exception {
    MailMessageConfig fixture = new MailMessageConfig();
    fixture.config = new XMLConfiguration();
    fixture.configFile = new File("");

    boolean result = fixture.needsReload();

    // An unexpected exception was thrown in user code while executing this test:
    // java.lang.SecurityException: Cannot write to files while generating test cases
    // at
    // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490)
    // at
    // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204)
    // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63)
    // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71)
    assertFalse(result);
}

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

/**
 * Validates that the connections that have been invalidated are removed from the pool properly.
 * @throws ConfigurationException if there is a problem setting up the default test connection
 * @throws RserveException if there is an issue connecting with an Rserver
 *//*from ww  w. j a v a 2  s.c o m*/
@Test
public void invalidateConnection() 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());

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

    pool.invalidateConnection(connection);

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

    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());
}

From source file:com.intuit.tank.vm.settings.BaseCommonsXmlConfigCpTest.java

/**
 * Run the boolean needsReload() method test.
 * /* w  w  w  . j  a va2s . c om*/
 * @throws Exception
 * 
 * @generatedBy CodePro at 9/3/14 3:44 PM
 */
@Test
public void testNeedsReload_3() throws Exception {
    MailMessageConfig fixture = new MailMessageConfig();
    fixture.config = new XMLConfiguration();
    fixture.configFile = new File("");

    boolean result = fixture.needsReload();

    // An unexpected exception was thrown in user code while executing this test:
    // java.lang.SecurityException: Cannot write to files while generating test cases
    // at
    // com.instantiations.assist.eclipse.junit.CodeProJUnitSecurityManager.checkWrite(CodeProJUnitSecurityManager.java:76)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:209)
    // at java.io.FileOutputStream.<init>(FileOutputStream.java:171)
    // at org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:490)
    // at
    // org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:204)
    // at com.intuit.tank.settings.BaseCommonsXmlConfig.readConfig(BaseCommonsXmlConfig.java:63)
    // at com.intuit.tank.settings.MailMessageConfig.<init>(MailMessageConfig.java:71)
    assertFalse(result);
}

From source file:io.datalayer.conf.XmlConfigurationTest.java

/**
 * Tests setting an attribute on the root element.
 *//*www .j a  v  a  2  s .c o m*/
@Test
public void testSetRootAttribute() throws ConfigurationException {
    conf.setProperty("[@test]", "true");
    assertEquals("Root attribute not set", "true", conf.getString("[@test]"));
    conf.save(testSaveConf);
    XMLConfiguration checkConf = new XMLConfiguration();
    checkConf.setFile(testSaveConf);
    checkSavedConfig(checkConf);
    assertTrue("Attribute not found after save", checkConf.containsKey("[@test]"));
    checkConf.setProperty("[@test]", "newValue");
    checkConf.save();
    conf = checkConf;
    checkConf = new XMLConfiguration();
    checkConf.setFile(testSaveConf);
    checkSavedConfig(checkConf);
    assertEquals("Attribute not modified after save", "newValue", checkConf.getString("[@test]"));
}

From source file:logica.Estacion.java

/**
 * @brief Ubicacion de los resumenes, en un Vector<String>
 * /* w w w .  j  a  v  a  2s .c  o  m*/
 * Retorna la ubicacion de los resumenes de esta estacion y de sus 
 * sub-estaciones, en un Vector<String>.
 * Se guardan en esa forma, primero la direccion propia y luego la de las 
 * sub-estaciones.
 * 
 * @return Direccion donde se encuentra el resumen.
 */
public Vector<String> getResumen() {
    Vector<String> direcciones = new Vector();
    // Instancio el manejador de XML
    XMLConfiguration registro = new XMLConfiguration();
    registro.setFileName(String.format("resumenes/%d.xml", ID));

    // No es necesario crear el resumen si no existe
    //        if ( !registro.getFile().exists() ) {
    //            // Si no existe, simplemente seteo el nombre del elemento base
    //            registro.setRootElementName("resumen");
    //            // Y creo el archivo
    //            try {
    //                registro.save();
    //            } catch (ConfigurationException ex1) {
    //                LOGGER.log(Level.SEVERE, null, ex1);
    //            }
    //        }

    // getFileName() me devuelve la direccion dentro del proyecto.
    // getURL() me devuelve la direccion desde el root de la maquina.
    if (registro.getFile().exists())
        direcciones.add(registro.getFileName());

    for (Estacion subestacion : redEstaciones) {
        if (subestacion != null)
            direcciones.addAll(subestacion.getResumen());
    }

    return direcciones;
}