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

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

Introduction

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

Prototype

public ConfigurationRuntimeException(Throwable cause) 

Source Link

Document

Constructs a new ConfigurationRuntimeException with specified nested Throwable.

Usage

From source file:keel.Algorithms.Neural_Networks.NNEP_Common.NeuralNetIndividualSpecies.java

/**
 * <p>//  www . j a v  a2s  . c  o m
 * Configuration parameters for this species are:
 * 
 * 
 * input-layer.number-of-inputs (int)
 *  Number of inputs. Number of inputs of this species neural nets.
 *
 * output-layer.number-of-outputs (int)
 *  Number of inputs. Number of outputs of this species neural nets.
 * 
 * hidden-layer(i).weight-range (complex)
 *  Weigth range of the hidden layer number "i".
 * 
 * output-layer.weight-range (complex)
 *  Weigth range of the outputlayer.
 *  
 * hidden-layer(i).maximum-number-of-neurons (int)
 *  Maximum number of neurons of hidden layer number "i".
 * 
 * hidden-layer(i).initial-number-of-neurons (int)
 *  Initial number of neurons of hidden layer number "i".
 * 
 * hidden-layer(i)[@type] (string)
 *  Layer type of the hidden layer number "i".
 *  
 * output-layer[@type] (string)
 *  Layer type of the output layer.
 * 
 * hidden-layer(i)[@biased] (string)
 *  Boolean indicating if hidden layer number "i" is biased.
 * 
 * output-layer[@type] (string)
 *  Boolean indicating if the output layer is biased.
 *  
 *  @param configutation Configuration if the Individual
 * </p>
 */

@SuppressWarnings("unchecked")
public void configure(Configuration configuration) {
    // -------------------------------------- Setup neuralNetType
    neuralNetType = configuration.getString("neural-net-type");

    // -------------------------------------- Setup nOfHiddenLayers 
    nOfHiddenLayers = configuration.getList("hidden-layer[@type]").size();

    // -------------------------------------- Setup nOfInputs 
    //nOfInputs = configuration.getInt("input-layer.number-of-inputs");

    // -------------------------------------- Setup nOfOutputs
    //nOfOutputs = configuration.getInt("output-layer.number-of-outputs");

    // Initialize arrays
    maxNofneurons = new int[nOfHiddenLayers];
    minNofneurons = new int[nOfHiddenLayers];
    initialMaxNofneurons = new int[nOfHiddenLayers];
    type = new String[nOfHiddenLayers + 1];
    initiator = new String[nOfHiddenLayers + 1];
    biased = new boolean[nOfHiddenLayers + 1];

    weightRanges = new Interval[nOfHiddenLayers + 1][];
    neuronTypes = new String[nOfHiddenLayers + 1][];
    percentages = new double[nOfHiddenLayers + 1][];
    initiatorNeuronTypes = new String[nOfHiddenLayers + 1][];
    for (int i = 0; i < nOfHiddenLayers + 1; i++) {
        String header;

        if (i != nOfHiddenLayers) {
            header = "hidden-layer(" + i + ")";
            // ---------------------------------- Setup maxNofneurons array
            maxNofneurons[i] = configuration.getInt(header + ".maximum-number-of-neurons");
            // ---------------------------------- Setup minNofneurons array
            minNofneurons[i] = configuration.getInt(header + ".minimum-number-of-neurons");
            // ---------------------------------- Setup initialMaxNofneurons array
            initialMaxNofneurons[i] = configuration.getInt(header + ".initial-maximum-number-of-neurons");
            // ---------------------------------- Setup initiator array
            initiator[i] = configuration.getString(header + ".initiator-of-links");
        } else {
            header = "output-layer";
            // ---------------------------------- Setup initiator array
            initiator[i] = configuration.getString(header + ".initiator-of-links");
        }

        //  ----------------------------------------- Setup type array
        type[i] = configuration.getString(header + "[@type]");

        //  ----------------------------------------- Setup biased array
        biased[i] = configuration.getBoolean(header + "[@biased]");

        // -------------------------------------- Setup weight ranges array
        weightRanges[i] = new Interval[1];
        try {
            // Range name
            String rangeName = header + ".weight-range";
            // Range classname
            String rangeClassname = configuration.getString(rangeName + "[@type]");
            // Range class
            Class<Interval> rangeClass = (Class<Interval>) Class.forName(rangeClassname);
            // Range instance
            Interval range = rangeClass.newInstance();
            // Configura range
            range.configure(configuration.subset(rangeName));
            // Set range
            if (i != nOfHiddenLayers)
                setHiddenLayerWeightRange(i, 0, range);
            else
                setOutputLayerWeightRange(0, range);
        } catch (ClassNotFoundException e) {
            throw new ConfigurationRuntimeException("Illegal range classname");
        } catch (InstantiationException e) {
            throw new ConfigurationRuntimeException("Problems creating an instance of range", e);
        } catch (IllegalAccessException e) {
            throw new ConfigurationRuntimeException("Problems creating an instance of range", e);
        }
    }
}

