commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r306972 - in /jakarta/commons/proper/beanutils/trunk/src: java/org/apache/commons/beanutils/LazyDynaMap.java test/org/apache/commons/beanutils/LazyDynaMapTestCase.java
Date Fri, 07 Oct 2005 01:35:10 GMT
Author: niallp
Date: Thu Oct  6 18:34:59 2005
New Revision: 306972

URL: http://svn.apache.org/viewcvs?rev=306972&view=rev
Log: (empty)

Modified:
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/LazyDynaMap.java
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/LazyDynaMapTestCase.java

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/LazyDynaMap.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/LazyDynaMap.java?rev=306972&r1=306971&r2=306972&view=diff
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/LazyDynaMap.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/LazyDynaMap.java
Thu Oct  6 18:34:59 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -249,7 +249,24 @@
      * with this DynaClass.
      */
     public DynaBean newInstance()  {
-        return new LazyDynaMap(this);
+
+        // Create a new instance of the Map
+        Map newMap = null;
+        try {
+            newMap = (Map)getMap().getClass().newInstance();
+        } catch(Exception ex) {
+            newMap = newMap();
+        }
+
+        // Crate new LazyDynaMap and initialize properties
+        LazyDynaMap lazyMap = new LazyDynaMap(newMap);
+        DynaProperty[] properties = this.getDynaProperties();
+        if (properties != null) {
+            for (int i = 0; i < properties.length; i++) {
+                lazyMap.add(properties[i]);
+            }
+        }
+        return lazyMap;
     }
 
 

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/LazyDynaMapTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/LazyDynaMapTestCase.java?rev=306972&r1=306971&r2=306972&view=diff
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/LazyDynaMapTestCase.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/LazyDynaMapTestCase.java
Thu Oct  6 18:34:59 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,8 +15,10 @@
  */
 package org.apache.commons.beanutils;
 
+import java.util.Map;
 import java.util.HashMap;
 import java.util.TreeMap;
+import java.util.List;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.lang.reflect.InvocationTargetException;
@@ -481,6 +483,27 @@
         } catch (IllegalArgumentException expected) {
             // expected result
         }
+    }
+
+    /**
+     * Test creating using DynaClass.newInstance()
+     */
+    public void testNewInstance() {
+
+        // Create LazyDynaMap using TreeMap 
+        // containing some properties
+        LazyDynaMap orig = new LazyDynaMap(new TreeMap());
+        orig.set("indexProp", 0, "indexVal0");
+        orig.set("indexProp", 2, "indexVal1");
+        assertEquals("Index prop size", 1, ((List)orig.get("indexProp")).size());
+        
+        LazyDynaMap newOne = (LazyDynaMap)orig.newInstance();
+        Map newMap = newOne.getMap();
+        assertEquals("Check Map type", TreeMap.class, newMap.getClass());
+        
+        ArrayList indexProp = (ArrayList)newMap.get("indexProp");
+        assertNotNull("Indexed Prop missing", indexProp);
+        assertEquals("Index prop size", 0, indexProp.size());
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message