Author: toad
Date: 2006-12-16 01:01:12 +0000 (Sat, 16 Dec 2006)
New Revision: 11433

Modified:
   trunk/freenet/src/freenet/clients/http/BookmarkManager.java
   trunk/freenet/src/freenet/clients/http/SymlinkerToadlet.java
   trunk/freenet/src/freenet/config/StringArrOption.java
   trunk/freenet/src/freenet/oldplugins/plugin/PluginManager.java
   trunk/freenet/src/freenet/pluginmanager/PluginManager.java
   trunk/freenet/src/freenet/support/api/StringArrCallback.java
Log:
StringArrCallback/StringArrOption should use String[].

Modified: trunk/freenet/src/freenet/clients/http/BookmarkManager.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/BookmarkManager.java 2006-12-16 
00:43:10 UTC (rev 11432)
+++ trunk/freenet/src/freenet/clients/http/BookmarkManager.java 2006-12-16 
01:01:12 UTC (rev 11433)
@@ -33,23 +33,16 @@
        private boolean started;

        public class BookmarkCallback implements StringArrCallback {
-               public String get() {
-                       StringBuffer buf = new StringBuffer("");
-                       
-                       for (Enumeration e = bookmarks.elements(); 
e.hasMoreElements(); ) {
-                               buf.append(e.nextElement().toString());
-                               buf.append(StringArrOption.delimiter);
+               public String[] get() {
+                       synchronized(BookmarkManager.this) {
+                               String[] values = new String[bookmarks.size()];
+                               for(int i=0;i<bookmarks.size();i++)
+                                       values[i] = bookmarks.get(i).toString();
+                               return values;
                        }
-                       
-                       if (buf.length() > 0) {
-                               return buf.substring(0, buf.length() - 1);
-                       } else {
-                               return "";
-                       }
                }

-               public void set(String newval) throws 
InvalidConfigValueException {
-                       String[] newvals = 
newval.split(StringArrOption.delimiter);
+               public void set(String[] newvals) throws 
InvalidConfigValueException {
                        bookmarks.clear();
                        for (int i = 0; i < newvals.length; i++) {
                                try {

Modified: trunk/freenet/src/freenet/clients/http/SymlinkerToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/SymlinkerToadlet.java        
2006-12-16 00:43:10 UTC (rev 11432)
+++ trunk/freenet/src/freenet/clients/http/SymlinkerToadlet.java        
2006-12-16 01:01:12 UTC (rev 11433)
@@ -28,10 +28,10 @@
                tslconfig.register("symlinks", null, 9, true, false, "Symlinks 
in ToadletServer", 
                                "A list of \"alias#target\"'s that forms a 
bunch of symlinks", 
                        new StringArrCallback() {
-                       public String get() {
+                       public String[] get() {
                                return getConfigLoadString();
                        }
-                       public void set(String val) throws 
InvalidConfigValueException {
+                       public void set(String[] val) throws 
InvalidConfigValueException {
                                //if(storeDir.equals(new File(val))) return;
                                // FIXME
                                throw new InvalidConfigValueException("Cannot 
set the plugins that's loaded.");
@@ -94,7 +94,7 @@
                return ret;
        }

-       private String getConfigLoadString() {
+       private String[] getConfigLoadString() {
                String retarr[] = new String[linkMap.size()];
                synchronized (linkMap) {
                        Iterator it = linkMap.keySet().iterator();
@@ -104,7 +104,7 @@
                                retarr[i++] = key + '#' + linkMap.get(key);
                        }
                }
-               return StringArrOption.arrayToString(retarr);
+               return retarr;
        }

        public String supportedMethods() {

Modified: trunk/freenet/src/freenet/config/StringArrOption.java
===================================================================
--- trunk/freenet/src/freenet/config/StringArrOption.java       2006-12-16 
00:43:10 UTC (rev 11432)
+++ trunk/freenet/src/freenet/config/StringArrOption.java       2006-12-16 
01:01:12 UTC (rev 11433)
@@ -7,48 +7,50 @@

 public class StringArrOption extends Option {

-    private final String defaultValue;
+    private final String[] defaultValue;
     private final StringArrCallback cb;
-       private String currentValue;
+       private String[] currentValue;

     public static final String delimiter = ";";

-       public StringArrOption(SubConfig conf, String optionName, String 
defaultValue, int sortOrder, 
+       public StringArrOption(SubConfig conf, String optionName, String[] 
defaultValue, int sortOrder, 
                        boolean expert, boolean forceWrite, String shortDesc, 
String longDesc, StringArrCallback cb) {
                super(conf, optionName, sortOrder, expert, forceWrite, 
shortDesc, longDesc);
-               this.defaultValue = (defaultValue==null)?"":defaultValue;
+               this.defaultValue = (defaultValue==null)?new 
String[0]:defaultValue;
                this.cb = cb;
-               this.currentValue = (defaultValue==null)?"":defaultValue;
+               this.currentValue = (defaultValue==null)?new 
String[0]:defaultValue;
        }

-       public StringArrOption(SubConfig conf, String optionName, String 
defaultValue[], int sortOrder, 
-                       boolean expert, boolean forceWrite, String shortDesc, 
String longDesc, StringArrCallback cb) {
-               this(conf, optionName, arrayToString(defaultValue), sortOrder, 
expert, forceWrite, shortDesc, longDesc, cb);
-       }
-       
        /** Get the current value. This is the value in use if we have finished
         * initialization, otherwise it is the value set at startup (possibly 
the default). */
        public String[] getValue() {
+               if(config.hasFinishedInitialization())
+                       currentValue = cb.get();
                String[] values = getValueString().split(delimiter);
                if(values.length == 1 && values[0].length() == 0) return new 
String[0]; 
                return values;
        }

-       public void setValue(String val) throws InvalidConfigValueException {
+       public void setValue(String[] val) throws InvalidConfigValueException {
                setInitialValue(val);
                cb.set(this.currentValue);
        }

+       public void setValue(String val) throws InvalidConfigValueException {
+               setValue(val.split(delimiter));
+       }
+       
        public String getValueString() {
-               if(config.hasFinishedInitialization())
-                       currentValue = cb.get();
-               return currentValue;
+               return arrayToString(getValue());
        }

-       public void setInitialValue(String val) throws 
InvalidConfigValueException {
+       public void setInitialValue(String[] val) throws 
InvalidConfigValueException {
                this.currentValue = val;
        }

+       public void setInitialValue(String val) throws 
InvalidConfigValueException {
+               this.currentValue = val.split(delimiter);
+       }

        public static String arrayToString(String[] arr) {
                if (arr == null)
@@ -71,7 +73,7 @@
                }
        }

-       public String getDefaultValue() {
+       public String[] getDefaultValue() {
                return defaultValue;
        }


Modified: trunk/freenet/src/freenet/oldplugins/plugin/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/oldplugins/plugin/PluginManager.java      
2006-12-16 00:43:10 UTC (rev 11432)
+++ trunk/freenet/src/freenet/oldplugins/plugin/PluginManager.java      
2006-12-16 01:01:12 UTC (rev 11433)
@@ -56,22 +56,19 @@
                         * @see freenet.support.api.StringArrCallback#get()
                         * @return The current value of this option
                         */
-                       public String get() {
-                               if(plugins.size() == 0) return "";
-                               StringBuffer optionValue = new StringBuffer();
+                       public String[] get() {
+                               if(plugins.size() == 0) return new String[0];
+                               String[] retval;
                                synchronized (syncObject) {
-                                       Iterator pluginIterator = 
plugins.iterator();
-                                       while (pluginIterator.hasNext()) {
-                                               Plugin plugin = (Plugin) 
pluginIterator.next();
-                                               if (optionValue.length() != 0) {
-                                                       
optionValue.append(StringArrOption.delimiter);
-                                               }
-                                               
optionValue.append(StringArrOption.encode(plugin.getClass().getName()));
+                                       retval = new String[plugins.size()];
+                                       for(int i=0;i<plugins.size();i++) {
+                                               Plugin plugin = (Plugin) 
plugins.get(i);
+                                               retval[i] = 
plugin.getClass().getName();
                                        }
                                }
                                if(Logger.shouldLog(Logger.MINOR, this))
-                                       Logger.minor(this, "Plugin list: 
"+optionValue.toString());
-                               return optionValue.toString();
+                                       Logger.minor(this, "Plugin list: 
"+retval);
+                               return retval;
                        };

                        /**
@@ -84,10 +81,8 @@
                         *             if setting the value is not allowed, or 
the new value
                         *             is not valid
                         */
-                       public void set(String val) throws 
InvalidConfigValueException {
-                               if(val == null || get().indexOf(val) >= 0) 
return;
-                               // it's probably silly as it won't allow more 
than 1 plugin to be loaded
-                               addPlugin(val, true);
+                       public void set(String[] val) throws 
InvalidConfigValueException {
+                               throw new InvalidConfigValueException("Not 
supported");
                        };
                });


Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2006-12-16 
00:43:10 UTC (rev 11432)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2006-12-16 
01:01:12 UTC (rev 11433)
@@ -16,6 +16,7 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
+import java.util.Vector;
 import java.util.jar.JarFile;

 import freenet.config.InvalidConfigValueException;
@@ -62,10 +63,10 @@
                // Start plugins in the config
                pmconfig.register("loadplugin", null, 9, true, false, "Plugins 
to load on startup ", "Classpath, name and location for plugins to load when 
node starts up", 
                        new StringArrCallback() {
-                                       public String get() {
+                                       public String[] get() {
                                                return getConfigLoadString();
                                        }
-                                       public void set(String val) throws 
InvalidConfigValueException {
+                                       public void set(String[] val) throws 
InvalidConfigValueException {
                                                //if(storeDir.equals(new 
File(val))) return;
                                                // FIXME
                                                throw new 
InvalidConfigValueException("Cannot set the plugins that's loaded.");
@@ -90,20 +91,20 @@
                */
        }

-       private String getConfigLoadString() {
-               StringBuffer out = new StringBuffer();
+       private String[] getConfigLoadString() {
                try{
                        Iterator it = getPlugins().iterator();

-                       if (it.hasNext())
-                               
out.append(StringArrOption.encode(((PluginInfoWrapper)it.next()).getFilename()));
-                       while (it.hasNext())
-                
out.append(StringArrOption.delimiter).append(StringArrOption.encode(((PluginInfoWrapper)
 it.next()).getFilename()));
+                       Vector v = new Vector();
+                       
+                       while(it.hasNext())
+                               
v.add(((PluginInfoWrapper)it.next()).getFilename());
+                       
+                       return (String[]) v.toArray(new String[v.size()]);
                }catch (NullPointerException e){
                        Logger.error(this, "error while loading plugins: 
disabling them:"+e);
-                       return "";
+                       return new String[0];
                }
-               return out.toString();
        }

        public void startPlugin(String filename, boolean store) {

Modified: trunk/freenet/src/freenet/support/api/StringArrCallback.java
===================================================================
--- trunk/freenet/src/freenet/support/api/StringArrCallback.java        
2006-12-16 00:43:10 UTC (rev 11432)
+++ trunk/freenet/src/freenet/support/api/StringArrCallback.java        
2006-12-16 01:01:12 UTC (rev 11433)
@@ -11,7 +11,7 @@
        /**
         * Get the current, used value of the config variable.
         */
-       String get();
+       String[] get();

        /**
         * Set the config variable to a new value.
@@ -19,6 +19,6 @@
         * @throws InvalidConfigOptionException If the new value is invalid for 
         * this particular option.
         */
-       void set(String val) throws InvalidConfigValueException;
+       void set(String[] val) throws InvalidConfigValueException;

 }


Reply via email to