2004-01-09 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Fri, 9 Jan 2004 17:55:57 +0000 (17:55 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Fri, 9 Jan 2004 17:55:57 +0000 (17:55 -0000)
* XmlSchemaSet.cs : implemented some members.
* XmlSchemaCollection.cs : modified to use internal schema set (This
  class provides more precise schema validation feature and will be
  commonly used for XPathNavigator2).
  Added .NET 1.1 .ctor() which takes XmlResolver.
* XmlSchema.cs : fix related to above changes.
  Use validation event handler on Read() at all required places.
  Added .NET 1.1 .ctor() which takes XmlResolver.
* XmlSchemaComplexType.cs : content type comparison was incorrect.
  Renamed confusing method.
* XmlSchemaElement.cs : don't use ContentTypeParticle in
  CheckRecursion(), where that property might not be determined yet.
* XmlSchemaGroupBase.cs : Modified ValidateRecurse() a bit (currently
  no effect)
* XmlSchemaGroupBase.cs,
  XmlSchemaChoice.cs,
  XmlSchemaAll.cs,
  XmlSchemaSequence.cs : moved CheckRecursion to XmlSchemaGroupBase.
* XmlSchemaObjectTable.cs : Fixed missing error info.
* BUGS-MS.txt : Added info a bit.

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

mcs/class/System.XML/System.Xml.Schema/BUGS-MS.txt
mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaAll.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaChoice.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaCollection.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/XmlSchemaGroupBase.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaObjectTable.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaSequence.cs
mcs/class/System.XML/System.Xml.Schema/XmlSchemaSet.cs

index 76d4e05ca559e4c4dc60ce8fea93f7f30c518d87..577378d730f1a2ac14ad6db4597025955609d649 100755 (executable)
@@ -87,7 +87,7 @@ BUGS in MS Implementation of XmlSchema:
        </xsd:choice>\r
        </xsd:complexType>\r
 \r
-       Related msxsdtest is mgH014.xsd.\r
+       Related msxsdtest is groupG001.xsd and mgH014.xsd.\r
 \r
 009. derived list incorrectly allowed\r
 \r
index 03a8d365f7741b86777144e5b402fa07a36bfb39..43776d144b3ae5bd739664a49de89cc822958553 100755 (executable)
@@ -49,7 +49,6 @@ namespace System.Xml.Schema
                private XmlSchemaCollection schemas;\r
 \r
                private XmlNameTable nameTable;\r
-               private XmlResolver resolver;\r
 \r
                internal bool missedSubComponents;\r
 \r
@@ -255,19 +254,27 @@ namespace System.Xml.Schema
                 ///             5. version should be a normalizedString\r
                 ///             6. xml:lang should be a language\r
                 /// </remarks>\r
-                [MonoTODO]\r
-                public void Compile(ValidationEventHandler handler)\r
+                public void Compile (ValidationEventHandler handler)\r
                {\r
-                       Compile (handler, new Stack (), this, null);\r
+                       Compile (handler, new XmlUrlResolver ());\r
+               }\r
+\r
+#if NET_1_0\r
+                internal void Compile (ValidationEventHandler handler, XmlResolver resolver)\r
+#else\r
+                public void Compile (ValidationEventHandler handler, XmlResolver resolver)\r
+#endif\r
+               {\r
+                       Compile (handler, new Stack (), this, null, resolver);\r
                        isCompiled = true;\r
                }\r
 \r
-               internal void Compile (ValidationEventHandler handler, XmlSchemaCollection col)\r
+               internal void Compile (ValidationEventHandler handler, XmlSchemaCollection col, XmlResolver resolver)\r
                {\r
-                       Compile (handler, new Stack (), this, col);\r
+                       Compile (handler, new Stack (), this, col, resolver);\r
                }\r
 \r
-               private void Compile (ValidationEventHandler handler, Stack schemaLocationStack, XmlSchema rootSchema, XmlSchemaCollection col)\r
+               private void Compile (ValidationEventHandler handler, Stack schemaLocationStack, XmlSchema rootSchema, XmlSchemaCollection col, XmlResolver resolver)\r
                 {\r
                        if (rootSchema != this) {\r
                                CompilationId = rootSchema.CompilationId;\r
@@ -277,19 +284,19 @@ namespace System.Xml.Schema
                                schemas = col;\r
                                if (schemas == null) {\r
                                        schemas = new XmlSchemaCollection ();\r
-                                       schemas.CompilationId = Guid.NewGuid ();\r
+                                       schemas.SchemaSet.CompilationId = Guid.NewGuid ();\r
                                }\r
-                               CompilationId = schemas.CompilationId;\r
+                               CompilationId = schemas.SchemaSet.CompilationId;\r
                                this.idCollection.Clear ();\r
                        }\r
                        schemas.Add (this);\r
 \r
-                       attributeGroups = new XmlSchemaObjectTable ();\r
-                       attributes = new XmlSchemaObjectTable ();\r
-                       elements = new XmlSchemaObjectTable ();\r
-                       groups = new XmlSchemaObjectTable ();\r
-                       notations = new XmlSchemaObjectTable ();\r
-                       schemaTypes = new XmlSchemaObjectTable ();\r
+                       attributeGroups.Clear ();\r
+                       attributes.Clear ();\r
+                       elements.Clear ();\r
+                       groups.Clear ();\r
+                       notations.Clear ();\r
+                       schemaTypes.Clear ();\r
 \r
                        //1. Union and List are not allowed in block default\r
                         if(BlockDefault != XmlSchemaDerivationMethod.All)\r
@@ -340,20 +347,21 @@ namespace System.Xml.Schema
                                 {\r
                                        if (ext.SchemaLocation == null) \r
                                                continue;\r
-                                       string url = GetResolvedUri (ext.SchemaLocation);\r
                                        Stream stream = null;\r
-                                       if (schemaLocationStack.Contains (url)) {\r
-                                               error(handler, "Nested inclusion was found: " + url);\r
-                                               // must skip this inclusion\r
-                                               continue;\r
-                                       }\r
-                                       try {\r
-                                               if (resolver == null)\r
-                                                       resolver = new XmlUrlResolver ();\r
-                                               stream = resolver.GetEntity (new Uri (url), null, typeof (Stream)) as Stream;\r
-                                       } catch (Exception) {\r
-                                               // FIXME: This is not good way to handle errors.\r
-                                               stream = null;\r
+                                       string url = null;\r
+                                       if (resolver != null) {\r
+                                               url = GetResolvedUri (resolver, ext.SchemaLocation);\r
+                                               if (schemaLocationStack.Contains (url)) {\r
+                                                       error(handler, "Nested inclusion was found: " + url);\r
+                                                       // must skip this inclusion\r
+                                                       continue;\r
+                                               }\r
+                                               try {\r
+                                                       stream = resolver.GetEntity (new Uri (url), null, typeof (Stream)) as Stream;\r
+                                               } catch (Exception) {\r
+                                               // LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch.\r
+                                                       stream = null;\r
+                                               }\r
                                        }\r
 \r
                                        // Process redefinition children in advance.\r
@@ -405,7 +413,7 @@ namespace System.Xml.Schema
 \r
                                        // Compile included schema.\r
                                        includedSchema.idCollection = this.IDCollection;\r
-                                       includedSchema.Compile (handler, schemaLocationStack, rootSchema, col);\r
+                                       includedSchema.Compile (handler, schemaLocationStack, rootSchema, col, resolver);\r
                                        schemaLocationStack.Pop ();\r
 \r
                                        if (import != null)\r
@@ -445,6 +453,8 @@ namespace System.Xml.Schema
                                         errorCount += numerr;\r
                                         if(numerr == 0)\r
                                         {\r
+                                               if (!attr.IsComplied (this.CompilationId))\r
+                                                       schemas.SchemaSet.GlobalAttributes.Add (attr.QualifiedName, attr);\r
                                                 XmlSchemaUtil.AddToTable (Attributes, attr, attr.QualifiedName, handler);\r
                                         }\r
                                 }\r
@@ -466,6 +476,8 @@ namespace System.Xml.Schema
                                         errorCount += numerr;\r
                                         if(numerr == 0)\r
                                         {\r
+                                               if (!ctype.IsComplied (this.CompilationId))\r
+                                                       schemas.SchemaSet.GlobalTypes.Add (ctype.QualifiedName, ctype);\r
                                                 XmlSchemaUtil.AddToTable (schemaTypes, ctype, ctype.QualifiedName, handler);\r
                                         }\r
                                 }\r
@@ -477,6 +489,8 @@ namespace System.Xml.Schema
                                         errorCount += numerr;\r
                                         if(numerr == 0)\r
                                         {\r
+                                               if (!stype.IsComplied (this.CompilationId))\r
+                                                       schemas.SchemaSet.GlobalTypes.Add (stype.QualifiedName, stype);\r
                                                 XmlSchemaUtil.AddToTable (SchemaTypes, stype, stype.QualifiedName, handler);\r
                                         }\r
                                 }\r
@@ -488,6 +502,8 @@ namespace System.Xml.Schema
                                         errorCount += numerr;\r
                                         if(numerr == 0)\r
                                         {\r
+                                               if (!elem.IsComplied (this.CompilationId))\r
+                                                       schemas.SchemaSet.GlobalElements.Add (elem.QualifiedName, elem);\r
                                                 XmlSchemaUtil.AddToTable (Elements, elem, elem.QualifiedName, handler);\r
                                         }\r
                                 }\r
