xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/src/drt/drtcases MarshalTests.java
Date Fri, 09 Apr 2004 21:54:16 GMT
zieg        2004/04/09 14:54:16

  Modified:    v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        MarshalStreamUtils.java UnmarshalResult.java
                        WrappedArrayTypeVisitor.java
               v2/test/src/drt/drtcases MarshalTests.java
  Log:
  fix problem with xsi:nil on the root element or object
  
  Revision  Changes    Path
  1.20      +11 -8     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalStreamUtils.java
  
  Index: MarshalStreamUtils.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/MarshalStreamUtils.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- MarshalStreamUtils.java	1 Apr 2004 22:04:36 -0000	1.19
  +++ MarshalStreamUtils.java	9 Apr 2004 21:54:16 -0000	1.20
  @@ -158,17 +158,17 @@
           //TODO: seem to be rechecking assertion, why not skip one ahead...
   
           try {
  +            int event = reader.getEventType();
   
  -            for (int state = reader.getEventType(); reader.hasNext();
  -                 state = reader.next()) {
  -                switch (state) {
  +            while (true) {
  +                switch (event) {
                       case XMLStreamReader.START_ELEMENT:
                           cnt++;
                           break;
                       case XMLStreamReader.END_ELEMENT:
                           if (cnt == 0) {
  -                            assert reader.hasNext();
  -                            reader.next();
  +                            if (reader.hasNext())
  +                                reader.next(); // move past end element
                               return;
                           } else {
                               cnt--;
  @@ -180,14 +180,17 @@
                       default:
                           break;
                   }
  +
  +                if (reader.hasNext()) {
  +                    event = reader.next();
  +                } else {
  +                    throw new XmlException("unexpected end of xml stream");
  +                }
               }
           }
           catch (XMLStreamException xse) {
               throw new XmlException(xse);
           }
  -
  -        //should not happen for well-formed xml
  -        throw new XmlException("unexpected end of xml stream");
       }
   
   
  
  
  
  1.16      +12 -7     xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshalResult.java
  
  Index: UnmarshalResult.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/UnmarshalResult.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- UnmarshalResult.java	6 Apr 2004 00:53:09 -0000	1.15
  +++ UnmarshalResult.java	9 Apr 2004 21:54:16 -0000	1.16
  @@ -179,17 +179,22 @@
       private Object unmarshalBindingType(BindingType bindingType)
           throws XmlException
       {
  -        TypeUnmarshaller um =
  -            typeTable.getOrCreateTypeUnmarshaller(bindingType, bindingLoader);
  -
           this.updateAttributeState();
   
  -        ObjectFactory of = extractObjectFactory();
  +        final TypeUnmarshaller um;
  +        final ObjectFactory of = extractObjectFactory();
           if (of == null) {
  +            if (hasXsiNil())
  +                um = NullUnmarshaller.getInstance();
  +            else
  +                um = typeTable.getOrCreateTypeUnmarshaller(bindingType,
  +                                                           bindingLoader);
               return um.unmarshal(this);
           } else {
               final RuntimeBindingType rtt = getRuntimeType(bindingType);
               final Object initial_obj = of.createObject(rtt.getJavaType());
  +            um = typeTable.getOrCreateTypeUnmarshaller(bindingType,
  +                                                       bindingLoader);
               um.unmarshal(initial_obj, this);
               return initial_obj;
           }
  @@ -938,6 +943,9 @@
       TypeUnmarshaller determineTypeUnmarshaller(TypeUnmarshaller base)
           throws XmlException
       {
  +        if (hasXsiNil())
  +            return NullUnmarshaller.getInstance();
  +
           final QName xsi_type = getXsiType();
   
           if (xsi_type != null) {
  @@ -952,9 +960,6 @@
               //reaching here means some problem with extracting the
               //unmarshaller for the xsi type, so just use the expected one
           }
  -
  -        if (hasXsiNil())
  -            return NullUnmarshaller.getInstance();
   
           return base;
       }
  
  
  
  1.3       +2 -0      xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/WrappedArrayTypeVisitor.java
  
  Index: WrappedArrayTypeVisitor.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/src/marshal/org/apache/xmlbeans/impl/marshal/WrappedArrayTypeVisitor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WrappedArrayTypeVisitor.java	6 Mar 2004 01:46:00 -0000	1.2
  +++ WrappedArrayTypeVisitor.java	9 Apr 2004 21:54:16 -0000	1.3
  @@ -84,6 +84,8 @@
   
       private static int getArrayLength(Object obj)
       {
  +        if (obj == null) return 0;
  +
           return Array.getLength(obj);
       }
   
  
  
  
  1.50      +38 -0     xml-xmlbeans/v2/test/src/drt/drtcases/MarshalTests.java
  
  Index: MarshalTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/drt/drtcases/MarshalTests.java,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- MarshalTests.java	6 Apr 2004 00:53:09 -0000	1.49
  +++ MarshalTests.java	9 Apr 2004 21:54:16 -0000	1.50
  @@ -413,6 +413,44 @@
       }
   
   
  +    public void testWrappedArray()
  +        throws Exception
  +    {
  +        String[] strs = new String[]{"aa", null, "bb", "cc"};
  +        final String java_type = strs.getClass().getName();
  +        strs = null;  // testing...
  +
  +        BindingContext bindingContext = getBindingContext(getBindingConfigDocument());
  +
  +        final XmlOptions options = new XmlOptions();
  +        Collection errors = new LinkedList();
  +        options.setErrorListener(errors);
  +
  +        Marshaller ctx =
  +            bindingContext.createMarshaller();
  +
  +        Assert.assertNotNull(ctx);
  +
  +        final QName element_name = new QName("java:com.mytest", "string-array");
  +        final QName schema_type = new QName("java:com.mytest", "ArrayOfString");
  +        final XMLStreamReader reader =
  +            ctx.marshalType(strs, element_name, schema_type, java_type, options);
  +
  +        inform("=======WRAPPED-ARRAY-OBJ: " + strs);
  +
  +//        dumpReader(reader);
  +        Assert.assertTrue(errors.isEmpty());
  +
  +        final Unmarshaller um = bindingContext.createUnmarshaller();
  +        Object retval = um.unmarshalType(reader, schema_type, java_type, options);
  +        Assert.assertTrue(errors.isEmpty());
  +
  +        Assert.assertTrue("expected " + ArrayUtils.arrayToString(strs) +
  +                          " got " + ArrayUtils.arrayToString(retval),
  +                          ArrayUtils.arrayEquals(strs, retval));
  +    }
  +
  +
       public void testByNameMarshalViaWriter()
           throws Exception
       {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org


Mime
View raw message