From source file:net.sf.jclal.evaluation.method.AbstractEvaluationMethod.java

/**
 *
 * @param configuration The configuration of the random generator.
 * <p>//from   w  w  w.  j  a  va2s .  c  o  m
 * rand-gen-factory type= class</p>
 *
 */
@SuppressWarnings("unchecked")
protected void setRandGenSettings(Configuration configuration) {
    // Random generators factory
    String randomError = "rand-gen-factory type= ";
    try {
        // Species classname
        String randGenFactoryClassname = configuration.getString("rand-gen-factory[@type]");
        randomError += randGenFactoryClassname;
        // Species class
        Class<? extends IRandGenFactory> randGenFactoryClass = (Class<? extends IRandGenFactory>) Class
                .forName(randGenFactoryClassname);
        // Species instance
        IRandGenFactory randGenFactory = randGenFactoryClass.newInstance();
        // Configure species
        if (randGenFactory instanceof IConfigure) {
            ((IConfigure) randGenFactory).configure(configuration.subset("rand-gen-factory"));
        }
        // Set species
        setRandGenFactory(randGenFactory);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException(
                "\nIllegal random generators factory classname: " + randomError);
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException(
                "\nProblems creating an instance of random generators factory: " + randomError, e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException(
                "\nProblems creating an instance of random generators factory: " + randomError, e);
    }
}

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

/**
 * Returns a copy of this object. This implementation will create a deep
 * clone, i.e. all configurations contained in this composite will also be
 * cloned. This only works if all contained configurations support cloning;
 * otherwise a runtime exception will be thrown. Registered event handlers
 * won't get cloned.//from   ww w. ja va2s.  c om
 *
 */
@Override
public Object clone() {
    try {
        ConcurrentCompositeConfiguration copy = (ConcurrentCompositeConfiguration) super.clone();
        copy.clearConfigurationListeners();
        copy.configList = new LinkedList<AbstractConfiguration>();
        copy.containerConfiguration = (AbstractConfiguration) ConfigurationUtils
                .cloneConfiguration(getContainerConfiguration());
        copy.configList.add(copy.containerConfiguration);

        for (Configuration config : configList) {
            if (config != getContainerConfiguration()) {
                copy.addConfiguration((AbstractConfiguration) ConfigurationUtils.cloneConfiguration(config));
            }
        }

        return copy;
    } catch (CloneNotSupportedException cnex) {
        // cannot happen
        throw new ConfigurationRuntimeException(cnex);
    }
}

From source file:keel.Algorithms.Neural_Networks.NNEP_Common.algorithm.NeuralNetAlgorithm.java

/**
 * <p>//w  ww .  ja v  a 2  s .c o m
 * Configuration parameters for NeuralNetAlgorithm class are:
 * 
 * <ul>
 * <li>
 * <code>species: ISpecies (complex)</code></p>
 * Individual species
 * </li><li>
 * <code>evaluator IEvaluator (complex)</code></p>
 * Individuals evaluator
 * </li><li>
 * <code>population-size (int)</code></p>
 * Population size
 * </li><li>
 * <code>max-of-generations (int)</code></p>
 * Maximum number of generations
 * </li>
 * <li>
 * <code>provider: IProvider (complex)</code></p>
 * Individuals provider
 * </li>
 * <li>
 * <code>mutator1: IMutator<I> (complex)</code></p>
 * Individuals mutator1
 * </li>
 * <li>
 * <code>mutator2: IMutator<I> (complex)</code></p>
 * Individuals mutator2
 * </li>
 * <li>
 * <code>creation-ratio (double)</code></p>
 * Ratio "elements created"/"elements remaining"
 * </li>
 * <li>
 * <code>percentage-second-mutator (int)</code></p>
 * Percentage of individuals mutated with second mutator
 * </li>
 * <li>
 * <code>max-generations-without-improving-mean (int)</code></p>
 * Maximum number of generations without improving mean fitness
 * </li>
 * <li>
 * <code>max-generations-without-improving-best (int)</code></p>
 * Maximum number of generations without improving best fitness
 * </li>
 * <li>
 * <code>fitness-difference (double)</code></p>
 * Difference between two fitness that we consider
  * enough to say that the fitness has improved
 * </li>
 * </ul>
 * </p>
 * @param configuration Configuration object to obtain the parameters
 */
@SuppressWarnings("unchecked")
public void configure(Configuration configuration) {

    // Random generators factory
    try {
        // Species classname
        String randGenFactoryClassname = configuration.getString("rand-gen-factory[@type]");
        // Species class
        Class<? extends IRandGenFactory> randGenFactoryClass = (Class<? extends IRandGenFactory>) Class
                .forName(randGenFactoryClassname);
        // Species instance
        IRandGenFactory randGenFactory = randGenFactoryClass.newInstance();
        // Configure species
        if (randGenFactory instanceof IConfigure) {
            ((IConfigure) randGenFactory).configure(configuration.subset("rand-gen-factory"));
        }
        // Set species
        setRandGenFactory(randGenFactory);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal random generators factory classname");
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of random generators factory",
                e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of random generators factory",
                e);
    }
    // Individual species
    try {
        // Species classname
        String speciesClassname = configuration.getString("species[@type]");
        // Species class
        Class<ISpecies<I>> speciesClass = (Class<ISpecies<I>>) Class.forName(speciesClassname);
        // Species instance
        ISpecies<I> species = speciesClass.newInstance();
        // Configure species if neccesary
        if (species instanceof IConfigure) {
            // Extract species configuration
            Configuration speciesConfiguration = configuration.subset("species");
            // Configure species
            ((IConfigure) species).configure(speciesConfiguration);
        }
        // Set species
        setSpecies(species);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal species classname");
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of species", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of species", e);
    }
    // Individuals evaluator
    try {
        // Evaluator classname
        String evaluatorClassname = configuration.getString("evaluator[@type]");
        // Evaluator class
        Class<IEvaluator<I>> evaluatorClass = (Class<IEvaluator<I>>) Class.forName(evaluatorClassname);
        // Evaluator instance
        IEvaluator<I> evaluator = evaluatorClass.newInstance();
        // Configure evaluator if neccesary
        if (evaluator instanceof IConfigure) {
            // Extract species configuration
            Configuration evaluatorConfiguration = configuration.subset("evaluator");
            // Configure evaluator
            ((IConfigure) evaluator).configure(evaluatorConfiguration);
        }
        // Set species
        setEvaluator(evaluator);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal evaluator classname");
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of evaluator", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of evaluator", e);
    }
    // Population size
    int populationSize = configuration.getInt("population-size");
    setPopulationSize(populationSize);
    // Maximum of generations
    int maxOfGenerations = configuration.getInt("max-of-generations");
    setMaxOfGenerations(maxOfGenerations);
    // Individuals provider
    try {
        // Provider classname
        String providerClassname = configuration.getString("provider[@type]");
        // Provider class
        Class<IProvider<I>> providerClass = (Class<IProvider<I>>) Class.forName(providerClassname);
        // Provider instance
        IProvider<I> provider = providerClass.newInstance();
        // Configure provider if neccesary
        if (provider instanceof IConfigure) {
            // Extract provider configuration
            Configuration providerConfiguration = configuration.subset("provider");
            // Configure provider
            ((IConfigure) provider).configure(providerConfiguration);
        }
        // Set provider
        setProvider(provider);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal provider classname");
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of provider", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of provider", e);
    }
    // Individuals mutator1
    try {
        // Mutator1 classname
        String mutator1Classname = configuration.getString("mutator1[@type]");
        // Mutator1 classe
        Class<IMutator<I>> mutator1Class = (Class<IMutator<I>>) Class.forName(mutator1Classname);
        // Mutator1 instance
        IMutator<I> mutator1 = mutator1Class.newInstance();
        // Configure mutator1 if neccesary
        if (mutator1 instanceof IConfigure) {
            // Extract mutator1 configuration
            Configuration mutator1Configuration = configuration.subset("mutator1");
            // Configure mutator1
            ((IConfigure) mutator1).configure(mutator1Configuration);
        }
        // Set mutator1
        setMutator1(mutator1);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal mutator1 classname");
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of mutator1", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of mutator1", e);
    }
    // Individuals mutator2
    try {
        // Mutator2 classname
        String mutator2Classname = configuration.getString("mutator2[@type]");
        // Mutator2 class
        Class<IMutator<I>> mutator2Class = (Class<IMutator<I>>) Class.forName(mutator2Classname);
        // Mutator2 instance
        IMutator<I> mutator2 = mutator2Class.newInstance();
        // Configure mutator2 if neccesary
        if (mutator2 instanceof IConfigure) {
            // Extract mutator2 configuration
            Configuration mutator2Configuration = configuration.subset("mutator2");
            // Configure mutator2 
            ((IConfigure) mutator2).configure(mutator2Configuration);
        }
        // Set mutator2
        setMutator2(mutator2);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("Illegal mutator2 classname");
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of mutator2", e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("Problems creating an instance of mutator2", e);
    }
    // Creation ratio
    double cratio = configuration.getDouble("creation-ratio");
    setCratio(cratio);
    // Percentage of individuals mutated with second mutator
    int percenageMutator2 = configuration.getInt("percentage-second-mutator");
    setPercentageSecondMutator(percenageMutator2);
    // Maximum of generations without improving mean fitness
    int mogmean = configuration.getInt("max-generations-without-improving-mean");
    setMogmean(mogmean);
    // Maximum of generations without improving best fitness
    int mogbest = configuration.getInt("max-generations-without-improving-best");
    setMogbest(mogbest);
    // Significative fitness difference
    double fitDif = configuration.getDouble("fitness-difference");
    setFitDif(fitDif);
}

