[jboss-svn-commits] JBoss Common SVN: r2921 - in jbossxb/trunk/src: test/java/org/jboss/test/xml and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Sep 12 06:01:23 EDT 2008


Author: alex.loubyansky at jboss.com
Date: 2008-09-12 06:01:23 -0400 (Fri, 12 Sep 2008)
New Revision: 2921

Modified:
   jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
   jbossxb/trunk/src/test/java/org/jboss/test/xml/XsiTypeUnitTestCase.java
Log:
JBXB-159

Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java	2008-09-11 00:29:55 UTC (rev 2920)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java	2008-09-12 10:01:23 UTC (rev 2921)
@@ -544,7 +544,7 @@
             if(trace)
                log.trace(element.getQName() + " uses xsi:type " + xsiType);
 
-            if(item.nonXsiParticle == null)
+            if(item != null && item.nonXsiParticle == null)
                item.nonXsiParticle = particle;
             
             String xsiTypePrefix;

Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/XsiTypeUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/XsiTypeUnitTestCase.java	2008-09-11 00:29:55 UTC (rev 2920)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/XsiTypeUnitTestCase.java	2008-09-12 10:01:23 UTC (rev 2921)
@@ -88,6 +88,26 @@
       "  </complexType>" +
       "</schema>";
 
+   private static final String ONE_ADDRESS_XSD =
+      "<schema targetNamespace='" + PO_NS + "'" +
+      "  xmlns='http://www.w3.org/2001/XMLSchema'" +
+      "  xmlns:jbxb='" + Constants.NS_JBXB + "'" +
+      "  xmlns:ipo='" + PO_NS + "'>" +
+      "  <include schemaLocation='http://www.example.com/schemas/address.xsd'/>" +
+      "  <element name='address' type='ipo:Address'/>" +
+      "</schema>";
+
+   private static final String ONE_ADDRESS_XML =
+      "<ipo:address" +
+      "  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
+      "  xmlns:ipo='" + PO_NS + "'" +
+      "  exportCode='1' xsi:type='ipo:UKAddress'>" +
+      "    <name>Helen Zoe</name>" +
+      "    <street>47 Eden Street</street>" +
+      "    <city>Cambridge</city>" +
+      "    <postcode>CB1 1JR</postcode>" +
+      "</ipo:address>";
+
    private static final String PO_XSD =
       "<schema targetNamespace='" + PO_NS + "'" +
       "  xmlns='http://www.w3.org/2001/XMLSchema'" +
@@ -283,6 +303,28 @@
       assertXmlEqual(COLLECTION_XML, writer.getBuffer().toString());
    }
 
+   public void testOneAddressUnmarshalling() throws Exception
+   {
+      SchemaBinding schema = XsdBinder.bind(new StringReader(ONE_ADDRESS_XSD), null, SCHEMA_RESOLVER);
+      Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+      Object o = unmarshaller.unmarshal(new StringReader(ONE_ADDRESS_XML), schema);
+      assertEquals(PurchaseOrder.INSTANCE.shipTo, o);
+   }
+
+   public void testOneAddressMarshalling() throws Exception
+   {
+      SchemaBinding schema = XsdBinder.bind(new StringReader(ONE_ADDRESS_XSD), null, SCHEMA_RESOLVER);
+
+      MarshallerImpl marshaller = new MarshallerImpl();
+      marshaller.setSchemaResolver(SCHEMA_RESOLVER);
+      marshaller.mapClassToXsiType(UKAddress.class, PO_NS, "UKAddress");
+
+      StringWriter writer = new StringWriter();
+
+      marshaller.marshal(schema, null, PurchaseOrder.INSTANCE.shipTo, writer);
+      assertXmlEqual(ONE_ADDRESS_XML, writer.getBuffer().toString());
+   }
+
    // Inner
 
    public static final class PurchaseOrder




More information about the jboss-svn-commits mailing list