@@ -524,12 +540,12 @@ namespace System.Xml.Schema
                                Validate(handler);\r
                }\r
 \r
-               private string GetResolvedUri (string relativeUri)\r
+               private string GetResolvedUri (XmlResolver resolver, string relativeUri)\r
                {\r
                        Uri baseUri = null;\r
                        if (this.SourceUri != null && this.SourceUri != String.Empty)\r
                                baseUri = new Uri (this.SourceUri);\r
-                       return new XmlUrlResolver ().ResolveUri (baseUri, relativeUri).ToString ();\r
+                       return resolver.ResolveUri (baseUri, relativeUri).ToString ();\r
                }\r
 \r
                internal bool IsNamespaceAbsent (string ns)\r
@@ -539,7 +555,6 @@ namespace System.Xml.Schema
 \r
                 #endregion\r
 \r
-                [MonoTODO]\r
                 private void Validate(ValidationEventHandler handler)\r
                 {\r
                        ValidationId = CompilationId;\r
@@ -572,28 +587,19 @@ namespace System.Xml.Schema
 \r
                 #region Read\r
 \r
-                public static XmlSchema Read(TextReader reader, ValidationEventHandler validationEventHandler)\r
+               // We cannot use xml deserialization, since it does not provide line info, qname context, and so on.\r
+                public static XmlSchema Read (TextReader reader, ValidationEventHandler validationEventHandler)\r
                 {\r
-                        return Read(new XmlTextReader(reader),validationEventHandler);\r
+                        return Read (new XmlTextReader (reader),validationEventHandler);\r
                 }\r
-                public static XmlSchema Read(Stream stream, ValidationEventHandler validationEventHandler)\r
+                public static XmlSchema Read (Stream stream, ValidationEventHandler validationEventHandler)\r
                 {\r
-                        return Read(new XmlTextReader(stream),validationEventHandler);\r
+                        return Read (new XmlTextReader (stream),validationEventHandler);\r
                 }\r
 \r
-               [MonoTODO ("Use ValidationEventHandler")]\r
-                public static XmlSchema Read(XmlReader rdr, ValidationEventHandler validationEventHandler)\r
+                public static XmlSchema Read (XmlReader rdr, ValidationEventHandler validationEventHandler)\r
                 {\r
-/*\r
-                       string baseURI = rdr.BaseURI;\r
-                        XmlSerializer xser = new XmlSerializer (typeof (XmlSchema));\r
-                        XmlSchema schema = (XmlSchema) xser.Deserialize (rdr);\r
-                       schema.SourceUri = baseURI;\r
-                       schema.Compile (validationEventHandler);\r
-                       schema.nameTable = rdr.NameTable;\r
-                       return schema;\r
-*/\r
-                       XmlSchemaReader reader = new XmlSchemaReader(rdr, validationEventHandler);\r
+                       XmlSchemaReader reader = new XmlSchemaReader (rdr, validationEventHandler);\r
 \r
                        if (reader.ReadState == ReadState.Initial)\r
                                reader.ReadNextElement ();\r
@@ -604,42 +610,43 @@ namespace System.Xml.Schema
                         {\r
                                 switch(reader.NodeType)\r
                                 {\r
-                                        case XmlNodeType.Element:\r
-                                                if(reader.LocalName == "schema")\r
-                                                {\r
-                                                        XmlSchema schema = new XmlSchema();\r
-                                                       schema.nameTable = rdr.NameTable;\r
-\r
-                                                        schema.LineNumber = reader.LineNumber;\r
-                                                        schema.LinePosition = reader.LinePosition;\r
-                                                        schema.SourceUri = reader.BaseURI;\r
-\r
-                                                        ReadAttributes(schema, reader, validationEventHandler);\r
-                                                        //IsEmptyElement does not behave properly if reader is\r
-                                                        //positioned at an attribute.\r
-                                                        reader.MoveToElement();\r
-                                                        if(!reader.IsEmptyElement)\r
-                                                        {\r
-                                                                ReadContent(schema, reader, validationEventHandler);\r
-                                                        }\r
-                                                                                                               else\r
-                                                                                                                       rdr.Skip ();\r
-                                                                                                                       \r
-                                                       if (rdr.NodeType == XmlNodeType.EndElement)\r
-                                                               rdr.Read ();\r
-                                                        return schema;\r
-                                                }\r
-                                                else\r
-                                                {\r
-                                                        //Schema can't be generated. Throw an exception\r
-                                                        throw new XmlSchemaException("The root element must be schema", null);\r
-                                                }\r
-                                        default:\r
-                                                error(validationEventHandler, "This should never happen. XmlSchema.Read 1 ",null);\r
-                                                break;\r
+                                case XmlNodeType.Element:\r
+                                       if(reader.LocalName == "schema")\r
+                                       {\r
+                                               XmlSchema schema = new XmlSchema ();\r
+                                               schema.nameTable = rdr.NameTable;\r
+\r
+                                               schema.LineNumber = reader.LineNumber;\r
+                                               schema.LinePosition = reader.LinePosition;\r
+                                               schema.SourceUri = reader.BaseURI;\r
+\r
+                                               ReadAttributes(schema, reader, validationEventHandler);\r
+                                               //IsEmptyElement does not behave properly if reader is\r
+                                               //positioned at an attribute.\r
+                                               reader.MoveToElement();\r
+                                               if(!reader.IsEmptyElement)\r
+                                               {\r
+                                                       ReadContent(schema, reader, validationEventHandler);\r
+                                               }\r
+                                               else\r
+                                                       rdr.Skip ();\r
+\r
+                                               if (rdr.NodeType == XmlNodeType.EndElement)\r
+                                                       rdr.Read ();\r
+                                               return schema;\r
+                                       }\r
+                                       else\r
+                                               //Schema can't be generated. Throw an exception\r
+                                               error (validationEventHandler, "The root element must be schema", null);\r
+                                       break;\r
+                                default:\r
+                                       error(validationEventHandler, "This should never happen. XmlSchema.Read 1 ",null);\r
+                                       break;\r
                                 }\r
                         } while(reader.Depth > startDepth && reader.ReadNextElement());\r
-                        throw new XmlSchemaException("The top level schema must have namespace "+XmlSchema.Namespace, null);\r
+\r
+                       // This is thrown regardless of ValidationEventHandler existence.\r
+                       throw new XmlSchemaException ("The top level schema must have namespace " + XmlSchema.Namespace, null);\r
                 }\r
 \r
                private static void ReadAttributes(XmlSchema schema, XmlSchemaReader reader, ValidationEventHandler h)\r
index 62b2925a68e028fbf40476b431a5bb974b2569a0..96e85839e70985bbd5e63d4badd794084be42bc4 100755 (executable)
@@ -53,7 +53,6 @@ namespace System.Xml.Schema
                /// 1. MaxOccurs must be one. (default is also one)\r
                /// 2. MinOccurs must be zero or one.\r
                /// </remarks>\r
-               [MonoTODO]\r
                internal override int Compile(ValidationEventHandler h, XmlSchema schema)\r
                {\r
                        // If this is already compiled this time, simply skip.\r
@@ -90,7 +89,6 @@ namespace System.Xml.Schema
                        return errorCount;\r
                }\r
 \r
-               [MonoTODO]\r
                internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
                {\r
                        if (IsValidated (schema.CompilationId))\r
@@ -141,12 +139,6 @@ namespace System.Xml.Schema
                        return GetMinEffectiveTotalRangeAllAndSequence ();\r
                }\r
 \r
-               internal override void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema)\r
-               {\r
-                       foreach (XmlSchemaElement el in this.Items)\r
-                               el.CheckRecursion (depth, h, schema);\r
-               }\r
-\r
                internal override void ValidateUniqueParticleAttribution (XmlSchemaObjectTable qnames, ArrayList nsNames,\r
                        ValidationEventHandler h, XmlSchema schema)\r
                {\r
index dc8ed48e9d73cbb4d430ee301c7a65a7b0d1f567..b04927f80bdcd0d32d6144dd86f468add5a3eddb 100755 (executable)
@@ -21,7 +21,7 @@ namespace System.Xml.Schema
                private static string xmlname = "choice";\r
                private decimal minEffectiveTotalRange = -1;\r
 \r
-               public XmlSchemaChoice()\r
+               public XmlSchemaChoice ()\r
                {\r
                        items = new XmlSchemaObjectCollection();\r
                }\r
@@ -47,7 +47,6 @@ namespace System.Xml.Schema
                        }\r
                }\r
 \r