From source file:org.apache.rya.indexing.GeoRyaSailFactory.java

/**
 * Create a {@link MongoClient} that is connected to the configured database.
 *
 * @param mongoConf - Configures what will be connected to. (not null)
 * @throws ConfigurationRuntimeException An invalid port was provided by {@code mongoConf}.
 * @throws MongoException Couldn't connect to the MongoDB database.
 *///ww w  . j  a va 2 s .  co  m
private static MongoClient createMongoClient(final MongoDBRdfConfiguration mongoConf)
        throws ConfigurationRuntimeException, MongoException {
    requireNonNull(mongoConf);
    requireNonNull(mongoConf.getMongoHostname());
    requireNonNull(mongoConf.getMongoPort());
    requireNonNull(mongoConf.getMongoDBName());

    // Connect to a running MongoDB server.
    final int port;
    try {
        port = Integer.parseInt(mongoConf.getMongoPort());
    } catch (final NumberFormatException e) {
        throw new ConfigurationRuntimeException("Port '" + mongoConf.getMongoPort() + "' must be an integer.");
    }

    final ServerAddress server = new ServerAddress(mongoConf.getMongoHostname(), port);

    // Connect to a specific MongoDB Database if that information is provided.
    final String username = mongoConf.getMongoUser();
    final String database = mongoConf.getMongoDBName();
    final String password = mongoConf.getMongoPassword();
    if (username != null && password != null) {
        final MongoCredential cred = MongoCredential.createCredential(username, database,
                password.toCharArray());
        return new MongoClient(server, Arrays.asList(cred));
    } else {
        return new MongoClient(server);
    }
}

