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:it.grid.storm.namespace.config.xml.XMLNamespaceLoader.java

private void init(String namespaceFileName, int refresh) {

    log.info("Reading Namespace configuration file " + namespaceFileName + " and setting refresh rate to "
            + refresh + " seconds.");

    // create reloading strategy for refresh
    xmlStrategy = new XMLReloadingStrategy();
    period = 3000; // Conversion in millisec.
    log.debug(" Refresh time is " + period + " millisec");
    xmlStrategy.setRefreshDelay(period); // Set to refresh sec the refreshing
                                         // delay.

    namespaceFN = namespaceFileName;/* w ww. ja  v  a 2s .c  o m*/

    // specify the properties file and set the reloading strategy for that file
    try {
        config = new XMLConfiguration();
        config.setFileName(namespaceFileName);

        // Validation of Namespace.xml
        log.debug(" ... CHECK of VALIDITY of NAMESPACE Configuration ...");

        schemaValidity = XMLNamespaceLoader.checkValidity(namespaceSchemaURL, namespaceFileName);
        if (!(schemaValidity)) {
            log.error("NAMESPACE IS NOT VALID IN RESPECT OF NAMESPACE SCHEMA! ");
            throw new ConfigurationException("XML is not valid!");
        } else {
            log.debug("Namespace is valid in respect of NAMESPACE SCHEMA.");
        }

        // This will throw a ConfigurationException if the XML document does not
        // conform to its DTD.

        config.setReloadingStrategy(xmlStrategy);

        Peeper peeper = new Peeper(this);
        timer.schedule(peeper, delay, period);

        log.debug("Timer initialized");

        config.load();
        log.debug("Namespace Configuration read!");

    } catch (ConfigurationException cex) {
        log.error("ATTENTION! Unable to load Namespace Configuration!");
        log.error(toString());
    }

}

From source file:cn.quickj.Setting.java

private static void loadApplicationConfig() {
    XMLConfiguration config;/*from  w w  w .  j a va2s .  c  o m*/
    try {
        config = new XMLConfiguration();
        // ??????
        config.setDelimiterParsingDisabled(true);
        String appconfigPath = webRoot + "WEB-INF/appconfig.xml";
        config.load(appconfigPath);
    } catch (Exception e) {
        config = null;
    }
    String className = null;
    if (config != null)
        className = config.getString("class", null);
    if (className != null) {
        try {
            Class<?> clazz = Class.forName(className);
            appconfig = (ApplicationConfig) clazz.newInstance();
            appconfig.init(config);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("?appconfig.xml?!" + e.getCause());
            appconfig = null;
        }
    }
}

From source file:com.egreen.tesla.server.api.component.Component.java

/**
 *
 * Init configurations from Component/*from w ww  .  j a v a 2  s .  co  m*/
 *
 * @param jf
 * @throws IOException
 * @throws ConfigurationException
 */
private void setConfiguraton(JarFile jf) throws IOException, ConfigurationException {
    JarEntry entry = jf.getJarEntry(TESLAR_WIDGET_MAINIFIESTXML);

    InputStream inputStream = jf.getInputStream(entry);
    configuration = new XMLConfiguration();
    configuration.load(inputStream);
    componentID = configuration.getString(Settings.COMPONENT_ID.getType());

    LOGGER.info("Loadding : " + componentID);

    component_base = context.getRealPath("/") + "/components/" + componentID;
}

From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLReader.java

private XMLConfiguration createXMLConfiguration() {
    XMLConfiguration xmlConfig = new XMLConfiguration();
    xmlConfig.setAttributeSplittingDisabled(true);
    xmlConfig.setDelimiterParsingDisabled(true);

    if (schemaValidation) {
        final InputStream resource = Resource.getAsInputStream("vrp_xml_schema.xsd");
        if (resource != null) {
            EntityResolver resolver = new EntityResolver() {

                @Override//www . j  a v a 2s  .  c  om
                public InputSource resolveEntity(String publicId, String systemId)
                        throws SAXException, IOException {
                    {
                        InputSource is = new InputSource(resource);
                        return is;
                    }
                }
            };
            xmlConfig.setEntityResolver(resolver);
            xmlConfig.setSchemaValidation(true);
        } else {
            logger.debug(
                    "cannot find schema-xsd file (vrp_xml_schema.xsd). try to read xml without xml-file-validation.");
        }
    }
    return xmlConfig;
}

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