-               [MonoTODO]\r
                internal override int Compile(ValidationEventHandler h, XmlSchema schema)\r
                {\r
                        // If this is already compiled this time, simply skip.\r
@@ -74,7 +73,6 @@ namespace System.Xml.Schema
                        return errorCount;\r
                }\r
                \r
-               [MonoTODO]\r
                internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
                {\r
                        if (IsValidated (schema.CompilationId))\r
@@ -135,12 +133,6 @@ namespace System.Xml.Schema
                        return product;\r
                }\r
 \r
-               internal override void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema)\r
-               {\r
-                       foreach (XmlSchemaParticle p in this.Items)\r
-                               p.CheckRecursion (depth, h, schema);\r
-               }\r
-\r
                internal override void ValidateUniqueParticleAttribution (XmlSchemaObjectTable qnames, ArrayList nsNames,\r
                        ValidationEventHandler h, XmlSchema schema)\r
                {\r
index e3984bb18da6776414994e63751ad0defa2ad4ae..f8c5e475ef51735c37776eb420f385c545693c86 100755 (executable)
@@ -18,45 +18,39 @@ namespace System.Xml.Schema
        public sealed class XmlSchemaCollection : ICollection, IEnumerable\r
        {\r
                //private fields\r
-               private Hashtable htable;\r
-               private Hashtable uriTable;\r
-               private XmlNameTable ntable;\r
-               internal Guid CompilationId;\r
+               private XmlSchemaSet schemaSet;\r
 \r
-               public XmlSchemaCollection()\r
+               public XmlSchemaCollection ()\r
                        : this (new NameTable ())\r
                {\r
                }\r
 \r
-               public XmlSchemaCollection(XmlNameTable nametable)\r
+               public XmlSchemaCollection (XmlNameTable nameTable)\r
+                       : this (new XmlSchemaSet (nameTable))\r
                {\r
-                       htable = new Hashtable();\r
-                       uriTable = new Hashtable ();\r
-                       ntable = nametable;\r
-                       CompilationId = Guid.NewGuid ();\r
+                       this.schemaSet.SchemaCollection = this;\r
+               }\r
+\r
+               internal XmlSchemaCollection (XmlSchemaSet schemaSet)\r
+               {\r
+                       this.schemaSet = schemaSet;\r
                }\r
 \r
                //properties\r
-               public int Count \r
-               { \r
-                       get\r
-                       { \r
-                               return this.htable.Count; \r
-                       }\r
-               }\r
-               public XmlNameTable NameTable \r
-               { \r
-                       get\r
-                       {\r
-                               return this.ntable;\r
-                       }\r
-               }\r
-               public XmlSchema this[ string ns ] \r
-               { \r
-                       get\r
-                       {\r
-                               return (XmlSchema) this.htable[GetSafeNs(ns)];\r
-                       }\r
+               internal XmlSchemaSet SchemaSet {\r
+                       get { return schemaSet; }\r
+               }\r
+\r
+               public int Count {\r
+                       get { return schemaSet.Count; }\r
+               }\r
+\r
+               public XmlNameTable NameTable { \r
+                       get { return schemaSet.NameTable; }\r
+               }\r
+\r
+               public XmlSchema this [ string ns ] { \r
+                       get { return schemaSet.Get (ns); }\r
                }\r
 \r
                // Events\r
@@ -65,138 +59,117 @@ namespace System.Xml.Schema
                // Methods\r
                public XmlSchema Add (string ns, XmlReader reader)\r
                {\r
-                       if (reader == null)\r
-                               throw new ArgumentNullException ("reader");\r
+                       return Add (ns, reader, new XmlUrlResolver ());\r
+               }\r
 \r
+#if NET_1_0\r
+               internal XmlSchema Add (string ns, XmlReader reader, XmlResolver resolver)\r
+#else\r
+               public XmlSchema Add (string ns, XmlReader reader, XmlResolver resolver)\r
+#endif\r
+               {\r
                        XmlSchema schema = XmlSchema.Read (reader, ValidationEventHandler);\r
-                       return Add (schema);\r
+                       schema.Compile (ValidationEventHandler, this, resolver);\r
+                       return schemaSet.Add (schema);\r
                }\r
 \r
-               public XmlSchema Add(string ns, string uri)\r
+               public XmlSchema Add (string ns, string uri)\r
                {\r
-                       return Add (ns, new XmlTextReader (uri));\r
+                       return schemaSet.Add (ns, uri);\r
                }\r
 \r
-               public XmlSchema Add(XmlSchema schema)\r
+               public XmlSchema Add (XmlSchema schema)\r
+               {\r
+                       return Add (schema, new XmlUrlResolver ());\r
+               }\r
+\r
+               public XmlSchema Add (XmlSchema schema, XmlResolver resolver)\r
                {\r
                        if (schema == null)\r
                                throw new ArgumentNullException ("schema");\r
 \r
+                       // XmlSchemaCollection.Add() compiles, while XmlSchemaSet.Add() does not\r
                        if (!schema.IsCompiled)\r
-                               schema.Compile (null, this);\r
-                       /*\r
-                       // This is requried to complete maybe missing sub components.\r
-                       foreach (XmlSchema existing in htable.Values)\r
-                               if (existing.CompilationId != this.CompilationId)\r
-                                       existing.Compile (null, this);\r
-                       */\r
+                               schema.Compile (ValidationEventHandler, this, resolver);\r
 \r
-                       htable [GetSafeNs(schema.TargetNamespace)] = schema;\r
-                       return schema;\r
+                       return schemaSet.Add (schema);\r
                }\r
 \r
-               public void Add(XmlSchemaCollection schema)\r
+               public void Add (XmlSchemaCollection schema)\r
                {\r
                        if (schema == null)\r
                                throw new ArgumentNullException ("schema");\r
 \r
                        foreach (XmlSchema s in schema)\r
-                               Add (s);\r
+                               schemaSet.Add (s);\r
                }\r
 \r
-               string GetSafeNs (string ns)\r
+               public bool Contains (string ns)\r
                {\r
-                       return ns == null ? "" : ns;\r
+                       return schemaSet.Contains (ns);\r
                }\r
 \r
-               public bool Contains(string ns)\r
-               {\r
-                       return this.htable.Contains(GetSafeNs(ns));\r
-               }\r
-               public bool Contains(XmlSchema schema)\r
+               public bool Contains (XmlSchema schema)\r
                {\r
-                       return this.htable.Contains(GetSafeNs(schema.TargetNamespace)); \r
+                       return schemaSet.Contains (schema);\r
                }\r
-               public void CopyTo(XmlSchema[] array, int index)\r
+\r
+               public void CopyTo (XmlSchema[] array, int index)\r
                {\r
-                       ((ICollection) this).CopyTo (array, index);\r
+                       schemaSet.CopyTo (array, index);\r
                }\r
 \r
-               public XmlSchemaCollectionEnumerator GetEnumerator()\r
+               public XmlSchemaCollectionEnumerator GetEnumerator ()\r
                {\r
-                       return new XmlSchemaCollectionEnumerator(this);\r
+                       return new XmlSchemaCollectionEnumerator (this);\r
                }\r
                \r
                // interface Methods\r
-               void ICollection.CopyTo(Array array, int index)\r
+               void ICollection.CopyTo (Array array, int index)\r
                {\r
-                       htable.Values.CopyTo (array, index);\r
+                       schemaSet.CopyTo (array, index);\r
                }\r
+\r
+               [MonoTODO]\r
                bool ICollection.IsSynchronized\r
                {\r
-                       get { return false; }\r
+                       get { throw new NotImplementedException (); }\r
                }\r
-               IEnumerator IEnumerable.GetEnumerator()\r
+\r
+               IEnumerator IEnumerable.GetEnumerator ()\r
                {\r
-                       return this.htable.GetEnumerator();\r
+                       return schemaSet.GetEnumerator ();\r
                }\r
+\r
+               [MonoTODO]\r
                Object ICollection.SyncRoot\r
                {\r
-                       get { return this; }\r
+                       get { throw new NotImplementedException (); }\r
                }\r
 \r
                // Internal Methods\r
                internal XmlSchemaAttribute FindAttribute (XmlQualifiedName qname)\r
                {\r
-                       XmlSchemaAttribute found = null;\r
-                       XmlSchema target = this [qname.Namespace];\r
-                       if (target != null)\r
-                               found = target.Attributes [qname] as XmlSchemaAttribute;\r
-                       if (found != null)\r
-                               return found;\r
-                       foreach (XmlSchema schema in htable.Values) {\r
-                               found = schema.Attributes [qname] as XmlSchemaAttribute;\r
-                               if (found != null)\r
-                                       return found;\r
-                       }\r
-                       return null;\r
+                       return (XmlSchemaAttribute) schemaSet.GlobalAttributes [qname];\r
                }\r
 \r
                internal XmlSchemaElement FindElement (XmlQualifiedName qname)\r
                {\r
-                       XmlSchemaElement found = null;\r
-                       XmlSchema target = this [qname.Namespace];\r
-                       if (target != null)\r
-                               found = target.Elements [qname] as XmlSchemaElement;\r
-                       if (found != null)\r
-                               return found;\r
-                       foreach (XmlSchema schema in htable.Values) {\r
-                               found = schema.Elements [qname] as XmlSchemaElement;\r
-                               if (found != null)\r
-                                       return found;\r
-                       }\r
-                       return null;\r
+                       return (XmlSchemaElement) schemaSet.GlobalElements [qname];\r
                }\r
 \r
                internal object FindSchemaType (XmlQualifiedName qname)\r
                {\r
-                       if (qname == XmlSchemaComplexType.AnyTypeName)\r
-                               return XmlSchemaComplexType.AnyType;
-                       else if (qname.Namespace == XmlSchema.Namespace)\r
-                               return XmlSchemaDatatype.FromName (qname);\r
-\r
-                       XmlSchemaType found = null;\r
-                       XmlSchema target = this [qname.Namespace];\r
-                       if (target != null)\r
-                               found = target.SchemaTypes [qname] as XmlSchemaType;\r
-                       if (found != null)\r
-                               return found;\r
-                       foreach (XmlSchema schema in htable.Values) {\r
-                               found = schema.SchemaTypes [qname] as XmlSchemaType;\r
-                               if (found != null)\r
-                                       return found;\r
-                       }\r
-                       return null;\r
+                       return schemaSet.GlobalTypes [qname];\r
                }\r
+\r
+               internal void OnValidationError (object o, ValidationEventArgs e)
+               {
+                       if (ValidationEventHandler != null)
+                               ValidationEventHandler (o, e);
+                       else
+                               throw e.Exception;
+               }
+
        }\r
 }\r
index 3b1a300b88cbe20e0b865cc7080f7c949835eabe..dc63bb1bc4d819dd634463dd999141f758edad61 100755 (executable)
@@ -55,11 +55,12 @@ namespace System.Xml.Schema
 \r
                internal static readonly XmlQualifiedName AnyTypeName = new XmlQualifiedName ("anyType", XmlSchema.Namespace);\r
 \r
-               public XmlSchemaComplexType()\r
+               public XmlSchemaComplexType ()\r
                {\r
                        attributes = new XmlSchemaObjectCollection();\r
                        block = XmlSchemaDerivationMethod.None;\r
                        attributeUses = new XmlSchemaObjectTable();\r
+                       contentTypeParticle = XmlSchemaParticle.Empty;\r
                }\r
 \r
                #region Attributes\r
@@ -405,7 +406,7 @@ namespace System.Xml.Schema
                                ValidateContentModel (h, schema);\r
                        else {\r
                                if (particle != null)\r
-                                       ValidateParticle (h, schema);\r
+                                       ValidateImmediateParticle (h, schema);\r
                                // contentModel never has them.\r
                                ValidateImmediateAttributes (h, schema);\r
                        }\r
@@ -446,7 +447,7 @@ namespace System.Xml.Schema
                        return errorCount;\r
                }\r
 \r
