You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by da...@apache.org on 2004/01/10 03:31:07 UTC

cvs commit: xml-xmlbeans/v1/test/src/drt/drtcases AssortedTests.java

daveremy    2004/01/09 18:31:07

  Modified:    v1/src/typeimpl/org/apache/xmlbeans/impl/schema
                        SchemaTypeImpl.java
               v1/test/src/drt/drtcases AssortedTests.java
  Log:
  commit on behalf of Kevin Krouse.
  
  avoid a ClassCastException by ignoring the xsi:type if it is bad.
  
  Revision  Changes    Path
  1.5       +14 -8     xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java
  
  Index: SchemaTypeImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SchemaTypeImpl.java	21 Oct 2003 21:53:04 -0000	1.4
  +++ SchemaTypeImpl.java	10 Jan 2004 02:31:06 -0000	1.5
  @@ -830,12 +830,14 @@
           if (xsiType != null)
           {
               SchemaType itype = wildcardTypeLoader.findType(xsiType);
  -            if (itype == null)
  -                return BuiltinSchemaTypeSystem.ST_NO_TYPE;
  -            if (type.isAssignableFrom(itype))
  +
  +            // NOTE: a previous version of XMLBeans used ST_NO_TYPE if the
  +            // xsiType was not derived from 'type', but this results in a
  +            // ClassCastException.  Instead we ignore xsi:type if it's not
  +            // found or a derived type.
  +            if (itype != null && type.isAssignableFrom(itype)) {
                   return itype;
  -            else
  -                return BuiltinSchemaTypeSystem.ST_NO_TYPE;
  +            }
           }
   
           return type;
  @@ -894,10 +896,14 @@
               if (xsiType != null)
               {
                   SchemaType itype = wildcardTypeLoader.findType(xsiType);
  -                if (itype == null || !type.isAssignableFrom(itype))
  -                    type = BuiltinSchemaTypeSystem.ST_NO_TYPE;
  -                else
  +
  +                // NOTE: a previous version of XMLBeans used ST_NO_TYPE if the
  +                // xsiType was not derived from 'type', but this results in a
  +                // ClassCastException.  Instead we ignore xsi:type if it's not
  +                // found or a derived type.
  +                if (itype != null && type.isAssignableFrom(itype)) {
                       type = itype;
  +                }
               }
           }
   
  
  
  
  1.3       +32 -1     xml-xmlbeans/v1/test/src/drt/drtcases/AssortedTests.java
  
  Index: AssortedTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v1/test/src/drt/drtcases/AssortedTests.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AssortedTests.java	24 Sep 2003 23:31:17 -0000	1.2
  +++ AssortedTests.java	10 Jan 2004 02:31:07 -0000	1.3
  @@ -63,8 +63,10 @@
   import org.apache.xmlbeans.XmlObject;
   import org.apache.xmlbeans.XmlCursor;
   import org.apache.xmlbeans.XmlException;
  +import org.apache.xmlbeans.XmlOptions;
   import org.apache.xmlbeans.XmlTime;
   import com.easypo.XmlPurchaseOrderDocumentBean;
  +import com.easypo.XmlCustomerBean;
   import com.easypo.XmlLineItemBean;
   
   import java.math.BigInteger;
  @@ -154,6 +156,36 @@
           Assert.assertEquals(BigInteger.valueOf(200), xdoc.getPurchaseOrder().getLineItemArray(1).getQuantity());
           Assert.assertEquals(BigInteger.valueOf(4), xdoc.getPurchaseOrder().getLineItemArray(2).getQuantity());
       }
  +
  +    // bug 45338
  +    public static void testComplexGetter() throws Exception
  +    {
  +        XmlPurchaseOrderDocumentBean xdoc =
  +            XmlPurchaseOrderDocumentBean.Factory.parse(
  +                "<purchase-order xmlns='http://openuri.org/easypo'" +
  +                    " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
  +                    " xsi:type='foo'>" +
  +                 "<customer xsi:type='bar'>" +
  +                   "<name>David Bau</name>" +
  +                   "<address>100 Main Street</address>" +
  +                 "</customer>" +
  +                 "<date>2003-05-18T11:50:00</date>" +
  +                 "<line-item>" +
  +                  "<description>Blue Candy</description>" +
  +                  "<per-unit-ounces>5.0</per-unit-ounces>" +
  +                  "<quantity>1</quantity>" +
  +                 "</line-item>" +
  +                "</purchase-order>");
  +
  +        Assert.assertEquals(false, xdoc.validate());
  +        Assert.assertEquals(XmlPurchaseOrderDocumentBean.type, xdoc.schemaType());
  +
  +        // check type of element when xsi:type is bad
  +        XmlObject cust = xdoc.getPurchaseOrder().getCustomer();
  +        Assert.assertEquals(XmlCustomerBean.type, cust.schemaType());
  +
  +        Assert.assertEquals("David Bau", ((XmlCustomerBean)cust).getName());
  +    }
       
       public static void donttestPrettyPrint() throws Exception
       {
  @@ -238,6 +270,5 @@
           Assert.assertEquals("12:00:00", xt.calendarValue().toString());
       }
   
  -    
       
   }
  
  
  

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