Example usage for org.apache.commons.configuration CompositeConfiguration getNumberOfConfigurations

List of usage examples for org.apache.commons.configuration CompositeConfiguration getNumberOfConfigurations

Introduction

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

Prototype

public int getNumberOfConfigurations() 

Source Link

Document

Return the number of configurations.

Usage

From source file:com.kixeye.chassis.bootstrap.Application.java

private void closeConfiguration(org.apache.commons.configuration.Configuration configuration)
        throws IOException {
    if (configuration instanceof CompositeConfiguration) {
        CompositeConfiguration config = (CompositeConfiguration) configuration;
        for (int i = 0; i < config.getNumberOfConfigurations(); i++) {
            closeConfiguration(config.getConfiguration(i));
        }/* w w  w. j  a v a  2s.  c  o  m*/
    } else if (configuration instanceof AggregatedConfiguration) {
        AggregatedConfiguration config = (AggregatedConfiguration) configuration;
        for (int i = 0; i < config.getNumberOfConfigurations(); i++) {
            closeConfiguration(config.getConfiguration(i));
        }
    } else {
        if (configuration instanceof DynamicWatchedConfiguration) {
            DynamicWatchedConfiguration dynamicWatchedConfiguration = (DynamicWatchedConfiguration) configuration;
            if (dynamicWatchedConfiguration.getSource() instanceof Closeable) {
                Closeables.close((Closeable) dynamicWatchedConfiguration.getSource(), true);
            }
        }
    }
}

From source file:ffx.autoparm.ForceFieldFilter_2.java

private void parse(CompositeConfiguration properties) {
    try {/* www.j a  v  a2 s .  co m*/
        int numConfigs = properties.getNumberOfConfigurations();
        /**
         * Loop over the configurations starting with lowest precedence.
         * This way higher precedence entries will overwrite lower
         * precedence entries within the ForceField instance.
         */
        for (int n = numConfigs - 1; n >= 0; n--) {
            Configuration config = properties.getConfiguration(n);
            Iterator i = config.getKeys();
            while (i.hasNext()) {
                String key = (String) i.next();
                ForceFieldType type = null;
                try {
                    type = ForceFieldType.valueOf(key.toUpperCase());
                } catch (Exception e) {
                    continue;
                }
                String list[] = config.getStringArray(key);
                for (String s : list) {
                    // Add back the key to the input line.
                    s = key + " " + s;
                    String tokens[] = s.trim().split(" +");
                    String input = s;
                    switch (type) {
                    case ATOM:
                        parseAtom(input, tokens);
                        break;
                    case ANGLE:
                        parseAngle(input, tokens);
                        break;
                    case BIOTYPE:
                        parseBioType(input, tokens);
                        break;
                    case BOND:
                        parseBond(input, tokens);
                        break;
                    case CHARGE:
                        parseCharge(input, tokens);
                        break;
                    case MULTIPOLE:
                        parseMultipole(input, tokens);
                        break;
                    case OPBEND:
                        parseOPBend(input, tokens);
                        break;
                    case STRBND:
                        parseStrBnd(input, tokens);
                        break;
                    case PITORS:
                        parsePiTorsion(input, tokens);
                        break;
                    case TORSION:
                        parseTorsion(input, tokens);
                        break;
                    case TORTORS:
                        parseTorsionTorsion(input, tokens);
                        break;
                    case UREYBRAD:
                        parseUreyBradley(input, tokens);
                        break;
                    case VDW:
                        parseVDW(input, tokens);
                        break;
                    case POLARIZE:
                        parsePolarize(input, tokens);
                        break;
                    default:
                        logger.warning("ForceField type recognized, but not stored:" + type);
                    }
                }
            }
        }
        //forceField.checkPolarizationTypes();
    } catch (Exception e) {
        String message = "Exception parsing force field.";
        logger.log(Level.WARNING, message, e);
    }
}

From source file:ffx.potential.parsers.ForceFieldFilter.java

private void parse(CompositeConfiguration properties) {
    try {/*ww w  . j  a  va2  s .  co  m*/
        int numConfigs = properties.getNumberOfConfigurations();
        /**
         * Loop over the configurations starting with lowest precedence.
         * This way higher precedence entries will overwrite lower
         * precedence entries within the ForceField instance.
         */
        for (int n = numConfigs - 1; n >= 0; n--) {
            Configuration config = properties.getConfiguration(n);
            Iterator i = config.getKeys();
            while (i.hasNext()) {
                String key = (String) i.next();

                /**
                 * If the key is not recognized as a force field keyword,
                 * continue to the next key.
                 */
                if (!ForceField.isForceFieldKeyword(key)) {
                    continue;
                }

                String list[] = config.getStringArray(key);
                for (String s : list) {
                    // Add back the key to the input line.
                    s = key + " " + s;

                    // Split the line on the pound symbol to remove comments.
                    String input = s.split("#+")[0];
                    String tokens[] = input.trim().split(" +");

                    // Parse keywords.
                    if (parseKeyword(tokens)) {
                        continue;
                    }

                    // Parse force field types.
                    ForceFieldType type;
                    try {
                        type = ForceFieldType.valueOf(key.toUpperCase());
                    } catch (Exception e) {
                        break;
                    }

                    switch (type) {
                    case ATOM:
                        parseAtom(input, tokens);
                        break;
                    case ANGLE:
                        parseAngle(input, tokens);
                        break;
                    case BIOTYPE:
                        parseBioType(input, tokens);
                        break;
                    case BOND:
                        parseBond(input, tokens);
                        break;
                    case CHARGE:
                        parseCharge(input, tokens);
                        break;
                    case MULTIPOLE:
                        parseMultipole(input, tokens);
                        break;
                    case OPBEND:
                        parseOPBend(input, tokens);
                        break;
                    case STRBND:
                        parseStrBnd(input, tokens);
                        break;
                    case PITORS:
                        parsePiTorsion(input, tokens);
                        break;
                    case IMPTORS:
                        parseImproper(input, tokens);
                        break;
                    case TORSION:
                        parseTorsion(input, tokens);
                        break;
                    case TORTORS:
                        parseTorsionTorsion(input, tokens);
                        break;
                    case UREYBRAD:
                        parseUreyBradley(input, tokens);
                        break;
                    case VDW:
                        parseVDW(input, tokens);
                        break;
                    case POLARIZE:
                        parsePolarize(input, tokens);
                        break;
                    case ISOLVRAD:
                        parseISolvRad(input, tokens);
                        break;
                    case RELATIVESOLV:
                        parseRelativeSolvation(input, tokens);
                        break;
                    default:
                        logger.log(Level.WARNING, "ForceField type recognized, but not stored:{0}", type);
                    }
                }
            }
        }
        forceField.checkPolarizationTypes();
    } catch (Exception e) {
        String message = "Exception parsing force field.";
        logger.log(Level.WARNING, message, e);
    }
}