-               private void ValidateParticle (ValidationEventHandler h, XmlSchema schema)\r
+               private void ValidateImmediateParticle (ValidationEventHandler h, XmlSchema schema)\r
                {\r
                        // {content type} as a particle.\r
                        errorCount += particle.Validate (h, schema);\r
@@ -791,7 +792,7 @@ namespace System.Xml.Schema
                        // 1.4.2.2.1\r
                        if (baseComplexType.ContentType != XmlSchemaContentType.Empty) {\r
                                // 1.4.2.2.2.1\r
-                               if (this.GetContentType () != baseComplexType.ContentType)\r
+                               if (this.GetContentType () != baseComplexType.GetContentType ())\r
                                        error (h, "Base complex type has different content type " + baseComplexType.ContentType + ".");\r
                                // 1.4.2.2.2.2 => 3.9.6 Particle Valid (Extension)\r
                                else if (this.contentTypeParticle == null ||\r
index 25d82000e857010c48ecc2269ad3a899595d3bfd..fe8041e2c46c6773b76376acf62131b8245a9e99 100755 (executable)
@@ -235,25 +235,30 @@ namespace System.Xml.Schema
 \r
                #endregion\r
 \r
-               /*\r
+               private XmlSchemaParticle substChoice;\r
+\r
+//             /*\r
                // FIXME: using this causes stack overflow...\r
-               internal override XmlSchemaParticle ActualParticle {\r
+               internal XmlSchemaParticle SubstitutingChoice {\r
                        get {\r
-                               if (this.SubstitutingElements != null && this.SubstitutingElements.Count > 0) {\r
+                               if (substChoice != null)\r
+                                       return substChoice;\r
+                               else if (this.SubstitutingElements != null && this.SubstitutingElements.Count > 0) {\r
                                        XmlSchemaChoice choice = new XmlSchemaChoice ();\r
+                                       substChoice = choice;\r
                                        choice.Compile (null, schema); // compute Validated Min/Max Occurs.\r
                                        choice.CompiledItems.Add (this);\r
                                        for (int i = 0; i < SubstitutingElements.Count; i++) {\r
                                                XmlSchemaElement se = SubstitutingElements [i] as XmlSchemaElement;\r
                                                choice.CompiledItems.Add (se);\r
                                        }\r
-                                       return choice;\r
                                }\r
                                else\r
-                                       return this;\r
+                                       substChoice= this;\r
+                               return substChoice;\r
                        }\r
                }\r
-               */\r
+//             */\r
 \r
                /// <remarks>\r
                /// a) If Element has parent as schema:\r
@@ -718,9 +723,9 @@ namespace System.Xml.Schema
                internal override void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema)\r
                {\r
                        XmlSchemaComplexType ct = this.ElementType as XmlSchemaComplexType;\r
-                       if (ct == null || ct.ContentTypeParticle == null)\r
+                       if (ct == null || ct.Particle == null)\r
                                return;\r
-                       ct.ContentTypeParticle.CheckRecursion (depth + 1, h, schema);\r
+                       ct.Particle.CheckRecursion (depth + 1, h, schema);\r
                }\r
 \r
                internal override void ValidateUniqueParticleAttribution (XmlSchemaObjectTable qnames, ArrayList nsNames,\r
index 42b51978420bc49a91bbee8968c3e4b9fd3367bb..983f7a4b38b66f97e173db8ae6638656ec92e7c2 100755 (executable)
@@ -1,18 +1,20 @@
-// Author: Dwivedi, Ajay kumar\r
-//            Adwiv@Yahoo.com\r
+//\r
+// XmlSchemaGroupBase.cs\r
+//\r
+// Authors:\r
+//     Dwivedi, Ajay kumar Adwiv@Yahoo.com\r
+//     Atsushi Enomoto atsushi@ximian.com\r
+//\r
 using System;\r
 using System.Xml.Serialization;\r
 \r
 namespace System.Xml.Schema\r
 {\r
-       /// <summary>\r
-       /// Summary description for XmlSchemaGroupBase.\r
-       /// </summary>\r
        public abstract class XmlSchemaGroupBase : XmlSchemaParticle\r
        {\r
                private XmlSchemaObjectCollection compiledItems;\r
 \r
-               protected XmlSchemaGroupBase()\r
+               protected XmlSchemaGroupBase ()\r
                {\r
                        compiledItems = new XmlSchemaObjectCollection ();\r
                }\r
@@ -47,6 +49,12 @@ namespace System.Xml.Schema
                        return true;\r
                }\r
 \r
+               internal override void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema)\r
+               {\r
+                       foreach (XmlSchemaParticle p in this.Items)\r
+                               p.CheckRecursion (depth, h, schema);\r
+               }\r
+\r
                internal void ValidateNSRecurseCheckCardinality (XmlSchemaAny any,\r
                        ValidationEventHandler h, XmlSchema schema)\r
                {\r
@@ -60,32 +68,45 @@ namespace System.Xml.Schema
                {\r
                        int index = 0;\r
                        for (int i = 0; i < baseGroup.CompiledItems.Count; i++) {\r
-                               XmlSchemaParticle pb = baseGroup.CompiledItems [i] as XmlSchemaParticle;\r
-                               if (pb.ActualParticle == XmlSchemaParticle.Empty)\r
+                               XmlSchemaParticle pb = ((XmlSchemaParticle) baseGroup.CompiledItems [i]).ActualParticle;\r
+                               if (pb == XmlSchemaParticle.Empty)\r
                                        continue;\r
                                XmlSchemaParticle pd = null;\r
                                while (this.CompiledItems.Count > index) {\r
-                                       pd = this.CompiledItems [index] as XmlSchemaParticle;\r
+                                       pd = ((XmlSchemaParticle) this.CompiledItems [index]).ActualParticle;\r
                                        index++;\r
-                                       if (pd.ActualParticle != XmlSchemaParticle.Empty)\r
+                                       if (pd != XmlSchemaParticle.Empty)\r
                                                break;\r
                                }\r
-                               if (pd != null) {\r
-                                       try {\r
-                                               pd.ActualParticle.ValidateDerivationByRestriction (pb.ActualParticle, h, schema);\r
-                                       } catch (XmlSchemaException ex) {\r
-                                               if (!pb.ValidateIsEmptiable ())\r
-                                                       error (h, "Invalid particle derivation by restriction was found. Invalid sub-particle derivation was found.", ex);\r
-                                               else\r
-                                                       index--; // try the same derived particle and next base particle.\r
-                                       }\r
-                               } else if (!pb.ValidateIsEmptiable ()) {\r
-                                       error (h, "Invalid particle derivation by restriction was found. Base schema particle has non-emptiable sub particle that is not mapped to the derived particle.");\r
-                                       return;\r
-                               }\r
+                               ValidateParticleSection (ref index, pd, pb, h, schema);\r
                        }\r
-                       if (index != this.CompiledItems.Count)\r
+                       if (this.compiledItems.Count > 0 && index != this.CompiledItems.Count)\r
                                error (h, "Invalid particle derivation by restriction was found. Extraneous derived particle was found.");\r
                }\r
+\r
+               private void ValidateParticleSection (ref int index, XmlSchemaParticle pd, XmlSchemaParticle pb, ValidationEventHandler h, XmlSchema schema)\r
+               {\r
+                       if (pd == pb) // they are same particle\r
+                               return;\r
+\r
+                       if (pd != null) {\r
+                               try {\r
+                                       XmlSchemaElement el = pd as XmlSchemaElement;\r
+                                       XmlSchemaParticle pdx = pd;\r
+                                       if (el != null && el.SubstitutingElements.Count > 0)\r
+                                               pdx = el.SubstitutingChoice;\r
+\r
+                                       pdx.ValidateDerivationByRestriction (pb, h, schema);\r
+                               } catch (XmlSchemaException ex) {\r
+                                       if (!pb.ValidateIsEmptiable ())\r
+                                               error (h, "Invalid particle derivation by restriction was found. Invalid sub-particle derivation was found.", ex);\r
+                                       else\r
+                                               index--; // try the same derived particle and next base particle.\r
+                               }\r
+                       } else if (!pb.ValidateIsEmptiable ()) {\r
+                               error (h, "Invalid particle derivation by restriction was found. Base schema particle has non-emptiable sub particle that is not mapped to the derived particle.");\r
+                               return;\r
+                       }\r
+               }\r
        }\r
 }\r
index 540b6e90f1f9c8ac0eb14f99d4ce408e958b4894..057e15bf2c35ee4244904eb0e683c4d919c29a96 100755 (executable)
@@ -47,8 +47,7 @@ namespace System.Xml.Schema
                {\r
                        if (table.ContainsKey (name))\r
                                throw new XmlSchemaException (\r
-                                       "Schema object for the name " + name + " already exists in this table.",\r
-                                       0, 0, value, null, null);\r
+                                       "Schema object for the name " + name + " already exists in this table.", value, null);\r
                        table [name] = value;\r
                }\r
 \r
index 4cf704ef175dc062b0f20bab9c6cbef8661df3cf..85558b1eae7ae97d66619c25228017b6c273cf72 100755 (executable)
@@ -49,7 +49,6 @@ namespace System.Xml.Schema
                }\r
 \r
 \r
