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

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

Introduction

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

Prototype

public ConfigurationException(Throwable cause) 

Source Link

Document

Constructs a new ConfigurationException with specified nested Throwable.

Usage

From source file:com.twitter.distributedlog.service.config.DefaultStreamConfigProvider.java

public DefaultStreamConfigProvider(String configFilePath, ScheduledExecutorService executorService,
        int reloadPeriod, TimeUnit reloadUnit) throws ConfigurationException {
    try {//from   ww w  .  ja  v  a2  s  .  c o m
        File configFile = new File(configFilePath);
        FileConfigurationBuilder properties = new PropertiesConfigurationBuilder(configFile.toURI().toURL());
        ConcurrentConstConfiguration defaultConf = new ConcurrentConstConfiguration(
                new DistributedLogConfiguration());
        DynamicDistributedLogConfiguration conf = new DynamicDistributedLogConfiguration(defaultConf);
        List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(properties);
        confSub = new ConfigurationSubscription(conf, fileConfigBuilders, executorService, reloadPeriod,
                reloadUnit);
        this.dynConf = Optional.of(conf);
    } catch (MalformedURLException ex) {
        throw new ConfigurationException(ex);
    }
}

From source file:eu.optimis.elasticityengine.config.ConfigurationManager.java

/**
 * Load configuration file as specified in the system property, and fall
 * back on the default file if required.
 *///from   www  .j a va2 s.c  o m
private void loadConfigurationFile(String defaultConfigFilePath, String defaultConfigFileName)
        throws ConfigurationException {
    String configFilePath = System.getProperty("configuration.file.path");
    String configFileName = System.getProperty("configuration.file.name");
    String filePath = configFilePath == null ? defaultConfigFilePath : configFilePath;
    String fileName = configFileName == null ? defaultConfigFileName : configFileName;

    URL configURL;

    if (!filePath.endsWith(File.pathSeparator)) {
        filePath += File.pathSeparatorChar;
    }

    // Check if the file exists on the system, else try reading it from the
    // classpath
    File configFile = new File(filePath + fileName);
    if (configFile.exists()) {
        try {
            configURL = new URL(filePath + fileName);
        } catch (MalformedURLException e) {
            throw new ConfigurationException(e);
        }
    } else {
        configURL = this.getClass().getClassLoader().getResource(fileName);
    }

    PropertiesConfiguration config = null;
    try {
        config = new PropertiesConfiguration(configURL);
    } catch (ConfigurationException e) {
        if (configFileName.equals(defaultConfigFileName) && configFilePath.equals(defaultConfigFilePath)) {
            log.fatal("Could not find default configuration file: '" + defaultConfigFilePath + "'", e);
            throw e;
        } else {
            // Try default file too
            try {
                config = new PropertiesConfiguration(defaultConfigFilePath);
            } catch (ConfigurationException e2) {
                log.fatal("Could not find specified " + "configuration file: '" + configFilePath
                        + File.pathSeparator + configFileName + "', and could not find default "
                        + "configuration file: '" + defaultConfigFilePath + "'", e2);
                throw e2;
            }

            log.warn("Could not find specified " + "configuration file: '" + configFilePath + File.pathSeparator
                    + configFileName + "', using default configuration at : '" + defaultConfigFilePath
                    + File.pathSeparator + defaultConfigFileName + "'");
        }
    }
    config.setThrowExceptionOnMissing(true);
    this.configuration = config;
}

From source file:eu.optimis_project.monitoring.config.ConfigurationManager.java

/**
 * Load configuration file as specified in the system property, and fall
 * back on the default file if required.
 *//*from   ww  w.  j a  v a2 s. c  o  m*/
private void loadConfigurationFile(String defaultConfigFilePath, String defaultConfigFileName)
        throws ConfigurationException {
    String configFilePath = System.getProperty("configuration.file.path");
    String configFileName = System.getProperty("configuration.file.name");
    String filePath = configFilePath == null ? defaultConfigFilePath : configFilePath;
    String fileName = configFileName == null ? defaultConfigFileName : configFileName;

    URL configURL;

    if (!filePath.endsWith(File.separator)) {
        filePath += File.separatorChar;
    }

    // Check if the file exists on the system, else try reading it from the
    // classpath
    File configFile = new File(filePath + fileName);
    if (configFile.exists()) {
        try {
            configURL = new URL(filePath + fileName);
        } catch (MalformedURLException e) {
            throw new ConfigurationException(e);
        }
    } else {
        configURL = this.getClass().getClassLoader().getResource(fileName);
    }

    PropertiesConfiguration config = null;
    try {
        config = new PropertiesConfiguration(configURL);
    } catch (ConfigurationException e) {
        if (defaultConfigFileName.equals(configFileName) && configFilePath.equals(defaultConfigFilePath)) {
            log.fatal("Could not find default configuration file: '" + configURL + "'", e);
            throw e;
        } else {
            // Try default file too
            try {
                config = new PropertiesConfiguration(defaultConfigFilePath);
            } catch (ConfigurationException e2) {
                log.warn("Could not find default file, trying same dir");
            }

            // Try file in same dir
            if (config == null) {
                String sameDirPath = System.getProperty("user.dir") + File.separatorChar
                        + defaultConfigFileName;
                try {
                    config = new PropertiesConfiguration(sameDirPath);
                    log.info("Using file in same directory:" + sameDirPath);
                } catch (ConfigurationException e2) {
                    log.fatal("Could not find specified " + "configuration file: '" + configFilePath
                            + File.separatorChar + configFileName + "', could not find default "
                            + "configuration file: '" + defaultConfigFilePath + File.separatorChar
                            + defaultConfigFileName + "', and could not find file in same dir: " + sameDirPath
                            + "'", e2);
                    throw e2;
                }
            }

            log.warn("Could not find specified " + "configuration file: '" + configFilePath + File.separatorChar
                    + configFileName + "', using default configuration at : '" + defaultConfigFilePath
                    + File.separatorChar + defaultConfigFileName + "'");
        }
    }
    config.setThrowExceptionOnMissing(true);
    this.configuration = config;
}