From source file:org.apache.rya.mongodb.MongoConnectorFactory.java

/**
 * Throw exception for un-configured required values.
 *
 * @param required  String to check//w ww .  j a va  2s  . c  o  m
 * @param message  throw configuration exception with this description
 * @return unaltered required string
 * @throws ConfigurationRuntimeException  if required is null
 */
private static String requireNonNull(final String required, final String message)
        throws ConfigurationRuntimeException {
    if (required == null) {
        throw new ConfigurationRuntimeException(message);
    }
    return required;
}

From source file:org.apache.rya.mongodb.MongoConnectorFactory.java

private static int requireNonNullInt(final String required, final String message)
        throws ConfigurationRuntimeException {
    if (required == null) {
        throw new ConfigurationRuntimeException(message);
    }//from   w w w  .ja  v  a2 s .c om
    try {
        return Integer.parseInt(required);
    } catch (final NumberFormatException e) {
        throw new ConfigurationRuntimeException(message);
    }
}

From source file:org.ssh.test.conf.IConfiguration.java

/**
 * Adds a new configuration to this combined configuration. It is possible
 * (but not mandatory) to give the new configuration a name. This name must
 * be unique, otherwise a {@code ConfigurationRuntimeException} will be
 * thrown. With the optional {@code at} argument you can specify where in
 * the resulting node structure the content of the added configuration
 * should appear. This is a string that uses dots as property delimiters
 * (independent on the current expression engine). For instance if you pass
 * in the string {@code "database.tables"}, all properties of the added
 * configuration will occur in this branch.
 * /*from www  . ja v a  2  s .  co m*/
 * @param config
 *            the configuration to add (must not be <b>null</b>)
 * @param name
 *            the name of this configuration (can be <b>null</b>)
 * @param at
 *            the position of this configuration in the combined tree (can
 *            be <b>null</b>)
 */
