commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r552279 - in /jakarta/commons/proper/beanutils/trunk/src: java/org/apache/commons/beanutils/ test/org/apache/commons/beanutils/
Date Sun, 01 Jul 2007 11:04:28 GMT
Author: niallp
Date: Sun Jul  1 04:04:26 2007
New Revision: 552279

URL: http://svn.apache.org/viewvc?view=rev&rev=552279
Log:
BEANUTILS-285 and BEANUTILS-258 - revert incompatible changes to prevent possible compatibility
problems

Modified:
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java
    jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/ConvertUtilsBean.java
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java
    jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/DynaBeanUtilsTestCase.java

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java?view=diff&rev=552279&r1=552278&r2=552279
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/BeanUtilsBean.java
Sun Jul  1 04:04:26 2007
@@ -398,7 +398,11 @@
 
         // Convert the specified value to the required type and store it
         if (index >= 0) {                    // Destination must be indexed
-            value = getConvertUtils().convert(value, type.getComponentType());
+            Converter converter = getConvertUtils().lookup(type.getComponentType());
+            if (converter != null) {
+                log.trace("        USING CONVERTER " + converter);
+                value = converter.convert(type.getComponentType(), value);
+            }
             try {
                 getPropertyUtils().setIndexedProperty(target, propName,
                                                  index, value);
@@ -418,7 +422,11 @@
                     (e, "Cannot set " + propName);
             }
         } else {                             // Destination must be simple
-            value = getConvertUtils().convert(value, type);
+            Converter converter = getConvertUtils().lookup(type);
+            if (converter != null) {
+                log.trace("        USING CONVERTER " + converter);
+                value = converter.convert(type, value);
+            }
             try {
                 getPropertyUtils().setSimpleProperty(target, propName, value);
             } catch (NoSuchMethodException e) {
@@ -957,25 +965,17 @@
 
         // Convert the specified value to the required type
         Object newValue = null;
-        Class sourceType = value == null ? null : value.getClass();
-        Class targetType = (type.isArray() && (index >= 0) ? type.getComponentType()
: type);
-        Converter converter = getConvertUtils().lookup(sourceType, targetType);
-        if (converter != null) {
-            newValue = converter.convert(targetType, value);
-            newValue = (targetType == String.class && newValue != null ? newValue.toString()
: newValue);
-        } else if (type.isArray() && (index < 0)) { // Scalar value into array
+        if (type.isArray() && (index < 0)) { // Scalar value into array
             if (value == null) {
                 String values[] = new String[1];
                 values[0] = (String) value;
-                newValue = getConvertUtils().convert(values, type);
+                newValue = getConvertUtils().convert((String[]) values, type);
             } else if (value instanceof String) {
-                String values[] = new String[1];
-                values[0] = (String) value;
-                newValue = getConvertUtils().convert(values, type);
+                newValue = getConvertUtils().convert(value, type);
             } else if (value instanceof String[]) {
                 newValue = getConvertUtils().convert((String[]) value, type);
             } else {
-                newValue = value;
+                newValue = getConvertUtils().convert(value, type);
             }
         } else if (type.isArray()) {         // Indexed value into array
             if (value instanceof String || value == null) {
@@ -985,7 +985,7 @@
                 newValue = getConvertUtils().convert(((String[]) value)[0],
                                                 type.getComponentType());
             } else {
-                newValue = value;
+                newValue = getConvertUtils().convert(value, type.getComponentType());
             }
         } else {                             // Value into scalar
             if ((value instanceof String) || (value == null)) {

Modified: jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/ConvertUtilsBean.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/ConvertUtilsBean.java?view=diff&rev=552279&r1=552278&r2=552279
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/ConvertUtilsBean.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/ConvertUtilsBean.java
Sun Jul  1 04:04:26 2007
@@ -431,10 +431,12 @@
             if (value == null) {
                 return ((String) null);
             } else {
-                return ((String)convert(value, String.class));
+                Converter converter = lookup(String.class);
+                return ((String) converter.convert(String.class, value));
             }
         } else {
-            return ((String)convert(value, String.class));
+            Converter converter = lookup(String.class);
+            return ((String) converter.convert(String.class, value));
         }
 
     }
@@ -485,10 +487,6 @@
 
         Class type = clazz;
         if (clazz.isArray()) {
-            Converter converter = lookup(clazz);
-            if (converter != null) {
-                return converter.convert(clazz, values);
-            }
             type = clazz.getComponentType();
         }
         if (log.isDebugEnabled()) {

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java?view=diff&rev=552279&r1=552278&r2=552279
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java
Sun Jul  1 04:04:26 2007
@@ -795,7 +795,7 @@
         assertTrue("stringArray of correct type",
                    newValue instanceof String[]);
         assertEquals("stringArray length",
-                     0, ((String[]) newValue).length);
+                     1, ((String[]) newValue).length);
         PropertyUtils.setProperty(bean, "stringArray", oldValue);
 
         // Indexed value into array

Modified: jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/DynaBeanUtilsTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/DynaBeanUtilsTestCase.java?view=diff&rev=552279&r1=552278&r2=552279
==============================================================================
--- jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/DynaBeanUtilsTestCase.java
(original)
+++ jakarta/commons/proper/beanutils/trunk/src/test/org/apache/commons/beanutils/DynaBeanUtilsTestCase.java
Sun Jul  1 04:04:26 2007
@@ -907,7 +907,7 @@
         assertTrue("stringArray of correct type",
                    newValue instanceof String[]);
         assertEquals("stringArray length",
-                     0, ((String[]) newValue).length);
+                     1, ((String[]) newValue).length);
         PropertyUtils.setProperty(bean, "stringArray", oldValue);
 
         // Indexed value into array



---------------------------------------------------------------------
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