2006-07-27 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 27 Jul 2006 15:15:12 +0000 (15:15 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 27 Jul 2006 15:15:12 +0000 (15:15 -0000)
* XmlSchema.cs, XmlSchemaSimpleTypeList.cs,
  XmlSchemaSimpleContentRestriction.cs, XmlSchemaUtil.cs,
  XmlSchemaSimpleContentExtension.cs, XmlSchemaElement.cs,
  XmlSchemaComplexType.cs, XmlSchemaSimpleTypeRestriction.cs,
  XmlSchemaSimpleTypeUnion.cs, XmlSchemaAttribute.cs :
  Finally fixed bugs around cross-referencing importing schema
  components (namely, #77489 and #78220) by resolving referenced
  components via new internal Find[Element|Attribute|AttributeGroup|
  SchemaType] methods in XmlSchema.

* XmlSchemaSetTest.cs : added bug #77489 case.
* XmlSchemaCollectionTests.cs : removed NotWorking from #77820 case.

svn path=/trunk/mcs/; revision=63042

14 files changed:
mcs/class/System.XML/System.Xml.Schema/ChangeLog
mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaAttribute.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaComplexType.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaElement.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaSimpleContentExtension.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaSimpleContentRestriction.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaSimpleTypeList.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaSimpleTypeRestriction.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaSimpleTypeUnion.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaUtil.cs
mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog
mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaCollectionTests.cs
mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaSetTests.cs

index 8bf2002640a4a5a3fa396848424552ad3b9b6be2..62a47641891458cb8564dc312d098fb8431734f7 100644 (file)
@@ -1,3 +1,15 @@
+2006-07-27  Atsushi Enomoto <atsushi@ximian.com>
+
+       * XmlSchema.cs, XmlSchemaSimpleTypeList.cs,
+         XmlSchemaSimpleContentRestriction.cs, XmlSchemaUtil.cs,
+         XmlSchemaSimpleContentExtension.cs, XmlSchemaElement.cs,
+         XmlSchemaComplexType.cs, XmlSchemaSimpleTypeRestriction.cs,
+         XmlSchemaSimpleTypeUnion.cs, XmlSchemaAttribute.cs :
+         Finally fixed bugs around cross-referencing importing schema 
+         components (namely, #77489 and #78220) by resolving referenced
+         components via new internal Find[Element|Attribute|AttributeGroup|
+         SchemaType] methods in XmlSchema.
+
 2006-07-27  Atsushi Enomoto <atsushi@ximian.com>
 
        * XmlSchema.cs : set ValidationEventHandler to XmlSchemaSet only
index 3033dcf21f7a0f905641ae02c0513645c2c21eaa..0745b526ae0f7a0ff1fbe51df567af31edeb247b 100644 (file)
@@ -566,6 +566,50 @@ namespace System.Xml.Schema
 
                #endregion
 
+               internal XmlSchemaAttribute FindAttribute (XmlQualifiedName name)
+               {
+                       XmlSchemaAttribute a;
+                       foreach (XmlSchema schema in schemas.Schemas ()) {
+                               a = schema.Attributes [name] as XmlSchemaAttribute;
+                               if (a != null)
+                                       return a;
+                       }
+                       return null;
+               }
+
+               internal XmlSchemaAttributeGroup FindAttributeGroup (XmlQualifiedName name)
+               {
+                       XmlSchemaAttributeGroup a;
+                       foreach (XmlSchema schema in schemas.Schemas ()) {
+                               a = schema.AttributeGroups [name] as XmlSchemaAttributeGroup;
+                               if (a != null)
+                                       return a;
+                       }
+                       return null;
+               }
+
+               internal XmlSchemaElement FindElement (XmlQualifiedName name)
+               {
+                       XmlSchemaElement a;
+                       foreach (XmlSchema schema in schemas.Schemas ()) {
+                               a = schema.Elements [name] as XmlSchemaElement;
+                               if (a != null)
+                                       return a;
+                       }
+                       return null;
+               }
+
+               internal XmlSchemaType FindSchemaType (XmlQualifiedName name)
+               {
+                       XmlSchemaType a;
+                       foreach (XmlSchema schema in schemas.Schemas ()) {
+                               a = schema.SchemaTypes [name] as XmlSchemaType;
+                               if (a != null)
+                                       return a;
+                       }
+                       return null;
+               }
+
                internal void Validate (ValidationEventHandler handler)
                {
                        ValidationId = CompilationId;
index 47bac444b37a6fd0eebf4c7fdd05104e7efa3191..999416cce27b837da165cf4efe8cb032d406e7a8 100644 (file)
@@ -380,7 +380,7 @@ namespace System.Xml.Schema
                        else if (SchemaTypeName != null && SchemaTypeName != XmlQualifiedName.Empty)\r
                        {\r
                                // If type is null, then it is missing sub components .\r
-                               XmlSchemaType type = schema.SchemaTypes [SchemaTypeName] as XmlSchemaType;\r
+                               XmlSchemaType type = schema.FindSchemaType (SchemaTypeName);\r
                                if (type is XmlSchemaComplexType)\r
                                        error(h,"An attribute can't have complexType Content");\r
                                else if (type != null) {        // simple type\r
@@ -402,7 +402,7 @@ namespace System.Xml.Schema
                        // Then, fill type information for the type references for the referencing attributes\r
                        if (RefName != null && RefName != XmlQualifiedName.Empty)\r
                        {\r
-                               referencedAttribute = schema.Attributes [RefName] as XmlSchemaAttribute;\r
+                               referencedAttribute = schema.FindAttribute (RefName);\r
                                // If el is null, then it is missing sub components .\r
                                if (referencedAttribute != null)\r
                                        errorCount += referencedAttribute.Validate (h, schema);\r
index 025896a0b6c16ae706d9ab76e7af36e1bd48dd07..c834c34f5d795e24ba2d1a852d29947f6213a2ec 100644 (file)
@@ -385,7 +385,7 @@ namespace System.Xml.Schema
                        if (contentModel != null) {\r
                                BaseSchemaTypeName = contentModel.Content != null ? contentModel.Content.GetBaseTypeName () : XmlQualifiedName.Empty;\r
 \r
-                               BaseXmlSchemaTypeInternal = schema.SchemaTypes [BaseSchemaTypeName] as XmlSchemaType;\r
+                               BaseXmlSchemaTypeInternal = schema.FindSchemaType(BaseSchemaTypeName);\r
                        }\r
                        // Resolve redefine.\r
                        if (this.isRedefineChild && BaseXmlSchemaType != null && this.QualifiedName == BaseSchemaTypeName) {\r
index a0b52d6beaa888755149effc281dd1d72a8c67e7..944a2709d1452f007b757db72e3919b0bd45a7f8 100644 (file)
@@ -653,7 +653,7 @@ namespace System.Xml.Schema
                        if (schemaType != null)\r
                                elementType = schemaType;\r
                        else if (SchemaTypeName != XmlQualifiedName.Empty) {\r
-                               XmlSchemaType type = schema.SchemaTypes [SchemaTypeName] as XmlSchemaType;\r
+                               XmlSchemaType type = schema.FindSchemaType (SchemaTypeName);\r
                                if (type != null) {\r
                                        type.Validate (h, schema);\r
                                        elementType = type;\r
index 5b55860e86210e3c6f40bf18995963016805c6ee..e224ac223a05df2b573969128dffbacc0c98013c 100644 (file)
@@ -149,7 +149,7 @@ namespace System.Xml.Schema
                        if (IsValidated (schema.ValidationId))\r
                                return errorCount;\r
 \r
-                       XmlSchemaType st = schema.SchemaTypes [baseTypeName] as XmlSchemaType;\r
+                       XmlSchemaType st = schema.FindSchemaType (baseTypeName);\r
                        if (st != null) {\r
                                XmlSchemaComplexType ct = st as XmlSchemaComplexType;\r
                                if (ct != null && ct.ContentModel is XmlSchemaComplexContent)\r
index 31e658d2e941030dc042a58da7eb88cc70b212a1..49276e01d61ad9808e42ab03f2f2ec7e16dde973 100644 (file)
@@ -184,7 +184,7 @@ namespace System.Xml.Schema
                                actualBaseSchemaType = baseType;\r
                        }\r
                        else if (baseTypeName != XmlQualifiedName.Empty) {\r
-                               XmlSchemaType st = schema.SchemaTypes [baseTypeName] as XmlSchemaType;\r
+                               XmlSchemaType st = schema.FindSchemaType (baseTypeName);\r
                                if (st != null) {\r
                                        st.Validate (h, schema);\r
                                        actualBaseSchemaType = st;\r
index 63e0bd1d976b4d08fa9ae66dc3b0e3f7d96e3aee..bdbc812753a47f7ad4d6c831d69ed19b56577e6f 100644 (file)
@@ -128,7 +128,7 @@ namespace System.Xml.Schema
                        // ListItemType\r
                        XmlSchemaSimpleType type = itemType;\r
                        if (type == null)\r
-                               type = schema.SchemaTypes [itemTypeName] as XmlSchemaSimpleType;\r
+                               type = schema.FindSchemaType (itemTypeName) as XmlSchemaSimpleType;\r
                        if (type != null) {\r
                                errorCount += type.Validate (h, schema);\r
                                validatedListItemType = type;\r
index 3795ad83780217013953f68cf64973be3521df47..e13f5fa794f8a9247545a0e2c19f0b0cd0cccdde 100644 (file)
@@ -383,7 +383,7 @@ namespace System.Xml.Schema
 \r
                        XmlSchemaSimpleType type = baseType;\r
                        if (type == null)\r
-                               type = schema.SchemaTypes [baseTypeName] as XmlSchemaSimpleType;\r
+                               type = schema.FindSchemaType (baseTypeName) as XmlSchemaSimpleType;\r
                        if (type != null) {\r
                                if (validate)\r
                                        errorCount += type.Validate (h, schema);\r
index 97f12b4cae725a20b80a3c201a59439d2213b04b..dfe50c1d0c905ea1736279e01381c6aa0c4277d4 100644 (file)
@@ -140,7 +140,7 @@ namespace System.Xml.Schema
                        if (MemberTypes != null) {\r
                                foreach (XmlQualifiedName memberTypeName in MemberTypes) {\r
                                        object type = null;\r
-                                       XmlSchemaType xstype = schema.SchemaTypes [memberTypeName] as XmlSchemaSimpleType;\r
+                                       XmlSchemaType xstype = schema.FindSchemaType (memberTypeName) as XmlSchemaSimpleType;\r
                                        if (xstype != null) {\r
                                                errorCount += xstype.Validate (h, schema);\r
                                                type = xstype;\r
index 6888737e56c0eebada317231545e75d0baca90ab..7cba123719a2657b13397fcf33b93050aae0b142 100644 (file)
@@ -514,7 +514,7 @@ namespace System.Xml.Schema
                                        if (redefined != null && grpRef.RefName == redefined.QualifiedName)\r
                                                grp = redefined;\r
                                        else\r
-                                               grp = schema.AttributeGroups [grpRef.RefName] as XmlSchemaAttributeGroup;\r
+                                               grp = schema.FindAttributeGroup (grpRef.RefName);\r
                                        // otherwise, it might be missing sub components.\r
                                        if (grp == null) {\r
                                                if (!schema.missedSubComponents)// && schema.Schemas [grpRef.RefName.Namespace] != null)\r
index a66160f252b06c1b4f525a69556c3b084bc1400f..ef54e59465f633478419d44fccec4c34944da6af 100644 (file)
@@ -1,3 +1,8 @@
+2006-07-27  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XmlSchemaSetTest.cs : added bug #77489 case.
+       * XmlSchemaCollectionTests.cs : removed NotWorking from #77820 case.
+
 2006-07-27  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XmlSchemaSetTests.cs : added AddWrongTargetNamespace().
index bf04de20f21547f268f812b3594bb665a00e042b..e5e29639980eed16eefe89fcffcad06a1b686b47 100644 (file)
@@ -79,7 +79,6 @@ namespace MonoTests.System.Xml
                }
 
                [Test] // bug #78220
-               [Category ("NotWorking")]
                public void TestCompile ()
                {
                        string schemaFragment1 = string.Format (CultureInfo.InvariantCulture,
index d2c260e7ef51fc64b965f07f4d52f0f47c4a2e0b..86d1d55815aa1a8d2bf1a9e6565232da0dd0934b 100644 (file)
@@ -165,6 +165,34 @@ namespace MonoTests.System.Xml
                        ss.RemoveRecursive (s);
                        Assert.IsTrue (ss.IsCompiled, "#5");
                }
+
+               [Test] // bug #77489
+               public void CrossSchemaReferences ()
+               {
+                       string schema1 = @"<xsd:schema id=""Base.Schema"" elementFormDefault=""qualified"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
+       <xsd:complexType name=""itemBase"" abstract=""true""> 
+               <xsd:attribute name=""id"" type=""xsd:string""
+use=""required""/> 
+               <xsd:attribute name=""type"" type=""xsd:string""
+use=""required""/> 
+       </xsd:complexType> 
+</xsd:schema>";
+
+                       string schema2 = @"<xsd:schema id=""Sub.Schema"" elementFormDefault=""qualified"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
+       <xsd:complexType name=""item""> 
+               <xsd:complexContent> 
+                       <xsd:extension base=""itemBase""> 
+                               <xsd:attribute name=""itemName""
+type=""xsd:string"" use=""required""/> 
+                       </xsd:extension> 
+               </xsd:complexContent> 
+       </xsd:complexType> 
+</xsd:schema>";
+                       XmlSchemaSet schemas = new XmlSchemaSet ();
+                       schemas.Add (XmlSchema.Read (new StringReader (schema1), null));
+                       schemas.Add (XmlSchema.Read (new StringReader (schema2), null));
+                       schemas.Compile ();
+               }
        }
 }
 #endif