protected String generateFilename(Configurable configurable) { return configurable.getName()+"-"+configurable.getUUID() + ".config"; }
/** * Write out the properties configuration to disk based on the UUID of the * {@link Configurable} * <br> * Default values are not stored within the file, but only those that have been changed or deleted. * * @param configurable * @throws Exception */ public void store(Configurable configurable) throws Exception { try { Map<String, String> propertyMap = configurable.getInternalPropertyMap(); Properties props = new Properties(); for (String key : propertyMap.keySet()) { if (!propertyMap.get(key).equals(configurable.getDefaultProperty(key))) { props.put(key, propertyMap.get(key)); } } File configFile = new File(baseConfigLocation,generateFilename(configurable)); logger.info("Storing configuration for "+configurable.getName()+" to "+configFile.getAbsolutePath()); props.store(new FileOutputStream(configFile), ""); } catch (Exception e) { throw new Exception("Configuration storage failed: " + e); } }
logger.info("Config file for "+configurable.getName()+" not yet created. Creating with default values."); configurable.restoreDefaults(); store(configurable); logger.error("There was a error reading the configuration file for "+configurable.getName()+", using defaults",e); configurable.restoreDefaults();