From source file:ee.ria.xroad.confproxy.ConfProxyProperties.java

/**
 * Constructs the configuration for the given
 * configuration proxy instance id.//from ww w  .j av  a 2s  .  c om
 * @param name the if of the configuration proxy instance
 * @throws ConfigurationException if the configuration could not be loaded
 */
public ConfProxyProperties(final String name) throws ConfigurationException {
    this.instance = name;
    String confDir = SystemProperties.getConfigurationProxyConfPath();
    File configFile = Paths.get(confDir, instance, CONF_INI).toFile();
    if (!configFile.exists()) {
        throw new ConfigurationException("'" + CONF_INI + "' does not exist.");
    }
    try {
        config = new HierarchicalINIConfiguration(configFile);
    } catch (ConfigurationException e) {
        log.error("Failed to load '{}': {}", configFile, e.getMessage());
        throw e;
    }
}

From source file:com.tamnd.core.util.ZConfig.java

private static Configuration LoadFromFile(String path) throws ConfigurationException {
    if (path.endsWith(".ini") || path.endsWith(".properties")) {
        HierarchicalINIConfiguration config = new HierarchicalINIConfiguration();
        config.setDelimiterParsingDisabled(true);
        config.setFileName(path);/*from  w  ww .ja v a2 s. c  o  m*/
        config.load();
        return config;
    } else if (path.endsWith(".xml")) {
        return new XMLConfiguration(path);
    } else {
        throw new ConfigurationException("Unknown configuration file extension");
    }
}

From source file:com.twitter.distributedlog.config.DynamicConfigurationFactory.java

public synchronized Optional<DynamicDistributedLogConfiguration> getDynamicConfiguration(String configPath,
        ConcurrentBaseConfiguration defaultConf) throws ConfigurationException {
    Preconditions.checkNotNull(configPath);
    try {//from  w  w w . ja  va2  s .c om
        if (!dynamicConfigs.containsKey(configPath)) {
            File configFile = new File(configPath);
            FileConfigurationBuilder properties = new PropertiesConfigurationBuilder(
                    configFile.toURI().toURL());
            DynamicDistributedLogConfiguration dynConf = new DynamicDistributedLogConfiguration(defaultConf);
            List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(properties);
            ConfigurationSubscription subscription = new ConfigurationSubscription(dynConf, fileConfigBuilders,
                    executorService, reloadPeriod, reloadUnit);
            subscriptions.add(subscription);
            dynamicConfigs.put(configPath, dynConf);
            LOG.info("Loaded dynamic configuration at {}", configPath);
        }
        return Optional.of(dynamicConfigs.get(configPath));
    } catch (MalformedURLException ex) {
        throw new ConfigurationException(ex);
    }
}

From source file:it.unimi.di.big.mg4j.document.IdentityDocumentFactory.java

protected boolean parseProperty(final String key, final String[] values,
        final Reference2ObjectMap<Enum<?>, Object> metadata) throws ConfigurationException {
    if (sameKey(PropertyBasedDocumentFactory.MetadataKeys.ENCODING, key)) {
        metadata.put(PropertyBasedDocumentFactory.MetadataKeys.ENCODING,
                Charset.forName(ensureJustOne(key, values)).toString());
        return true;
    }/*from   w ww.j a  v a  2 s. com*/
    if (sameKey(PropertyBasedDocumentFactory.MetadataKeys.WORDREADER, key)) {
        try {
            final String spec = (ensureJustOne(key, values)).toString();
            metadata.put(PropertyBasedDocumentFactory.MetadataKeys.WORDREADER, spec);
            // Just to check
            ObjectParser.fromSpec(spec, WordReader.class, MG4JClassParser.PACKAGE);
        } catch (ClassNotFoundException e) {
            throw new ConfigurationException(e);
        }
        // TODO: this must turn into a more appropriate exception
        catch (Exception e) {
            throw new ConfigurationException(e);
        }
        return true;
    }
    if (sameKey(MetadataKeys.FIELDNAME, key)) {
        metadata.put(MetadataKeys.FIELDNAME, ensureJustOne(key, values));
        return true;
    }

    return super.parseProperty(key, values, metadata);
}

