Author: toad
Date: 2006-02-21 00:55:09 +0000 (Tue, 21 Feb 2006)
New Revision: 8075

Modified:
   branches/config/src/freenet/config/BooleanOption.java
   branches/config/src/freenet/config/Config.java
   branches/config/src/freenet/config/FilePersistentConfig.java
   branches/config/src/freenet/config/IntOption.java
   branches/config/src/freenet/config/LongOption.java
   branches/config/src/freenet/config/Option.java
   branches/config/src/freenet/config/ShortOption.java
   branches/config/src/freenet/config/StringOption.java
   branches/config/src/freenet/config/SubConfig.java
Log:
Config options are now successfully saved to disk and loaded from disk.
At least, listenPort is.

Modified: branches/config/src/freenet/config/BooleanOption.java
===================================================================
--- branches/config/src/freenet/config/BooleanOption.java       2006-02-20 
23:02:06 UTC (rev 8074)
+++ branches/config/src/freenet/config/BooleanOption.java       2006-02-21 
00:55:09 UTC (rev 8075)
@@ -39,5 +39,14 @@
        public String getValueString() {
                return Boolean.toString(getValue());
        }
+
+       public void setInitialValue(String val) throws 
InvalidConfigValueException {
+               if(val.equalsIgnoreCase("true") || val.equalsIgnoreCase("yes")) 
{
+                       currentValue = true;
+               } else if(val.equalsIgnoreCase("false") || 
val.equalsIgnoreCase("no")) {
+                       currentValue = false;
+               } else
+                       throw new OptionFormatException("Unrecognized boolean: 
"+val);
+       }

 }

Modified: branches/config/src/freenet/config/Config.java
===================================================================
--- branches/config/src/freenet/config/Config.java      2006-02-20 23:02:06 UTC 
(rev 8074)
+++ branches/config/src/freenet/config/Config.java      2006-02-21 00:55:09 UTC 
(rev 8075)
@@ -32,5 +32,9 @@
        public void finishedInit() {
                // Do nothing
        }
+
+       public void onRegister(SubConfig config, Option o) {
+               // Do nothing
+       }

 }

Modified: branches/config/src/freenet/config/FilePersistentConfig.java
===================================================================
--- branches/config/src/freenet/config/FilePersistentConfig.java        
2006-02-20 23:02:06 UTC (rev 8074)
+++ branches/config/src/freenet/config/FilePersistentConfig.java        
2006-02-21 00:55:09 UTC (rev 8075)
@@ -114,4 +114,15 @@
                }
                return fs;
        }
+       
+       public void onRegister(SubConfig config, Option o) {
+               if(origConfigFileContents == null) return;
+               String name = 
config.prefix+SimpleFieldSet.MULTI_LEVEL_CHAR+o.name;
+               String val = origConfigFileContents.get(name);
+               try {
+                       o.setInitialValue(val);
+               } catch (InvalidConfigValueException e) {
+                       Logger.error(this, "Could not parse config option 
"+name+": "+e, e);
+               }
+       }
 }

Modified: branches/config/src/freenet/config/IntOption.java
===================================================================
--- branches/config/src/freenet/config/IntOption.java   2006-02-20 23:02:06 UTC 
(rev 8074)
+++ branches/config/src/freenet/config/IntOption.java   2006-02-21 00:55:09 UTC 
(rev 8075)
@@ -48,6 +48,12 @@
                cachedStringValue = val;
                currentValue = x;
        }
+       
+       public void setInitialValue(String val) {
+               int x = Fields.parseInt(val);
+               cachedStringValue = val;
+               currentValue = x;
+       }

        public String getValueString() {
                if(cachedStringValue != null) return cachedStringValue;

Modified: branches/config/src/freenet/config/LongOption.java
===================================================================
--- branches/config/src/freenet/config/LongOption.java  2006-02-20 23:02:06 UTC 
(rev 8074)
+++ branches/config/src/freenet/config/LongOption.java  2006-02-21 00:55:09 UTC 
(rev 8075)
@@ -54,4 +54,10 @@
                return Long.toString(getValue());
        }

