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

cvs commit: xml-xmlbeans/v2/test/cases/marshal doc2.xml

zieg        2004/05/02 22:48:15

  Modified:    v2/src/marshal/org/apache/xmlbeans/impl/marshal
                        UnmarshalResult.java
               v2/test/cases/marshal doc2.xml
  Log:
  better xsi:type handling
  
  Revision  Changes    Path
  1.22      +27 -2     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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- UnmarshalResult.java	27 Apr 2004 21:37:26 -0000	1.21
  +++ UnmarshalResult.java	3 May 2004 05:48:15 -0000	1.22
  @@ -985,16 +985,41 @@
       {
           final QName xsi_type = getXsiType();
   
  -        if (xsi_type != null) {
  +
  +        if (xsi_type != null && !xsi_type.equals(expected.getSchemaTypeName())) {
               final BindingType binding_type = lookupBindingType(xsi_type);
               if (binding_type != null) {
  -                return typeTable.createRuntimeType(binding_type, bindingLoader);
  +                final RuntimeBindingType actual_rtt =
  +                    typeTable.createRuntimeType(binding_type, bindingLoader);
  +                if (isLegalTypeSubstitution(expected, actual_rtt)) {
  +                    return actual_rtt;
  +                } else {
  +                    String e = "invalid type substitution: " +
  +                        actual_rtt.getSchemaTypeName() + " for " +
  +                        expected.getSchemaTypeName();
  +                    addError(e);
  +                }
               }
               //reaching here means some problem with extracting the
               //BindingType for the xsi type, so just use the expected one
           }
   
           return expected;
  +    }
  +
  +
  +    //is xsi:type substitution ok.  only checks java compat for now.
  +    private static boolean isLegalTypeSubstitution(RuntimeBindingType expected,
  +                                                   RuntimeBindingType actual)
  +    {
  +        if (expected == actual) return true;
  +
  +        final Class expected_type = expected.getJavaType();
  +        final Class actual_type = actual.getJavaType();
  +        if (expected_type == actual_type) return true;
  +        if (expected_type.equals(actual_type)) return true;
  +
  +        return expected_type.isAssignableFrom(actual_type);
       }
   
   
  
  
  
  1.11      +2 -1      xml-xmlbeans/v2/test/cases/marshal/doc2.xml
  
  Index: doc2.xml
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/marshal/doc2.xml,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- doc2.xml	17 Apr 2004 00:06:23 -0000	1.10
  +++ doc2.xml	3 May 2004 05:48:15 -0000	1.11
  @@ -40,7 +40,8 @@
   
   <!--        test bad xsi type TODO: handle better-->
   <!--        <n1:SomeDate xsi:type='xsd:string'>2002-03-06T08:04:39.265Z</n1:SomeDate>-->
  -        <n1:SomeDate>2002-03-06T08:04:39.265Z</n1:SomeDate>
  +        <n1:SomeDate xsi:type='xsd:dateTime'>2002-03-06T08:04:39.265Z</n1:SomeDate>
  +<!--        <n1:SomeDate>2002-03-06T08:04:39.265Z</n1:SomeDate>-->
   
   
       </n1:Myelt>
  
  
  

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