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:it.unimi.di.big.mg4j.document.tika.AbstractSimpleTikaDocumentFactory.java

protected boolean parseProperty(final String key, final String[] values,
        final Reference2ObjectMap<Enum<?>, Object> metadata) throws ConfigurationException {
    if (sameKey(PropertyBasedDocumentFactory.MetadataKeys.WORDREADER, key)) {
        try {//from  w ww .  j ava2  s .c  o m
            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;
    }
    return super.parseProperty(key, values, metadata);
}

From source file:edu.cwru.sepia.Main.java

private static HierarchicalConfiguration getConfiguration(String filename) throws ConfigurationException {
    HierarchicalConfiguration configuration = null;
    try {//from  www.  ja  v  a 2 s . co m
        configuration = new XMLConfiguration(new File(filename));
    } catch (Exception ex) {
    }
    if (configuration == null || configuration.isEmpty()) {
        try {
            configuration = new HierarchicalINIConfiguration(new File(filename));
        } catch (Exception ex) {
        }
    }
    if (configuration == null)
        throw new ConfigurationException("Unable to load configuration file as XML, or INI.");
    return configuration;
}

From source file:cc.kune.wave.server.CustomSettingsBinder.java

/**
 * Bind configuration parameters into Guice Module.
 *
 * @param propertyFile the property file
 * @param settingsArg the settings arg/*from   www . j  a va  2  s . c  o m*/
 * @return a Guice module configured with setting support.
 * @throws ConfigurationException on configuration error
 */
public static Module bindSettings(String propertyFile, Class<?>... settingsArg) throws ConfigurationException {
    final CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    config.addConfiguration(new PropertiesConfiguration(propertyFile));

    List<Field> fields = new ArrayList<Field>();
    for (Class<?> settings : settingsArg) {
        fields.addAll(Arrays.asList(settings.getDeclaredFields()));
    }

    // Reflect on settings class and absorb settings
    final Map<Setting, Field> settings = new LinkedHashMap<Setting, Field>();
    for (Field field : fields) {
        if (!field.isAnnotationPresent(Setting.class)) {
            continue;
        }

        // Validate target type
        SettingTypeValidator typeHelper = supportedSettingTypes.get(field.getType());
        if (typeHelper == null || !typeHelper.check(field.getGenericType())) {
            throw new IllegalArgumentException(field.getType() + " is not one of the supported setting types");
        }

        Setting setting = field.getAnnotation(Setting.class);
        settings.put(setting, field);
    }

    // Now validate them
    List<String> missingProperties = new ArrayList<String>();
    for (Setting setting : settings.keySet()) {
        if (setting.defaultValue().isEmpty()) {
            if (!config.containsKey(setting.name())) {
                missingProperties.add(setting.name());
            }
        }
    }
    if (missingProperties.size() > 0) {
        StringBuilder error = new StringBuilder();
        error.append("The following required properties are missing from the server configuration: ");
        error.append(Joiner.on(", ").join(missingProperties));
        throw new ConfigurationException(error.toString());
    }

    // bundle everything up in an injectable guice module
    return new AbstractModule() {

        @Override
        protected void configure() {
            // We must iterate the settings a third time when binding.
            // Note: do not collapse these loops as that will damage
            // early error detection. The runtime is still O(n) in setting count.
            for (Map.Entry<Setting, Field> entry : settings.entrySet()) {
                Class<?> type = entry.getValue().getType();
                Setting setting = entry.getKey();

                if (int.class.equals(type)) {
                    Integer defaultValue = null;
                    if (!setting.defaultValue().isEmpty()) {
                        defaultValue = Integer.parseInt(setting.defaultValue());
                    }
                    bindConstant().annotatedWith(Names.named(setting.name()))
                            .to(config.getInteger(setting.name(), defaultValue));
                } else if (boolean.class.equals(type)) {
                    Boolean defaultValue = null;
                    if (!setting.defaultValue().isEmpty()) {
                        defaultValue = Boolean.parseBoolean(setting.defaultValue());
                    }
                    bindConstant().annotatedWith(Names.named(setting.name()))
                            .to(config.getBoolean(setting.name(), defaultValue));
                } else if (String.class.equals(type)) {
                    bindConstant().annotatedWith(Names.named(setting.name()))
                            .to(config.getString(setting.name(), setting.defaultValue()));
                } else {
                    String[] value = config.getStringArray(setting.name());
                    if (value.length == 0 && !setting.defaultValue().isEmpty()) {
                        value = setting.defaultValue().split(",");
                    }
                    bind(new TypeLiteral<List<String>>() {
                    }).annotatedWith(Names.named(setting.name())).toInstance(ImmutableList.copyOf(value));
                }
            }
        }
    };
}

From source file:com.facebook.presto.accumulo.conf.AccumuloConfig.java

public static AccumuloConfig fromFile(File f) throws ConfigurationException {
    if (!f.exists() || f.isDirectory()) {
        throw new ConfigurationException(format("File %s does not exist or is a directory", f));
    }/*  w w w . jav a2 s.c  o m*/
    PropertiesConfiguration props = new PropertiesConfiguration(f);
    props.setThrowExceptionOnMissing(true);

    AccumuloConfig config = new AccumuloConfig();
    config.setCardinalityCacheExpiration(
            Duration.valueOf(props.getString(CARDINALITY_CACHE_EXPIRE_DURATION, "5m")));
    config.setCardinalityCacheSize(props.getInt(CARDINALITY_CACHE_SIZE, 100_000));
    config.setInstance(props.getString(INSTANCE));
    config.setMetadataManagerClass(props.getString(METADATA_MANAGER_CLASS, "default"));
    config.setPassword(props.getString(PASSWORD));
    config.setUsername(props.getString(USERNAME));
    config.setZkMetadataRoot(props.getString(ZOOKEEPER_METADATA_ROOT, "/presto-accumulo"));
    config.setZooKeepers(props.getString(ZOOKEEPERS));
    config.setMiniAccumuloCluster(props.getBoolean(MINI_ACCUMULO_CLUSTER, false));
    return config;
}

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

protected boolean parseProperty(final String key, final String[] values,
        final Reference2ObjectMap<Enum<?>, Object> metadata) throws ConfigurationException {
    if (sameKey(PropertyBasedDocumentFactory.MetadataKeys.MIMETYPE, key)) {
        metadata.put(PropertyBasedDocumentFactory.MetadataKeys.MIMETYPE, ensureJustOne(key, values));
        return true;
    } else if (sameKey(PropertyBasedDocumentFactory.MetadataKeys.ENCODING, key)) {
        metadata.put(PropertyBasedDocumentFactory.MetadataKeys.ENCODING,
                Charset.forName(ensureJustOne(key, values)).toString());
        return true;
    } else if (sameKey(PropertyBasedDocumentFactory.MetadataKeys.WORDREADER, key)) {
        try {/*  www  .  ja  v  a  2  s .co m*/
            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;
    } else if (sameKey(MetadataKeys.MAXPREANCHOR, key)) {
        metadata.put(MetadataKeys.MAXPREANCHOR, Integer.valueOf(ensureJustOne(key, values)));
        return true;
    } else if (sameKey(MetadataKeys.MAXANCHOR, key)) {
        metadata.put(MetadataKeys.MAXANCHOR, Integer.valueOf(ensureJustOne(key, values)));
        return true;
    } else if (sameKey(MetadataKeys.MAXPOSTANCHOR, key)) {
        metadata.put(MetadataKeys.MAXPOSTANCHOR, Integer.valueOf(ensureJustOne(key, values)));
        return true;
    }

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

From source file:ch.admin.suis.msghandler.config.ClientConfiguration.java

/**
 * Adds a new sender configuration. This method does check, if a configuration with the same name has been already
 * added./*from w w w . j  a  v a  2  s.c  om*/
 *
 * @param senderConfiguration the senderConfiguration to add; cannot be <code>null</code>
 */
public void addSenderConfiguration(SenderConfiguration senderConfiguration) throws ConfigurationException {
    Validate.notNull(senderConfiguration, "sender configuration cannot be null");

    // check if we already have a configuration with the same name!
    for (SenderConfiguration existing : senderConfigurations) {
        if (StringUtils.equals(existing.getName(), senderConfiguration.getName())) {
            throw new ConfigurationException(
                    "sender configuration with the name " + senderConfiguration.getName()
                            + " already exists; this sender will not be started: " + senderConfiguration);
        }
    }
    senderConfigurations.add(senderConfiguration);
}

From source file:ch.admin.suis.msghandler.config.SedexCertConfigFactory.java

/**
 * Parses the certificateConfiguration.xml file and collects the required configuration values.
 *
 * @param xmlConfig  the config file in internal representation
 * @param configFile absolute path of the config file to be parsed
 * @throws ConfigurationException if a configuration error is detected.
 *///www.  j a  va2  s  .  c  o m
private void parseFile(XMLConfiguration xmlConfig, final String configFile) throws ConfigurationException {

    List<SedexCertConfig> sedexCfgs = new ArrayList<>();

    List privateCertificates = xmlConfig.configurationsAt("privateCertificate");

    LOG.debug("Parsing file: " + configFile);
    for (Iterator i = privateCertificates.iterator(); i.hasNext();) {
        sedexCfgs.addAll(handlePrivateCertificate(i, configFile));
    }

    if (sedexCfgs.isEmpty()) {
        throw new ConfigurationException(
                "No certificateConfiguration/privateCertificate tag found in config: " + configFile);
    }

    //Falls mehrere Sedex Config Dateien vorhanden sein sollten, dann muss jeder Eintrag ein expire Date haben!
    if (sedexCfgs.size() > 1) {
        handleMultipleCerts(sedexCfgs, configFile);
    } else {
        sedexCertConfig = sedexCfgs.get(0);
    }
}

From source file:de.teamgrit.grit.entities.Controller.java

/**
 * Restores the state of GRIT.//www  . j a v  a2 s.c  o m
 *
 * @param state
 *            the State storing the state information.
 * @throws ConfigurationException
 *             if the restoring fails.
 */
public void restoreState(State state) throws ConfigurationException {
    m_state = state;
    try {
        m_connections = state.restoreConnections();
        if (!m_connections.isEmpty()) {
            m_nextConnectionId = Collections.max(m_connections.keySet()) + 1;
        }
    } catch (InvalidStructureException e) {
        throw new ConfigurationException(e);
    }
    m_courses = state.restoreCourses();
    if (!m_courses.isEmpty()) {
        m_nextCourseId = Collections.max(m_courses.keySet()) + 1;
    }
}

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;/*www .j av  a2 s  .co 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:com.liferay.ide.server.util.CustomPropertiesConfigLayout.java

public void save(Writer out) throws ConfigurationException {
    try {/*  w ww. j  a  v  a 2 s .  co m*/
        char delimiter = getConfiguration().isDelimiterParsingDisabled() ? 0
                : getConfiguration().getListDelimiter();
        PropertiesConfiguration.PropertiesWriter writer = new CustomPropertiesWriter(out, delimiter);

        if (getHeaderComment() != null) {
            writer.writeln(getCanonicalHeaderComment(true));
            writer.writeln(null);
        }

        for (Iterator it = getKeys().iterator(); it.hasNext();) {
            String key = (String) it.next();
            if (getConfiguration().containsKey(key)) {

                // Output blank lines before property
                for (int i = 0; i < getBlancLinesBefore(key); i++) {
                    writer.writeln(null);
                }

                // Output the comment
                if (getComment(key) != null) {
                    writer.writeln(getCanonicalComment(key, true));
                }

                // Output the property and its value
                boolean singleLine = (isForceSingleLine() || isSingleLine(key))
                        && !getConfiguration().isDelimiterParsingDisabled();
                writer.writeProperty(key, getConfiguration().getProperty(key), singleLine);
            }
        }

        writer.flush();
        writer.close();
    } catch (IOException ioex) {
        throw new ConfigurationException(ioex);
    }
}