/**
 * Validates that the connection pool will not allow connections to be handed out
 * when no valid servers were set./* w  w  w . j  a  v a  2s .c  o m*/
 * @throws RserveException if there is an issue connecting with an Rserver
 */
@Test(expected = IllegalStateException.class)
public void noValidServers() throws RserveException {
    // set up a pool with an empty configuration
    pool = new RConnectionPool(new XMLConfiguration());
    assertNotNull("Connection pool should never be null", pool);
    assertTrue("The pool should not be open", pool.isClosed());
    assertEquals("There should be no connections", 0, pool.getNumberOfConnections());
    assertEquals("There should be no connections", 0, pool.getNumberOfActiveConnections());
    assertEquals("There should be no connections", 0, pool.getNumberOfIdleConnections());

    // if we try to get a connection, we shouldn't be able to - there are none configured
    pool.borrowConnection();
}

From source file:keel.Algorithms.Neural_Networks.NNEP_Regr.KEELWrapperRegr.java

/**
 * <p>//from   ww w .j  a  v  a 2  s  . c  o  m
 * Configure the execution of the algorithm.
 * </p>
 * @param jobFilename Name of the KEEL file with properties of the
 *                    execution
 */

@SuppressWarnings("unchecked")
private static void configureJob(String jobFilename) {

    Properties props = new Properties();

    try {
        InputStream paramsFile = new FileInputStream(jobFilename);
        props.load(paramsFile);
        paramsFile.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
        System.exit(0);
    }

    // Files training and test
    String trainFile;
    String testFile;
    StringTokenizer tokenizer = new StringTokenizer(props.getProperty("inputData"));
    tokenizer.nextToken();
    trainFile = tokenizer.nextToken();
    trainFile = trainFile.substring(1, trainFile.length() - 1);
    testFile = tokenizer.nextToken();
    testFile = testFile.substring(1, testFile.length() - 1);

    // Classification or Regression ??
    byte[] schema = null;
    try {
        schema = readSchema(trainFile);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DatasetException e) {
        e.printStackTrace();
    }

    // Algorithm auxiliar configuration
    XMLConfiguration algConf = new XMLConfiguration();
    algConf.setRootElementName("algorithm");
    algConf.addProperty("population-size", 1000);
    algConf.addProperty("max-of-generations", Integer.parseInt(props.getProperty("Generations")));
    algConf.addProperty("creation-ratio", 10.0);
    algConf.addProperty("percentage-second-mutator", 10);
    algConf.addProperty("max-generations-without-improving-mean", 20);
    algConf.addProperty("max-generations-without-improving-best", 20);
    algConf.addProperty("fitness-difference", 0.0000001);
    algConf.addProperty("species[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Common.NeuralNetIndividualSpecies");
    algConf.addProperty("species.neural-net-type",
            "keel.Algorithms.Neural_Networks.NNEP_Regr.neuralnet.NeuralNetRegressor");
    if (props.getProperty("Transfer").equals("Product_Unit")) {
        algConf.addProperty("species.hidden-layer[@type]",
                "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.ExpLayer");
        algConf.addProperty("species.hidden-layer[@biased]", false);
        algConf.addProperty("evaluator[@log-input-data]", true);
    } else {
        algConf.addProperty("species.hidden-layer[@type]",
                "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.SigmLayer");
        algConf.addProperty("species.hidden-layer[@biased]", true);
    }
    int neurons = Integer.parseInt(props.getProperty("Hidden_nodes"));
    algConf.addProperty("species.hidden-layer.minimum-number-of-neurons",
            (neurons / 3) != 0 ? (neurons / 3) : 1);
    algConf.addProperty("species.hidden-layer.initial-maximum-number-of-neurons",
            (neurons / 2) != 0 ? (neurons / 2) : 1);
    algConf.addProperty("species.hidden-layer.maximum-number-of-neurons", neurons);
    algConf.addProperty("species.hidden-layer.initiator-of-links",
            "keel.Algorithms.Neural_Networks.NNEP_Common.initiators.RandomInitiator");
    algConf.addProperty("species.hidden-layer.weight-range[@type]", "net.sf.jclec.util.range.Interval");
    algConf.addProperty("species.hidden-layer.weight-range[@closure]", "closed-closed");
    algConf.addProperty("species.hidden-layer.weight-range[@left]", -5.0);
    algConf.addProperty("species.hidden-layer.weight-range[@right]", 5.0);
    algConf.addProperty("species.output-layer[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.LinearLayer");
    algConf.addProperty("species.output-layer[@biased]", true);
    algConf.addProperty("species.output-layer.initiator-of-links",
            "keel.Algorithms.Neural_Networks.NNEP_Common.initiators.RandomInitiator");
    algConf.addProperty("species.output-layer.weight-range[@type]", "net.sf.jclec.util.range.Interval");
    algConf.addProperty("species.output-layer.weight-range[@closure]", "closed-closed");
    algConf.addProperty("species.output-layer.weight-range[@left]", -5.0);
    algConf.addProperty("species.output-layer.weight-range[@right]", 5.0);

    algConf.addProperty("evaluator[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Regr.problem.regression.RegressionProblemEvaluator");

    algConf.addProperty("evaluator[@normalize-data]", true);

    algConf.addProperty("evaluator.error-function",
            "keel.Algorithms.Neural_Networks.NNEP_Regr.problem.errorfunctions.MSEErrorFunction");

    algConf.addProperty("evaluator.input-interval[@closure]", "closed-closed");
    if (props.getProperty("Transfer").equals("Product_Unit")) {
        algConf.addProperty("evaluator.input-interval[@left]", 1.0);
        algConf.addProperty("evaluator.input-interval[@right]", 2.0);
    } else {
        algConf.addProperty("evaluator.input-interval[@left]", 0.1);
        algConf.addProperty("evaluator.input-interval[@right]", 0.9);
    }

    algConf.addProperty("evaluator.output-interval[@closure]", "closed-closed");

    algConf.addProperty("evaluator.output-interval[@left]", 1.0);
    algConf.addProperty("evaluator.output-interval[@right]", 2.0);

    algConf.addProperty("provider[@type]", "keel.Algorithms.Neural_Networks.NNEP_Common.NeuralNetCreator");
    algConf.addProperty("mutator1[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Common.mutators.structural.StructuralMutator");
    algConf.addProperty("mutator1.temperature-exponent[@value]", 1.0);
    algConf.addProperty("mutator1.significative-weigth[@value]", 0.0000001);
    algConf.addProperty("mutator1.neuron-ranges.added[@min]", 1);
    algConf.addProperty("mutator1.neuron-ranges.added[@max]", 2);
    algConf.addProperty("mutator1.neuron-ranges.deleted[@min]", 1);
    algConf.addProperty("mutator1.neuron-ranges.deleted[@max]", 2);

    algConf.addProperty("mutator1.links-ranges[@relative]", false);
    algConf.addProperty("mutator1.links-ranges.added[@min]", 1);
    algConf.addProperty("mutator1.links-ranges.added[@max]", 6);
    algConf.addProperty("mutator1.links-ranges.deleted[@min]", 1);
    algConf.addProperty("mutator1.links-ranges.deleted[@max]", 6);
    algConf.addProperty("mutator2[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Common.mutators.parametric.ParametricSAMutator");

    algConf.addProperty("mutator2.temperature-exponent[@value]", 0.0);
    algConf.addProperty("mutator2.amplitude[@value]", 5.0);
    algConf.addProperty("mutator2.fitness-difference[@value]", 0.0000001);
    algConf.addProperty("mutator2.initial-alpha-values[@input]", 0.5);
    algConf.addProperty("mutator2.initial-alpha-values[@output]", 1.0);
    algConf.addProperty("rand-gen-factory[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Common.util.random.RanNnepFactory");
    algConf.addProperty("rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed")));

    // Neural Net Algorithm
    algorithm = new NeuralNetAlgorithm<NeuralNetIndividual>();

    algorithm.configure(algConf);

    // Read data
    ProblemEvaluator evaluator = (ProblemEvaluator) algorithm.getEvaluator();
    evaluator.readData(schema, new KeelDataSet(trainFile), new KeelDataSet(testFile));
    ((NeuralNetIndividualSpecies) algorithm.getSpecies()).setNOfInputs(evaluator.getTrainData().getNofinputs());
    ((NeuralNetIndividualSpecies) algorithm.getSpecies())
            .setNOfOutputs(evaluator.getTrainData().getNofoutputs());

    // Read output files
    tokenizer = new StringTokenizer(props.getProperty("outputData"));
    String trainResultFile = tokenizer.nextToken();
    trainResultFile = trainResultFile.substring(1, trainResultFile.length() - 1);
    consoleReporter.setTrainResultFile(trainResultFile);
    String testResultFile = tokenizer.nextToken();
    testResultFile = testResultFile.substring(1, testResultFile.length() - 1);
    consoleReporter.setTestResultFile(testResultFile);
    String bestModelResultFile = tokenizer.nextToken();
    bestModelResultFile = bestModelResultFile.substring(1, bestModelResultFile.length() - 1);
    consoleReporter.setBestModelResultFile(bestModelResultFile);

    listeners.add(consoleReporter);
}