public void addConfiguration(AbstractConfiguration config, String name, String at) {
    if (config == null) {
        throw new IllegalArgumentException("Added configuration must not be null!");
    }
    if (name != null && namedConfigurations.containsKey(name)) {
        throw new ConfigurationRuntimeException(
                "A configuration with the name '" + name + "' already exists in this combined configuration!");
    }

    ConfigData cd = new ConfigData(config, name, at);
    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Adding configuration " + config + " with name " + name);
    }
    configurations.add(cd);
    if (name != null) {
        namedConfigurations.put(name, config);
    }

    config.addConfigurationListener(this);
    invalidate();
}

From source file:org.ssh.test.conf.IConfiguration.java

/**
 * Triggers the contained configurations to perform a reload check if
 * necessary. This method is called when a property of this combined
 * configuration is accessed and the {@code forceReloadCheck} property is
 * set to <b>true</b>./*from   w  w  w . ja  v a  2s  .com*/
 * 
 * @see #setForceReloadCheck(boolean)
 * @since 1.6
 */
protected void performReloadCheck() {
    for (ConfigData cd : configurations) {
        try {
            // simply retrieve a property; this is enough for
            // triggering a reload
            cd.getConfiguration().getProperty(PROP_RELOAD_CHECK);
        } catch (Exception ex) {
            if (!ignoreReloadExceptions) {
                throw new ConfigurationRuntimeException(ex);
            }
        }
    }
}