Example usage for org.apache.commons.configuration AbstractConfiguration getDouble

List of usage examples for org.apache.commons.configuration AbstractConfiguration getDouble

Introduction

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

Prototype

public double getDouble(String key) 

Source Link

Usage

From source file:org.skb.util.types.composite.util.TSPropertyMap.java

public String loadFromFile(String fn) {
    try {//from  www .  java 2s  .c  om
        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;
}