public void load(String filename) { Map data = FileUtil.readResilientConfigFile(filename, false); // horrendous recursive loading going on here due to logger + config depedencies. If already // loaded // then use the existing data as it might have already been written to... if (propertiesMap == null) { ConcurrentHashMapWrapper<String, Object> c_map = new ConcurrentHashMapWrapper<String, Object>(data.size() + 256, 0.75f, 8); c_map.putAll(data); propertiesMap = c_map; } /* * Can't do this yet. Sometimes, there's a default set to x, but the code * calls get..Parameter(..., y). y != x. When the user sets the the parameter * to x, we remove it from the list. Later, the get..Parameter(.., y) returns * y because there is no entry. * * The solution is to not allow get..Parameter(.., y) when there's a default * value. Another reason to not allow it is that having two defaults confuses * coders. * // Remove entries that are default. Saves memory, reduces // file size when saved again ConfigurationDefaults def = ConfigurationDefaults.getInstance(); Iterator it = new TreeSet(propertiesMap.keySet()).iterator(); while (it.hasNext()) { String key = (String)it.next(); Object defValue = def.getDefaultValueAsObject(key); if (defValue == null) continue; if (defValue instanceof Long) { int iDefValue = ((Long)defValue).intValue(); int iValue = getIntParameter(key, iDefValue); if (iValue == iDefValue) propertiesMap.remove(key); } if (defValue instanceof String) { String sDefValue = defValue.toString(); String sValue = getStringParameter(key, sDefValue); if (sValue.compareTo(sDefValue) == 0) propertiesMap.remove(key); } } */ }
public void save(String filename) { if (propertiesMap == null) { // nothing to save, initialisation not complete return; } /** * Note - propertiesMap isn't synchronised! We'll clone the map now, because we need to modify * it. The BEncoding code will create a new map object (TreeMap) because it needs to be sorted, * so we might as well do it here too. */ TreeMap<String, Object> properties_clone = propertiesMap.toTreeMap(); // Remove any transient parameters. if (!this.transient_properties.isEmpty()) { properties_clone.keySet().removeAll(this.transient_properties); } FileUtil.writeResilientConfigFile(filename, properties_clone); List<COConfigurationListener> listeners_copy; synchronized (listenerz) { listeners_copy = new ArrayList<COConfigurationListener>(listenerz); } for (int i = 0; i < listeners_copy.size(); i++) { COConfigurationListener l = (COConfigurationListener) listeners_copy.get(i); if (l != null) { try { l.configurationSaved(); } catch (Throwable e) { Debug.printStackTrace(e); } } else { Debug.out("COConfigurationListener is null"); } } if (exported_parameters_dirty) { exportParameters(); } }
public String getDirectoryParameter(String parameter) throws IOException { String dir = getStringParameter(parameter); if (dir.length() > 0) { File temp = new File(dir); if (!temp.exists()) { FileUtil.mkdirs(temp); } if (!temp.isDirectory()) { throw new IOException("Configuration error. This is not a directory: " + dir); } } return dir; }