cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r924896 - /cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java
Date Thu, 18 Mar 2010 17:04:23 GMT
Author: dkulp
Date: Thu Mar 18 17:04:23 2010
New Revision: 924896

URL: http://svn.apache.org/viewvc?rev=924896&view=rev
Log:
[CXF-2720, CXF-2699] Fixes for Aegis MapType for subclasses and
minOccurs=0 elements

Modified:
    cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/collection/MapType.java

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=924896&r1=924895&r2=924896&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
Thu Mar 18 17:04:23 2010
@@ -61,8 +61,6 @@ public class MapType extends AegisType {
     public Object readObject(MessageReader reader, Context context) throws DatabindingException
{
         Map<Object, Object> map = instantiateMap();
         try {
-            AegisType kType = getKeyType();
-            AegisType vType = getValueType();
 
             while (reader.hasMoreElementReaders()) {
                 MessageReader entryReader = reader.getNextElementReader();
@@ -72,12 +70,18 @@ public class MapType extends AegisType {
                     Object value = null;
 
                     while (entryReader.hasMoreElementReaders()) {
-                                                
+
                         MessageReader evReader = entryReader.getNextElementReader();
 
                         if (evReader.getName().equals(getKeyName())) {
+                            AegisType kType = TypeUtil.getReadType(evReader.getXMLStreamReader(),
+                                                              context.getGlobalContext(),

+                                                              getKeyType());
                             key = kType.readObject(evReader, context);
                         } else if (evReader.getName().equals(getValueName())) {
+                            AegisType vType = TypeUtil.getReadType(evReader.getXMLStreamReader(),
+                                                              context.getGlobalContext(),
+                                                              getValueType());
                             value = vType.readObject(evReader, context);
                         } else {
                             readToEnd(evReader);
@@ -107,7 +111,7 @@ public class MapType extends AegisType {
      * extends the <code>Map</code> interface a <code>HashMap</code>
is
      * created. Otherwise the map classs (i.e. LinkedHashMap) is instantiated
      * using the default constructor.
-     * 
+     *
      * @return
      */
     @SuppressWarnings("unchecked")
@@ -167,10 +171,11 @@ public class MapType extends AegisType {
         MessageWriter keyWriter = entryWriter.getElementWriter(getKeyName());
         kType.writeObject(entry.getKey(), keyWriter, context);
         keyWriter.close();
-
-        MessageWriter valueWriter = entryWriter.getElementWriter(getValueName());
-        vType.writeObject(entry.getValue(), valueWriter, context);
-        valueWriter.close();
+        if (entry.getValue() != null) {
+            MessageWriter valueWriter = entryWriter.getElementWriter(getValueName());
+            vType.writeObject(entry.getValue(), valueWriter, context);
+            valueWriter.close();
+        }
 
         entryWriter.close();
     }
@@ -199,19 +204,24 @@ public class MapType extends AegisType {
         XmlSchemaSequence evSequence = new XmlSchemaSequence();
         evType.setParticle(evSequence);
 
-        createElement(evSequence, getKeyName(), kType);
-        createElement(evSequence, getValueName(), vType);
+        createElement(evSequence, getKeyName(), kType, false);
+        createElement(evSequence, getValueName(), vType, true);
     }
 
     /**
      * Creates a element in a sequence for the key type and the value type.
      */
-    private void createElement(XmlSchemaSequence seq, QName name, AegisType type) {
+    private void createElement(XmlSchemaSequence seq, QName name,
+                               AegisType type, boolean optional) {
         XmlSchemaElement element = new XmlSchemaElement();
         seq.getItems().add(element);
         element.setName(name.getLocalPart());
         element.setSchemaTypeName(type.getSchemaType());
-        element.setMinOccurs(0);
+        if (optional) {
+            element.setMinOccurs(0);
+        } else {
+            element.setMinOccurs(1);            
+        }
         element.setMaxOccurs(1);
     }
 



Mime
View raw message