From source file:br.gov.frameworkdemoiselle.internal.implementation.ConfigurationLoader.java

private org.apache.commons.configuration.Configuration createConfiguration() {
    AbstractConfiguration config;/*ww  w  .  j a v a2s. c o  m*/

    switch (this.type) {
    case XML:
        config = new XMLConfiguration();
        break;

    case SYSTEM:
        config = new SystemConfiguration();
        break;

    default:
        config = new PropertiesConfiguration();
    }

    config.setDelimiterParsingDisabled(true);
    return config;
}

From source file:keel.Algorithms.Neural_Networks.NNEP_Clas.KEELWrapperClas.java

/**
 * <p>//from ww w.j a  v  a2s.c  o m
 * Configure the execution of the algorithm.
 * 
 * @param jobFilename Name of the KEEL file with properties of the
 *                    execution
 *  </p>                  
 */

@SuppressWarnings("unchecked")
private static void configureJob(String jobFilename) {

    Properties props = new Properties();

    try {
        InputStream paramsFile = new FileInputStream(jobFilename);
        props.load(paramsFile);
        paramsFile.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
        System.exit(0);
    }

    // Files training and test
    String trainFile;
    String testFile;
    StringTokenizer tokenizer = new StringTokenizer(props.getProperty("inputData"));
    tokenizer.nextToken();
    trainFile = tokenizer.nextToken();
    trainFile = trainFile.substring(1, trainFile.length() - 1);
    testFile = tokenizer.nextToken();
    testFile = testFile.substring(1, testFile.length() - 1);

    // Classification or Regression ??
    byte[] schema = null;
    try {
        schema = readSchema(trainFile);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DatasetException e) {
        e.printStackTrace();
    }

    // Algorithm auxiliar configuration
    XMLConfiguration algConf = new XMLConfiguration();
    algConf.setRootElementName("algorithm");
    algConf.addProperty("population-size", 1000);
    algConf.addProperty("max-of-generations", Integer.parseInt(props.getProperty("Generations")));
    algConf.addProperty("creation-ratio", 10.0);
    algConf.addProperty("percentage-second-mutator", 10);
    algConf.addProperty("max-generations-without-improving-mean", 20);
    algConf.addProperty("max-generations-without-improving-best", 20);
    algConf.addProperty("fitness-difference", 0.0000001);
    algConf.addProperty("species[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Common.NeuralNetIndividualSpecies");
    algConf.addProperty("species.neural-net-type",
            "keel.Algorithms.Neural_Networks.NNEP_Clas.neuralnet.NeuralNetClassifier");
    if (props.getProperty("Transfer").equals("Product_Unit")) {
        algConf.addProperty("species.hidden-layer[@type]",
                "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.ExpLayer");
        algConf.addProperty("species.hidden-layer[@biased]", false);
        algConf.addProperty("evaluator[@log-input-data]", true);
    } else {
        algConf.addProperty("species.hidden-layer[@type]",
                "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.SigmLayer");
        algConf.addProperty("species.hidden-layer[@biased]", true);
    }
    int neurons = Integer.parseInt(props.getProperty("Hidden_nodes"));
    algConf.addProperty("species.hidden-layer.minimum-number-of-neurons",
            (neurons / 3) != 0 ? (neurons / 3) : 1);
    algConf.addProperty("species.hidden-layer.initial-maximum-number-of-neurons",
            (neurons / 2) != 0 ? (neurons / 2) : 1);
    algConf.addProperty("species.hidden-layer.maximum-number-of-neurons", neurons);
    algConf.addProperty("species.hidden-layer.initiator-of-links",
            "keel.Algorithms.Neural_Networks.NNEP_Common.initiators.RandomInitiator");
    algConf.addProperty("species.hidden-layer.weight-range[@type]", "net.sf.jclec.util.range.Interval");
    algConf.addProperty("species.hidden-layer.weight-range[@closure]", "closed-closed");
    algConf.addProperty("species.hidden-layer.weight-range[@left]", -5.0);
    algConf.addProperty("species.hidden-layer.weight-range[@right]", 5.0);
    algConf.addProperty("species.output-layer[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.LinearLayer");
    algConf.addProperty("species.output-layer[@biased]", true);
    algConf.addProperty("species.output-layer.initiator-of-links",
            "keel.Algorithms.Neural_Networks.NNEP_Common.initiators.RandomInitiator");
    algConf.addProperty("species.output-layer.weight-range[@type]", "net.sf.jclec.util.range.Interval");
    algConf.addProperty("species.output-layer.weight-range[@closure]", "closed-closed");
    algConf.addProperty("species.output-layer.weight-range[@left]", -5.0);
    algConf.addProperty("species.output-layer.weight-range[@right]", 5.0);
    algConf.addProperty("evaluator[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Clas.problem.classification.softmax.SoftmaxClassificationProblemEvaluator");

    algConf.addProperty("evaluator[@normalize-data]", true);

    algConf.addProperty("evaluator.error-function",
            "keel.Algorithms.Neural_Networks.NNEP_Clas.problem.errorfunctions.LogisticErrorFunction");

    algConf.addProperty("evaluator.input-interval[@closure]", "closed-closed");

    if (props.getProperty("Transfer").equals("Product_Unit")) {
        algConf.addProperty("evaluator.input-interval[@left]", 1.0);
        algConf.addProperty("evaluator.input-interval[@right]", 2.0);
    } else {
        algConf.addProperty("evaluator.input-interval[@left]", 0.1);
        algConf.addProperty("evaluator.input-interval[@right]", 0.9);
    }

    algConf.addProperty("evaluator.output-interval[@closure]", "closed-closed");

    algConf.addProperty("evaluator.output-interval[@left]", 0.0);
    algConf.addProperty("evaluator.output-interval[@right]", 1.0);

    algConf.addProperty("provider[@type]", "keel.Algorithms.Neural_Networks.NNEP_Common.NeuralNetCreator");
    algConf.addProperty("mutator1[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Common.mutators.structural.StructuralMutator");
    algConf.addProperty("mutator1.temperature-exponent[@value]", 1.0);
    algConf.addProperty("mutator1.significative-weigth[@value]", 0.0000001);
    algConf.addProperty("mutator1.neuron-ranges.added[@min]", 1);
    algConf.addProperty("mutator1.neuron-ranges.added[@max]", 2);
    algConf.addProperty("mutator1.neuron-ranges.deleted[@min]", 1);
    algConf.addProperty("mutator1.neuron-ranges.deleted[@max]", 2);
    algConf.addProperty("mutator1.links-ranges[@relative]", true);
    algConf.addProperty("mutator1.links-ranges.percentages[@hidden]", 30);
    algConf.addProperty("mutator1.links-ranges.percentages[@output]", 5);
    algConf.addProperty("mutator2[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Common.mutators.parametric.ParametricSRMutator");
    algConf.addProperty("mutator2.temperature-exponent[@value]", 0.0);
    algConf.addProperty("mutator2.amplitude[@value]", 5.0);
    algConf.addProperty("mutator2.fitness-difference[@value]", 0.0000001);
    algConf.addProperty("mutator2.initial-alpha-values[@input]", 0.5);
    algConf.addProperty("mutator2.initial-alpha-values[@output]", 1.0);
    algConf.addProperty("rand-gen-factory[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Common.util.random.RanNnepFactory");
    algConf.addProperty("rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed")));

    // Neural Net Algorithm
    algorithm = new CCRElitistNeuralNetAlgorithm();

    algorithm.configure(algConf);

    // Read data
    ProblemEvaluator evaluator = (ProblemEvaluator) algorithm.getEvaluator();

    evaluator.readData(schema, new KeelDataSet(trainFile), new KeelDataSet(testFile));

    ((NeuralNetIndividualSpecies) algorithm.getSpecies()).setNOfInputs(evaluator.getTrainData().getNofinputs());
    ((NeuralNetIndividualSpecies) algorithm.getSpecies())
            .setNOfOutputs(evaluator.getTrainData().getNofoutputs() - 1);

    // Read output files
    tokenizer = new StringTokenizer(props.getProperty("outputData"));
    String trainResultFile = tokenizer.nextToken();
    trainResultFile = trainResultFile.substring(1, trainResultFile.length() - 1);
    consoleReporter.setTrainResultFile(trainResultFile);
    String testResultFile = tokenizer.nextToken();
    testResultFile = testResultFile.substring(1, testResultFile.length() - 1);
    consoleReporter.setTestResultFile(testResultFile);
    String bestModelResultFile = tokenizer.nextToken();
    bestModelResultFile = bestModelResultFile.substring(1, bestModelResultFile.length() - 1);
    consoleReporter.setBestModelResultFile(bestModelResultFile);

    listeners.add(consoleReporter);
}