-               [MonoTODO]\r
                internal override int Compile(ValidationEventHandler h, XmlSchema schema)\r
                {\r
                        // If this is already compiled this time, simply skip.\r
@@ -76,7 +75,6 @@ namespace System.Xml.Schema
                        return errorCount;\r
                }\r
                \r
-               [MonoTODO]\r
                internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
                {\r
                        if (IsValidated (schema.CompilationId))\r
@@ -95,6 +93,9 @@ namespace System.Xml.Schema
                internal override void ValidateDerivationByRestriction (XmlSchemaParticle baseParticle,\r
                        ValidationEventHandler h, XmlSchema schema)\r
                {\r
+                       if (this == baseParticle) // quick check\r
+                               return;\r
+\r
                        XmlSchemaElement el = baseParticle as XmlSchemaElement;\r
                        if (el != null) {\r
                                // Forbidden\r
@@ -158,12 +159,6 @@ namespace System.Xml.Schema
                        return GetMinEffectiveTotalRangeAllAndSequence ();\r
                }\r
 \r
-               internal override void CheckRecursion (int depth, ValidationEventHandler h, XmlSchema schema)\r
-               {\r
-                       foreach (XmlSchemaParticle p in this.Items)\r
-                               p.CheckRecursion (depth, h, schema);\r
-               }\r
-\r
                internal override void ValidateUniqueParticleAttribution (XmlSchemaObjectTable qnames, ArrayList nsNames,\r
                        ValidationEventHandler h, XmlSchema schema)\r
                {\r
index 352149082cb74ff20762fffbe3c60f32b3fb62b5..67ea7d1c2a1e2d85150d6f0134bc2b45003f59fe 100644 (file)
@@ -5,9 +5,8 @@
 //     Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
 //
 // (C)2003 Atsushi Enomoto
+// (C)2004 Novell Inc.
 //
-#if NET_1_2
-
 using System;
 using System.Collections;
 using System.Collections.Specialized;
@@ -19,55 +18,108 @@ using System.Xml.XPath;
 
 namespace System.Xml.Schema
 {
+#if NET_1_2
        public class XmlSchemaSet
+#else
+       internal class XmlSchemaSet
+#endif
        {
+               XmlNameTable nameTable;
+               XmlResolver xmlResolver;
+
+               Hashtable schemas;
+               XmlSchemaObjectTable attributes;
+               XmlSchemaObjectTable elements;
+               XmlSchemaObjectTable types;
+               XmlSchemaCollection col;
+
+               bool isCompiled;
+
+               internal Guid CompilationId;\r
+
+               public XmlSchemaSet () : this (new NameTable ())
+               {
+               }
+
+               public XmlSchemaSet (XmlNameTable nameTable)
+               {
+                       this.nameTable = nameTable;
+                       schemas = new Hashtable ();
+                       attributes = new XmlSchemaObjectTable ();
+                       elements = new XmlSchemaObjectTable ();
+                       types = new XmlSchemaObjectTable ();
+                       CompilationId = Guid.NewGuid ();
+               }
+
+               public event ValidationEventHandler ValidationEventHandler;
+
                public int Count {
-                       get { throw new NotImplementedException (); }
+                       get { return schemas.Count; }
                }
 
                public XmlSchemaObjectTable GlobalAttributes {
-                       get { throw new NotImplementedException (); }
+                       get { return attributes; }
                }
 
                public XmlSchemaObjectTable GlobalElements {
-                       get { throw new NotImplementedException (); }
+                       get { return elements; }
                }
 
                public XmlSchemaObjectTable GlobalTypes { 
-                       get { throw new NotImplementedException (); }
+                       get { return types; }
                }
 
                public bool IsCompiled { 
-                       get { throw new NotImplementedException (); }
+                       get { return isCompiled; }
                }
 
                public XmlNameTable NameTable { 
-                       get { throw new NotImplementedException (); }
+                       get { return nameTable; }
                }
 
-               public XmlResolver XmlResolver { 
-                       set { throw new NotImplementedException (); }
+               // This is mainly used for event delegating
+               internal XmlSchemaCollection SchemaCollection {
+                       get { return col; }
+                       set { col = value; }
                }
 
+               public XmlResolver XmlResolver { 
+                       set { xmlResolver = value; }
+               }
 
                public XmlSchema Add (string targetNamespace, string url)
                {
-                       throw new NotImplementedException ();
+                       XmlTextReader r = null;
+                       try {
+                               r = new XmlTextReader (url);
+                               return Add (targetNamespace, r);
+                       } finally {
+                               if (r != null)
+                                       r.Close ();
+                       }
                }
 
+               [MonoTODO ("Check how targetNamespace is used")]
                public XmlSchema Add (string targetNamespace, XmlReader reader)
                {
-                       throw new NotImplementedException ();
+                       return Add (XmlSchema.Read (reader, null));
                }
 
+               [MonoTODO ("Check the exact behavior when namespaces are in conflict")]
                public void Add (XmlSchemaSet schemaSet)
                {
-                       throw new NotImplementedException ();
+                       foreach (XmlSchema schema in schemaSet.schemas)
+                               schemas.Add (schema.TargetNamespace, schema);
                }
 
+               [MonoTODO ("Check the exact behavior when namespaces are in conflict")]
                public XmlSchema Add (XmlSchema schema)
                {
-                       throw new NotImplementedException ();
+                       XmlSchema existing = schemas [GetSafeNs (schema.TargetNamespace)] as XmlSchema;
+                       if (existing != null)
+                               return existing;
+                       schemas.Add (GetSafeNs (schema.TargetNamespace), schema);
+                       return schema;
                }
 
                public void Compile ()
@@ -77,44 +129,65 @@ namespace System.Xml.Schema
 
                public bool Contains (string targetNamespace)
                {
-                       throw new NotImplementedException ();
+                       return schemas.ContainsKey (targetNamespace);
                }
 
                public bool Contains (XmlSchema targetNamespace)
                {
-                       throw new NotImplementedException ();
+                       return schemas.Contains (targetNamespace);
                }
 
                public void CopyTo (XmlSchema[] array, int index)
                {
-                       throw new NotImplementedException ();
+                       schemas.CopyTo (array, index);
                }
 
-               public XmlSchema Remove (XmlSchema schema)
+               internal void CopyTo (Array array, int index)
                {
-                       throw new NotImplementedException ();
+                       schemas.CopyTo (array, index);
                }
 
-               public ArrayList Schemas ()
+               internal XmlSchema Get (string ns)
                {
-                       throw new NotImplementedException ();
+                       return (XmlSchema) schemas [GetSafeNs (ns)];
+               }
+
+               internal IEnumerator GetEnumerator()\r
+               {\r
+                       return schemas.GetEnumerator();\r
+               }\r
+\r
+               string GetSafeNs (string ns)\r
+               {\r
+                       return ns == null ? "" : ns;\r
+               }\r
+\r
+               internal void OnValidationError (object o, ValidationEventArgs e)
+               {
+                       if (col != null)
+                               col.OnValidationError (o, e);
+                       if (ValidationEventHandler != null)
+                               ValidationEventHandler (o, e);
+                       else
+                               throw e.Exception;
                }
 
-               public ArrayList Schemas (string targetNamespace)
+               [MonoTODO ("Check exact behavior")]
+               public XmlSchema Remove (XmlSchema schema)
                {
-                       throw new NotImplementedException ();
+                       schemas.Remove (schema);
+                       return schema;
                }
 
-               public  XmlSchemaSet ()  
+               public ArrayList Schemas ()
                {
-                       throw new NotImplementedException ();
+                       return new ArrayList (schemas);
                }
 
-               public  XmlSchemaSet (XmlNameTable nameTable)
+               [MonoTODO]
+               public ArrayList Schemas (string targetNamespace)
                {
                        throw new NotImplementedException ();
                }
        }
 }
-
-#endif