geronimo-xbean-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r768929 - /geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/MapRecipe.java
Date Mon, 27 Apr 2009 11:31:27 GMT
Author: gnodet
Date: Mon Apr 27 11:31:27 2009
New Revision: 768929

URL: http://svn.apache.org/viewvc?rev=768929&view=rev
Log:
Add support for Dictionary on MapRecipe

Modified:
    geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/MapRecipe.java

Modified: geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/MapRecipe.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/MapRecipe.java?rev=768929&r1=768928&r2=768929&view=diff
==============================================================================
--- geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/MapRecipe.java
(original)
+++ geronimo/xbean/trunk/xbean-reflect/src/main/java/org/apache/xbean/recipe/MapRecipe.java
Mon Apr 27 11:31:27 2009
@@ -26,6 +26,9 @@
 import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
+import java.util.Dictionary;
+import java.util.AbstractMap;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
@@ -130,10 +133,14 @@
             throw new ConstructionException("Error while creating set instance: " + mapType.getName());
         }
 
-        if(!(o instanceof Map)) {
+        Map instance;
+        if (o instanceof Map) {
+            instance = (Map) o;
+        } else if (o instanceof Dictionary) {
+            instance = new DummyDictionaryAsMap((Dictionary) o);
+        } else {
             throw new ConstructionException("Specified map type does not implement the Map
interface: " + mapType.getName());
         }
-        Map instance = (Map) o;
 
         // get component type
         Type keyType = Object.class;
@@ -277,4 +284,22 @@
         }
     }
 
+    public static class DummyDictionaryAsMap extends AbstractMap {
+
+        private final Dictionary dictionary;
+
+        public DummyDictionaryAsMap(Dictionary dictionary) {
+            this.dictionary = dictionary;
+        }
+
+        @Override
+        public Object put(Object key, Object value) {
+            return dictionary.put(key, value);
+        }
+
+        public Set entrySet() {
+            throw new UnsupportedOperationException();
+        }
+    }
+
 }



Mime
View raw message