List of usage examples for org.apache.commons.configuration CompositeConfiguration getConfiguration
public Configuration getConfiguration(int index)
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)); }/* www .j a v a 2 s . co 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 {//from w w w .ja v a 2 s . c o 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.ui.KeywordPanel.java
private void configToKeywords(FFXSystem newSystem) { CompositeConfiguration properties = newSystem.getProperties(); Hashtable<String, Keyword> keywordHash = new Hashtable<>(); // Create the "Comments" property. Keyword keyword = new Keyword("COMMENTS"); keywordHash.put("COMMENTS", keyword); // Loop over properties from the keyword file. Configuration config = properties.getConfiguration(0); if (config instanceof PropertiesConfiguration) { PropertiesConfiguration prop = (PropertiesConfiguration) config; Iterator<String> keys = prop.getKeys(); while (keys.hasNext()) { String key = keys.next(); if (keywordHash.contains(key)) { keyword = keywordHash.get(key); keyword.append(prop.getStringArray(key)); } else { String[] values = prop.getStringArray(key); keyword = new Keyword(key, values); keywordHash.put(key, keyword); }/*from ww w .jav a 2 s.c o m*/ } } newSystem.setKeywords(keywordHash); }
From source file:ffx.potential.parsers.ForceFieldFilter.java
private void parse(CompositeConfiguration properties) { try {/* ww w . j a va2 s .c o 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); } }