Author: nextgens
Date: 2007-03-07 21:20:34 +0000 (Wed, 07 Mar 2007)
New Revision: 12018
Modified:
trunk/apps/Thaw/src/thaw/core/Config.java
trunk/apps/Thaw/src/thaw/core/Core.java
Log:
Thaw: Refactor the config. a bit: add a few comments, remove dead code
Modified: trunk/apps/Thaw/src/thaw/core/Config.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Config.java 2007-03-07 20:38:49 UTC (rev
12017)
+++ trunk/apps/Thaw/src/thaw/core/Config.java 2007-03-07 21:20:34 UTC (rev
12018)
@@ -29,19 +29,14 @@
*/
public class Config {
- private File configFile = new File("thaw.conf.xml"); /* Default name */
+ public static String CONFIG_FILE_NAME = "thaw.conf.xml";
+ private final File configFile;
- private HashMap parameters = null; /* String (param) -> String (value)
*/
- private Vector pluginNames = null; /* String (plugin names) */
+ private final HashMap parameters; /* String (param) -> String (value) */
+ private final Vector pluginNames; /* String (plugin names) */
-
- public Config() {
- this(null);
- }
-
public Config(final String filename) {
- if(filename != null)
- configFile = new File(filename);
+ configFile = new File(filename);
parameters = new HashMap();
pluginNames = new Vector();
@@ -49,25 +44,18 @@
/**
* Returns the corresponding value
+ *
* @return null if the value doesn't exit in the config.
*/
public String getValue(final String key) {
- try {
- return ((String)parameters.get(key));
- } catch(final Exception e) { /* I should see for the correct
exception */
- Logger.notice(this, "Unknow key in configuration:
'"+key+"'");
- return null;
- }
+ return ((String)parameters.get(key));
}
/**
* Set the value in the config.
*/
public void setValue(final String key, final String value) {
- if(value != null)
- Logger.info(this, "Setting value '"+key+"' to
'"+value+"'");
- else
- Logger.info(this, "Setting value '"+key+"' to null");
+ Logger.info(this, "Setting value '"+key+"' to '"+value+"'");
parameters.put(key, value);
}
@@ -181,6 +169,7 @@
/**
* Save the configuration.
+ *
* @return true if success, else false.
*/
public boolean saveConfig() {
@@ -201,8 +190,6 @@
Logger.warning(this, "Error while checking perms to
save config: "+e);
}
-
-
configOut = new StreamResult(configFile);
Document xmlDoc = null;
@@ -309,5 +296,4 @@
setDefaultValue("multipleSockets", "true");
setDefaultValue("sameComputer", "true");
}
-
}
Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java 2007-03-07 20:38:49 UTC (rev
12017)
+++ trunk/apps/Thaw/src/thaw/core/Core.java 2007-03-07 21:20:34 UTC (rev
12018)
@@ -136,9 +136,10 @@
* Init configuration. May re-set I18n.
*/
public boolean initConfig() {
- config = new Config();
+ config = new Config(Config.CONFIG_FILE_NAME);
+
+ // FIXME: awfull hack to set default values if necessary. Maybe
the freenet's config framework should be borrowed ;)
config.loadConfig();
-
config.setDefaultValues();
return true;