From source file:com.linkedin.pinot.core.data.manager.config.FileBasedInstanceDataManagerConfig.java

private void checkRequiredKeys() throws ConfigurationException {
    for (String keyString : REQUIRED_KEYS) {
        if (!_instanceDataManagerConfiguration.containsKey(keyString)) {
            throw new ConfigurationException("Cannot find required key : " + keyString);
        }/*from w ww  .j  a  v  a 2  s.c om*/
    }
}

From source file:edu.hawaii.soest.pacioos.text.TextSourceFactory.java

/**
 * Configure and return a simple text-based source driver instance using the given XML-based
 * configuration file.//from  w  ww.  ja  v  a 2 s .co m
 * 
 * @param configLocation  the path to the file on disk or in a jar
 * @return  a new instance of a subclassed SimpleTextSource
 * @throws ConfigurationException
 */
public static SimpleTextSource getSimpleTextSource(String configLocation) throws ConfigurationException {

    // Get the per-driver configuration
    XMLConfiguration xmlConfig = new XMLConfiguration();
    xmlConfig.setListDelimiter(new String("|").charAt(0));
    xmlConfig.load(configLocation);
    String connectionType = xmlConfig.getString("connectionType");

    if (log.isDebugEnabled()) {
        Iterator i = xmlConfig.getKeys();
        while (i.hasNext()) {
            String key = (String) i.next();
            String value = xmlConfig.getString(key);
            log.debug(key + ":\t\t" + value);

        }

    }

    // return the correct configuration type
    if (connectionType.equals("file")) {
        FileTextSource fileTextSource = getFileTextSource(xmlConfig);
        String filePath = xmlConfig.getString("connectionParams.filePath");
        fileTextSource.setDataFilePath(filePath);

        simpleTextSource = (SimpleTextSource) fileTextSource;

    } else if (connectionType.equals("socket")) {
        SocketTextSource socketTextSource = getSocketTextSource(xmlConfig);
        String hostName = xmlConfig.getString("connectionParams.hostName");
        socketTextSource.setHostName(hostName);
        int hostPort = xmlConfig.getInt("connectionParams.hostPort");
        socketTextSource.setHostPort(hostPort);

        simpleTextSource = (SimpleTextSource) socketTextSource;

    } else if (connectionType.equals("serial")) {
        SerialTextSource serialTextSource = getSerialTextSource(xmlConfig);
        String serialPort = xmlConfig.getString("connectionParams.serialPort");
        serialTextSource.setSerialPort(serialPort);
        int baudRate = xmlConfig.getInt("connectionParams.serialPortParams.baudRate");
        serialTextSource.setBaudRate(baudRate);
        int dataBits = xmlConfig.getInt("connectionParams.serialPortParams.dataBits");
        serialTextSource.setDataBits(dataBits);
        int stopBits = xmlConfig.getInt("connectionParams.serialPortParams.stopBits");
        serialTextSource.setStopBits(stopBits);
        String parity = xmlConfig.getString("connectionParams.serialPortParams.parity");
        serialTextSource.setParity(parity);

        simpleTextSource = (SimpleTextSource) serialTextSource;

    } else {
        throw new ConfigurationException("There was an issue parsing the configuration."
                + " The connection type of " + connectionType + " wasn't recognized.");
    }

    return simpleTextSource;

}

From source file:de.sub.goobi.metadaten.copier.MetadataPathSelector.java

/**
 * Creates a new MetadataPathSelector.//w  ww . j  a  v  a  2s .c om
 *
 * @param path
 *            path to create sub-selector, passed to {
 *            {@link #create(String)}.
 * @throws ConfigurationException
 *             if the path is invalid
 */

public MetadataPathSelector(String path) throws ConfigurationException {
    String pathSegment = matchCurrentPathSegment(path);
    Matcher pathSelectorHasElementSelector = SEGMENT_WITH_ELEMENT_SELELCTOR_SCHEME.matcher(pathSegment);
    if (pathSelectorHasElementSelector.matches()) {
        docStructType = pathSelectorHasElementSelector.group(1);
        String indexSymbol = pathSelectorHasElementSelector.group(2);
        try {
            index = getIndexValue(indexSymbol);
            if (index instanceof Integer && ((Integer) index).intValue() < 0) {
                throw new ConfigurationException("Negative element count is not allowed, in path: " + path);
            }
        } catch (NumberFormatException e) {
            throw new ConfigurationException("Cannot create metadata path selector: " + e.getMessage(), e);
        }
    } else {
        docStructType = pathSegment;
        index = null;
    }
    selector = super.create(path.substring(pathSegment.length() + 1));
}