From source file:com.aol.advertising.qiao.config.AgentXmlConfiguration.java

/**
 * Load configuration file and interpolate variables. Note that due to the
 * way Apache Commons Configuration treats property keys, user should avoid
 * using dot ('.') in the property key. Otherwise ACC may not substitute
 * some value if the variable contains valid element name(s).
 *
 * @param xmlConfigFile//  w  w w  .  j av  a  2  s  . c  o  m
 * @param propConfigFiles
 * @return
 * @throws ConfigurationException
 */
protected HierarchicalConfiguration readConfigurationFiles(String xmlConfigFile, String propConfigFiles)
        throws ConfigurationException {
    try {
        // convert URI to URL
        URL[] prop_urls = null;
        URL xml_url = CommonUtils.uriToURL(xmlConfigFile);
        if (propConfigFiles != null) {
            String[] prop_files = propConfigFiles.split(",");
            prop_urls = new URL[prop_files.length];
            for (int i = 0; i < prop_files.length; i++) {
                prop_urls[i] = CommonUtils.uriToURL(prop_files[i]);
            }
        }

        // combine xml and properties configurations
        CombinedConfiguration combined_cfg = new CombinedConfiguration(new OverrideCombiner());

        XMLConfiguration cfg_xml = new XMLConfiguration();
        cfg_xml.setDelimiterParsingDisabled(true);
        cfg_xml.setAttributeSplittingDisabled(true);
        cfg_xml.load(xml_url);

        combined_cfg.addConfiguration(cfg_xml);

        if (prop_urls != null) {
            // properties in the earlier files take precedence if duplicate
            for (int i = 0; i < prop_urls.length; i++) {
                PropertiesConfiguration cfg_props = new PropertiesConfiguration();
                cfg_props.setDelimiterParsingDisabled(true);
                cfg_props.load(prop_urls[i]);

                combined_cfg.addConfiguration(cfg_props);

            }
        }

        HierarchicalConfiguration config = (HierarchicalConfiguration) combined_cfg.interpolatedConfiguration(); // !!! resolve variables

        return config;
    } catch (Exception e) {
        throw new ConfigurationException(e.getMessage(), e);
    }

}

