geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r479580 - /geronimo/server/branches/1.1/modules/common/src/java/org/apache/geronimo/common/propertyeditor/MapEditor.java
Date Mon, 27 Nov 2006 10:42:16 GMT
Author: vamsic007
Date: Mon Nov 27 02:42:15 2006
New Revision: 479580

URL: http://svn.apache.org/viewvc?view=rev&rev=479580
Log:
GERONIMO-2458 MapEditor does not work

Modified:
    geronimo/server/branches/1.1/modules/common/src/java/org/apache/geronimo/common/propertyeditor/MapEditor.java

Modified: geronimo/server/branches/1.1/modules/common/src/java/org/apache/geronimo/common/propertyeditor/MapEditor.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/1.1/modules/common/src/java/org/apache/geronimo/common/propertyeditor/MapEditor.java?view=diff&rev=479580&r1=479579&r2=479580
==============================================================================
--- geronimo/server/branches/1.1/modules/common/src/java/org/apache/geronimo/common/propertyeditor/MapEditor.java
(original)
+++ geronimo/server/branches/1.1/modules/common/src/java/org/apache/geronimo/common/propertyeditor/MapEditor.java
Mon Nov 27 02:42:15 2006
@@ -19,17 +19,22 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.util.Iterator;
 import java.util.Properties;
 import java.util.Map;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
- * A property editor for {@link java.util.Properties}.
+ * A property editor for {@link java.util.Map}.
  *
  * @version $Rev$ $Date$
  */
 public class MapEditor
    extends TextPropertyEditorSupport
 {
+    private static final Log log = LogFactory.getLog(MapEditor.class);
     /**
      *
      * @throws PropertyEditorException  An IOException occured.
@@ -50,11 +55,30 @@
         Map map = (Map) getValue();
         if (!(map instanceof Properties)) {
             Properties p = new Properties();
-            if (map != null) {
-                p.putAll(map);
+            if(map != null) {
+                if(!map.containsKey(null) && !map.containsValue(null)) {
+                    p.putAll(map);
+                } else {
+                    // Map contains null keys or values.  Replace null with empty string.
+                    log.warn("Map contains null keys or values.  Replacing null values with
empty string.");
+                    for(Iterator itr = map.entrySet().iterator(); itr.hasNext(); ) {
+                        Map.Entry entry = (Map.Entry) itr.next();
+                        Object key = entry.getKey();
+                        Object value = entry.getValue();
+                        if(key == null) {
+                            key = "";
+                        }
+                        if(value == null) {
+                            value = "";
+                        }
+                        p.put(key, value);
+                    }
+                }
+                map = p;
             }
-            map = p;
         }
-        return map.toString();
+        PropertiesEditor pe = new PropertiesEditor();
+        pe.setValue(map);
+        return pe.getAsText();
     }
 }



Mime
View raw message