cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r726724 - in /cxf/trunk/rt/databinding/aegis/src: main/java/org/apache/cxf/aegis/type/basic/ main/java/org/apache/cxf/aegis/type/collection/ main/java/org/apache/cxf/aegis/xml/stax/ test/java/org/apache/cxf/aegis/type/map/ test/java/org/apa...
Date Mon, 15 Dec 2008 16:09:44 GMT
Author: bimargulies
Date: Mon Dec 15 08:09:43 2008
New Revision: 726724

URL: http://svn.apache.org/viewvc?rev=726724&view=rev
Log:
CXF-1947

Fix Boolean and String types to handle xsi:nil correctly. Amazing that 
no one noticed this. Also fix original report of messing up nil values
in maps.

Modified:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BooleanType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/StringType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementReader.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/map/MapsTest.java
    cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/map/fortest/MapTestImpl.java

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BooleanType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BooleanType.java?rev=726724&r1=726723&r2=726724&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BooleanType.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BooleanType.java
Mon Dec 15 08:09:43 2008
@@ -24,16 +24,24 @@
 import org.apache.cxf.aegis.xml.MessageWriter;
 
 /**
- * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
+ * Aegis type for {@link java.lang.Boolean}. These can be null.
  */
 public class BooleanType extends Type {
     @Override
     public Object readObject(MessageReader reader, Context context) {
+        if (reader.isXsiNil()) {
+            reader.readToEnd();
+            return null;
+        }
         return Boolean.valueOf(reader.getValueAsBoolean());
     }
 
     @Override
     public void writeObject(Object object, MessageWriter writer, Context context) {
-        writer.writeValueAsBoolean(((Boolean)object).booleanValue());
+        if (object == null) {
+            writer.writeXsiNil();
+        } else {
+            writer.writeValueAsBoolean(((Boolean)object).booleanValue());
+        }
     }
 }

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/StringType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/StringType.java?rev=726724&r1=726723&r2=726724&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/StringType.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/StringType.java
Mon Dec 15 08:09:43 2008
@@ -38,6 +38,10 @@
 
     @Override
     public void writeObject(Object object, MessageWriter writer, Context context) {
-        writer.writeValue(object);
+        if (object == null && isNillable()) {
+            writer.writeXsiNil();
+        } else {
+            writer.writeValue(object);
+        }
     }
 }

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java?rev=726724&r1=726723&r2=726724&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java
Mon Dec 15 08:09:43 2008
@@ -64,14 +64,15 @@
             Type kType = getKeyType();
             Type vType = getValueType();
 
-            Object key = null;
-            Object value = null;
-
             while (reader.hasMoreElementReaders()) {
                 MessageReader entryReader = reader.getNextElementReader();
 
                 if (entryReader.getName().equals(getEntryName())) {
+                    Object key = null;
+                    Object value = null;
+
                     while (entryReader.hasMoreElementReaders()) {
+                                                
                         MessageReader evReader = entryReader.getNextElementReader();
 
                         if (evReader.getName().equals(getKeyName())) {

Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementReader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementReader.java?rev=726724&r1=726723&r2=726724&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementReader.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementReader.java
Mon Dec 15 08:09:43 2008
@@ -124,6 +124,10 @@
     public String getValue() {
         if (value == null) {
             try {
+                if (isXsiNil()) {
+                    readToEnd();
+                    return null;
+                }
                 value = root.getElementText();
                 
                 hasCheckedChildren = true;

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/map/MapsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/map/MapsTest.java?rev=726724&r1=726723&r2=726724&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/map/MapsTest.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/map/MapsTest.java
Mon Dec 15 08:09:43 2008
@@ -86,6 +86,16 @@
     }
     
     @Test
+    public void testNull() throws Exception {
+        ObjectWithAMap obj1 = clientInterface.returnObjectWithAMap();
+        assertNull(obj1.getTheMap().get("raw"));
+        Map<Long, String> m = clientInterface.getMapLongToString();
+        String str2 = m.get(Long.valueOf(2)); 
+        assertNull("value for 2 should be null, was " + str2, str2);
+                  
+    }
+    
+    @Test
     public void testObjectsWithMaps() throws Exception {
         ObjectWithAMap obj1 = clientInterface.returnObjectWithAMap();
         ObjectWithAMapNs2 obj2 = clientInterface.returnObjectWithAMapNs2();
@@ -95,7 +105,7 @@
         assertNotNull(obj1.getTheMap());
         assertNotNull(obj2.getTheMap()); 
         
-        assertEquals(2, obj1.getTheMap().size());
+        assertEquals(3, obj1.getTheMap().size());
         assertEquals(3, obj2.getTheMap().size());
         
         assertTrue(obj1.getTheMap().get("rainy"));

Modified: cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/map/fortest/MapTestImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/map/fortest/MapTestImpl.java?rev=726724&r1=726723&r2=726724&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/map/fortest/MapTestImpl.java
(original)
+++ cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/map/fortest/MapTestImpl.java
Mon Dec 15 08:09:43 2008
@@ -39,6 +39,7 @@
     public ObjectWithAMap returnObjectWithAMap() {
         ObjectWithAMap ret = new ObjectWithAMap();
         ret.getTheMap().put("rainy", Boolean.TRUE);
+        ret.getTheMap().put("raw", null);
         ret.getTheMap().put("sunny", Boolean.FALSE);
         return ret;
     }
@@ -46,6 +47,7 @@
     public Map<Long, String> getMapLongToString() {
         Map<Long, String> map = new HashMap<Long, String>();
         map.put(Long.valueOf(1), "one");
+        map.put(Long.valueOf(2), null);
         map.put(Long.valueOf(27), "twenty-seven");
         return map;
     }



Mime
View raw message