+       public void setInitialValue(String val) throws 
InvalidConfigValueException {
+               long x = Fields.parseLong(val);
+               cachedStringValue = val;
+               currentValue = x;
+       }
+
 }

Modified: branches/config/src/freenet/config/Option.java
===================================================================
--- branches/config/src/freenet/config/Option.java      2006-02-20 23:02:06 UTC 
(rev 8074)
+++ branches/config/src/freenet/config/Option.java      2006-02-21 00:55:09 UTC 
(rev 8075)
@@ -30,5 +30,12 @@
        public abstract void setValue(String val) throws 
InvalidConfigValueException;

        public abstract String getValueString();
+
+       /** Set to a value from the config file; this is not passed on to the 
callback, as we
+        * expect the client-side initialization to check the value. The 
callback is not valid
+        * until the client calls finishedInitialization().
+        * @throws InvalidConfigValueException 
+        */
+       public abstract void setInitialValue(String val) throws 
InvalidConfigValueException;

 }

Modified: branches/config/src/freenet/config/ShortOption.java
===================================================================
--- branches/config/src/freenet/config/ShortOption.java 2006-02-20 23:02:06 UTC 
(rev 8074)
+++ branches/config/src/freenet/config/ShortOption.java 2006-02-21 00:55:09 UTC 
(rev 8075)
@@ -33,5 +33,10 @@
        public String getValueString() {
                return Short.toString(getValue());
        }
+
+       public void setInitialValue(String val) throws 
InvalidConfigValueException {
+               short x = Fields.parseShort(val);
+               currentValue = x;
+       }

 }

Modified: branches/config/src/freenet/config/StringOption.java
===================================================================
--- branches/config/src/freenet/config/StringOption.java        2006-02-20 
23:02:06 UTC (rev 8074)
+++ branches/config/src/freenet/config/StringOption.java        2006-02-21 
00:55:09 UTC (rev 8075)
@@ -30,5 +30,9 @@
        public String getValueString() {
                return getValue();
        }
+
+       public void setInitialValue(String val) throws 
InvalidConfigValueException {
+               this.currentValue = val;
+       }

 }

Modified: branches/config/src/freenet/config/SubConfig.java
===================================================================
--- branches/config/src/freenet/config/SubConfig.java   2006-02-20 23:02:06 UTC 
(rev 8074)
+++ branches/config/src/freenet/config/SubConfig.java   2006-02-21 00:55:09 UTC 
(rev 8075)
@@ -23,14 +23,18 @@
                this.prefix = prefix;
                map = new HashMap();
                hasInitialized = false;
+               config.register(this);
        }

-       public synchronized void register(Option o) {
-               if(o.name.indexOf(SimpleFieldSet.MULTI_LEVEL_CHAR) != -1)
-                       throw new IllegalArgumentException("Option names must 
not contain "+SimpleFieldSet.MULTI_LEVEL_CHAR);
-               if(map.containsKey(o.name))
-                       throw new IllegalArgumentException("Already registered: 
"+o.name+" on "+this);
-               map.put(o.name, o);
+       public void register(Option o) {
+               synchronized(this) {
+                       if(o.name.indexOf(SimpleFieldSet.MULTI_LEVEL_CHAR) != 
-1)
+                               throw new IllegalArgumentException("Option 
names must not contain "+SimpleFieldSet.MULTI_LEVEL_CHAR);
+                       if(map.containsKey(o.name))
+                               throw new IllegalArgumentException("Already 
registered: "+o.name+" on "+this);
+                       map.put(o.name, o);
+               }
+               config.onRegister(this, o);
        }

        public void register(String optionName, int defaultValue, int sortOrder,
@@ -123,7 +127,6 @@
         */
        public void finishedInitialization() {
                hasInitialized = true;
-               config.register(this);
        }

        /**


Reply via email to