From source file:keel.Algorithms.Neural_Networks.IRPropPlus_Clas.KEELIRPropPlusWrapperClas.java

/**
 * <p>/*  w w w .jav a 2  s . c  o  m*/
 * Configure the execution of the algorithm.
 * 
 * @param jobFilename Name of the KEEL file with properties of the
 *                    execution
 * </p>                   
 */

@SuppressWarnings("unchecked")
private static void configureJob(String jobFilename) {

    Properties props = new Properties();

    try {
        InputStream paramsFile = new FileInputStream(jobFilename);
        props.load(paramsFile);
        paramsFile.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
        System.exit(0);
    }

    // Files training and test
    String trainFile;
    String testFile;
    StringTokenizer tokenizer = new StringTokenizer(props.getProperty("inputData"));
    tokenizer.nextToken();
    trainFile = tokenizer.nextToken();
    trainFile = trainFile.substring(1, trainFile.length() - 1);
    testFile = tokenizer.nextToken();
    testFile = testFile.substring(1, testFile.length() - 1);

    // Configure schema
    byte[] schema = null;
    try {
        schema = readSchema(trainFile);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DatasetException e) {
        e.printStackTrace();
    }

    // Auxiliar configuration file
    XMLConfiguration conf = new XMLConfiguration();
    conf.setRootElementName("algorithm");

    // Configure randGenFactory
    randGenFactory = new RanNnepFactory();
    conf.addProperty("rand-gen-factory[@seed]", Integer.parseInt(props.getProperty("seed")));
    if (randGenFactory instanceof IConfigure)
        ((IConfigure) randGenFactory).configure(conf.subset("rand-gen-factory"));

    // Configure species
    NeuralNetIndividualSpecies nnspecies = new NeuralNetIndividualSpecies();
    species = (ISpecies) nnspecies;
    if (props.getProperty("Transfer").equals("Product_Unit")) {
        conf.addProperty("species.neural-net-type",
                "keel.Algorithms.Neural_Networks.IRPropPlus_Clas.MSEOptimizablePUNeuralNetClassifier");
        conf.addProperty("species.hidden-layer[@type]",
                "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.ExpLayer");
        conf.addProperty("species.hidden-layer[@biased]", false);
    } else {
        conf.addProperty("species.neural-net-type",
                "keel.Algorithms.Neural_Networks.IRPropPlus_Clas.MSEOptimizableSigmNeuralNetClassifier");
        conf.addProperty("species.hidden-layer[@type]",
                "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.SigmLayer");
        conf.addProperty("species.hidden-layer[@biased]", true);
    }
    int neurons = Integer.parseInt(props.getProperty("Hidden_nodes"));
    conf.addProperty("species.hidden-layer.minimum-number-of-neurons", neurons);
    conf.addProperty("species.hidden-layer.initial-maximum-number-of-neurons", neurons);
    conf.addProperty("species.hidden-layer.maximum-number-of-neurons", neurons);
    conf.addProperty("species.hidden-layer.initiator-of-links",
            "keel.Algorithms.Neural_Networks.IRPropPlus_Clas.FullRandomInitiator");
    conf.addProperty("species.hidden-layer.weight-range[@type]", "net.sf.jclec.util.range.Interval");
    conf.addProperty("species.hidden-layer.weight-range[@closure]", "closed-closed");
    if (props.getProperty("Transfer").equals("Product_Unit")) {
        conf.addProperty("species.hidden-layer.weight-range[@left]", -0.1);
        conf.addProperty("species.hidden-layer.weight-range[@right]", 0.1);
    } else {
        conf.addProperty("species.hidden-layer.weight-range[@left]", -5.0);
        conf.addProperty("species.hidden-layer.weight-range[@right]", 5.0);
    }
    conf.addProperty("species.output-layer[@type]",
            "keel.Algorithms.Neural_Networks.NNEP_Common.neuralnet.LinearLayer");
    conf.addProperty("species.output-layer[@biased]", true);
    conf.addProperty("species.output-layer.initiator-of-links",
            "keel.Algorithms.Neural_Networks.IRPropPlus_Clas.FullRandomInitiator");
    conf.addProperty("species.output-layer.weight-range[@type]", "net.sf.jclec.util.range.Interval");
    conf.addProperty("species.output-layer.weight-range[@closure]", "closed-closed");
    conf.addProperty("species.output-layer.weight-range[@left]", -5.0);
    conf.addProperty("species.output-layer.weight-range[@right]", 5.0);
    if (species instanceof IConfigure)
        ((IConfigure) species).configure(conf.subset("species"));

    // Configure evaluator
    evaluator = (IEvaluator) new SoftmaxClassificationProblemEvaluator();
    if (props.getProperty("Transfer").equals("Product_Unit"))
        conf.addProperty("evaluator[@log-input-data]", true);
    conf.addProperty("evaluator[@normalize-data]", true);
    conf.addProperty("evaluator.error-function",
            "keel.Algorithms.Neural_Networks.NNEP_Clas.problem.errorfunctions.LogisticErrorFunction");
    conf.addProperty("evaluator.input-interval[@closure]", "closed-closed");
    conf.addProperty("evaluator.input-interval[@left]", 0.1);
    conf.addProperty("evaluator.input-interval[@right]", 0.9);
    conf.addProperty("evaluator.output-interval[@closure]", "closed-closed");
    conf.addProperty("evaluator.output-interval[@left]", 0.0);
    conf.addProperty("evaluator.output-interval[@right]", 1.0);
    if (evaluator instanceof IConfigure)
        ((IConfigure) evaluator).configure(conf.subset("evaluator"));

    // Configure provider
    provider = new NeuralNetCreator();
    KEELIRPropPlusWrapperClas system = new KEELIRPropPlusWrapperClas();
    provider.contextualize(system);

    // Configure iRProp+ algorithm
    algorithm = new IRPropPlus();
    conf.addProperty("algorithm.initial-step-size[@value]", 0.0125);
    conf.addProperty("algorithm.minimum-delta[@value]", 0.0);
    conf.addProperty("algorithm.maximum-delta[@value]", 50.0);
    conf.addProperty("algorithm.positive-eta[@value]", 1.2);
    conf.addProperty("algorithm.negative-eta[@value]", 0.2);
    conf.addProperty("algorithm.cycles[@value]", Integer.parseInt(props.getProperty("Epochs")));
    if (algorithm instanceof IConfigure)
        ((IConfigure) algorithm).configure(conf.subset("algorithm"));

    // Read data
    ProblemEvaluator<AbstractIndividual<INeuralNet>> evaluator2 = (ProblemEvaluator<AbstractIndividual<INeuralNet>>) evaluator;
    evaluator2.readData(schema, new KeelDataSet(trainFile), new KeelDataSet(testFile));
    nnspecies.setNOfInputs(evaluator2.getTrainData().getNofinputs());
    nnspecies.setNOfOutputs(evaluator2.getTrainData().getNofoutputs() - 1);
    algorithm.setTrainingData(evaluator2.getTrainData());

    // Read output files
    tokenizer = new StringTokenizer(props.getProperty("outputData"));
    String trainResultFile = tokenizer.nextToken();
    trainResultFile = trainResultFile.substring(1, trainResultFile.length() - 1);
    consoleReporter.setTrainResultFile(trainResultFile);
    String testResultFile = tokenizer.nextToken();
    testResultFile = testResultFile.substring(1, testResultFile.length() - 1);
    consoleReporter.setTestResultFile(testResultFile);
    String bestModelResultFile = tokenizer.nextToken();
    bestModelResultFile = bestModelResultFile.substring(1, bestModelResultFile.length() - 1);
    consoleReporter.setBestModelResultFile(bestModelResultFile);
}