List of usage examples for org.apache.commons.configuration AbstractConfiguration getInteger
public Integer getInteger(String key, Integer defaultValue)
From source file:com.netflix.paas.config.base.ConfigurationProxyUtils.java
static Supplier<?> getStaticSupplier(Class<?> type, String key, String defaultValue, AbstractConfiguration configuration) { if (type.isAssignableFrom(String.class)) { return Suppliers.ofInstance(configuration.getString(key, defaultValue)); } else if (type.isAssignableFrom(Integer.class)) { return Suppliers.ofInstance( configuration.getInteger(key, defaultValue == null ? 0 : Integer.parseInt(defaultValue))); } else if (type.isAssignableFrom(Double.class)) { return Suppliers.ofInstance( configuration.getDouble(key, defaultValue == null ? 0.0 : Double.parseDouble(defaultValue))); } else if (type.isAssignableFrom(Long.class)) { return Suppliers.ofInstance( configuration.getLong(key, defaultValue == null ? 0L : Long.parseLong(defaultValue))); } else if (type.isAssignableFrom(Boolean.class)) { return Suppliers.ofInstance(configuration.getBoolean(key, defaultValue == null ? false : Boolean.parseBoolean(defaultValue))); }/*from w w w . j av a 2 s. com*/ throw new RuntimeException("Unsupported value type " + type.getCanonicalName()); }
From source file:org.skb.util.types.composite.util.TSPropertyMap.java
public String loadFromFile(String fn) { try {/*w w w.j av a 2s. c o m*/ AbstractConfiguration cfg; String prefix = ""; if (fn.endsWith(".ini")) { cfg = new INIConfiguration(fn); prefix = "tribe."; } else if (fn.endsWith(".xml")) cfg = new XMLConfiguration(fn); else if (fn.endsWith(".properties")) cfg = new PropertiesConfiguration(fn); else return "unknown configuration file format, use '.ini' or '.xml' or '.properties'"; File file = new File(fn); if (!file.canRead()) return "can't read configuration file <" + fn + ">"; Iterator<?> it; if (prefix != "") it = cfg.getKeys(prefix); else it = cfg.getKeys(); while (it.hasNext()) { String p = it.next().toString(); if (this.containsKey(p)) { String type = this.get(p, TSPropertyMap.pmValType).toString(); if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_STRING)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getString(p)); else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_BOOLEAN)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getBoolean(p, false)); else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_INTEGER)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getInteger(p, 0)); else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_DOUBLE)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getDouble(p)); else if (type.equals(TSRepository.TString.TS_ATOMIC_JAVA_LONG)) this.put(p, TSPropertyMap.pmValValueFile, cfg.getLong(p, 0)); // else // System.err.println("TSPropMap, loadfromfile, unknown type <"+type+"> for <"+p+">"); } } } catch (Exception e) { // ReportManager repMgr=ReportManager.getInstance(); // repMgr.reportErrorNoFile(e.toString()); } return null; }