X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=mcs%2Fclass%2FSystem.XML%2FSystem.Xml.Schema%2FXmlSchemaGroup.cs;h=d308b3f8668b50f35bc85bd68177808d1ac2ff93;hb=c39145af2464b19374fac41b252e07480ae1a197;hp=46f89fc9ed5c4621b410c8bf303e5fdc74e447b3;hpb=d22745d61411afd798f0b753c669e122c9628854;p=mono.git diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaGroup.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaGroup.cs index 46f89fc9ed5..d308b3f8668 100755 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaGroup.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaGroup.cs @@ -1,6 +1,33 @@ -// Author: Dwivedi, Ajay kumar -// Adwiv@Yahoo.com +// +// System.Xml.Schema.XmlSchemaGroup.cs +// +// Author: +// Dwivedi, Ajay kumar Adwiv@Yahoo.com +// Atsushi Enomoto ginga@kit.hi-ho.ne.jp +// + +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// using System; +using System.Collections; using System.Xml.Serialization; using System.Xml; @@ -14,11 +41,13 @@ namespace System.Xml.Schema private string name; private XmlSchemaGroupBase particle; private XmlQualifiedName qualifiedName; + private bool isCircularDefinition; - private static string xmlname = "group"; + const string xmlname = "group"; public XmlSchemaGroup() { + qualifiedName = XmlQualifiedName.Empty; } [System.Xml.Serialization.XmlAttribute("name")] @@ -28,9 +57,9 @@ namespace System.Xml.Schema set{ name = value; } } - [XmlElement("all",typeof(XmlSchemaAll),Namespace="http://www.w3.org/2001/XMLSchema")] - [XmlElement("choice",typeof(XmlSchemaChoice),Namespace="http://www.w3.org/2001/XMLSchema")] - [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace="http://www.w3.org/2001/XMLSchema")] + [XmlElement("all",typeof(XmlSchemaAll),Namespace=XmlSchema.Namespace)] + [XmlElement("choice",typeof(XmlSchemaChoice),Namespace=XmlSchema.Namespace)] + [XmlElement("sequence",typeof(XmlSchemaSequence),Namespace=XmlSchema.Namespace)] public XmlSchemaGroupBase Particle { get{ return particle; } @@ -38,22 +67,39 @@ namespace System.Xml.Schema } [XmlIgnore] +#if NET_2_0 + public XmlQualifiedName QualifiedName +#else internal XmlQualifiedName QualifiedName +#endif { get{ return qualifiedName;} } + internal bool IsCircularDefinition + { + get { return isCircularDefinition; } + } + // 1. name must be present // 2. MinOccurs & MaxOccurs of the Particle must be absent - [MonoTODO] - internal int Compile(ValidationEventHandler h, XmlSchemaInfo info) + internal override int Compile(ValidationEventHandler h, XmlSchema schema) { + // If this is already compiled this time, simply skip. + if (this.IsComplied (schema.CompilationId)) + return 0; + +#if NET_2_0 + if (Particle != null) + Particle.Parent = this; +#endif + if(Name == null) error(h,"Required attribute name must be present"); else if(!XmlSchemaUtil.CheckNCName(this.name)) error(h,"attribute name must be NCName"); else - qualifiedName = new XmlQualifiedName(Name,info.TargetNamespace); + qualifiedName = new XmlQualifiedName(Name,schema.TargetNamespace); if(Particle == null) { @@ -66,32 +112,40 @@ namespace System.Xml.Schema if(Particle.MinOccursString != null) Particle.error(h,"MinOccurs must not be present when the Particle is a child of Group"); - if(Particle is XmlSchemaChoice) - { - errorCount += ((XmlSchemaChoice)Particle).Compile(h,info); - } - else if(Particle is XmlSchemaSequence) - { - errorCount += ((XmlSchemaSequence)Particle).Compile(h,info); - } - else if(Particle is XmlSchemaAll) - { - errorCount += ((XmlSchemaAll)Particle).Compile(h,info); - } - else - { - error(h,"only all,choice or sequence are allowed"); - } + Particle.Compile (h, schema); } - XmlSchemaUtil.CompileID(Id,this,info.IDCollection,h); + XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h); + this.CompilationId = schema.CompilationId; return errorCount; } - [MonoTODO] - internal int Validate(ValidationEventHandler h) + internal override int Validate(ValidationEventHandler h, XmlSchema schema) { + if (this.IsValidated (schema.ValidationId)) + return errorCount; + + // 3.8.6 Model Group Correct :: 2. Circular group disallowed. + if (Particle != null) { // in case of invalid schema. + Particle.parentIsGroupDefinition = true; + + try { + Particle.CheckRecursion (0, h, schema); + } catch (XmlSchemaException ex) { + error (h, ex.Message, ex); + this.isCircularDefinition = true; + return errorCount; + } + errorCount += Particle.Validate (h,schema); + + Particle.ValidateUniqueParticleAttribution (new XmlSchemaObjectTable (), + new ArrayList (), h, schema); + Particle.ValidateUniqueTypeAttribution ( + new XmlSchemaObjectTable (), h, schema); + } + + this.ValidationId = schema.ValidationId; return errorCount; } @@ -128,17 +182,13 @@ namespace System.Xml.Schema { group.name = reader.Value; } - else if(reader.NamespaceURI == "" || reader.NamespaceURI == XmlSchema.Namespace) + else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace) { error(h,reader.Name + " is not a valid attribute for group",null); } else { - if(reader.Prefix == "xmlns") - group.Namespaces.Add(reader.LocalName, reader.Value); - else if(reader.Name == "xmlns") - group.Namespaces.Add("",reader.Value); - //TODO: Add to Unhandled attributes + XmlSchemaUtil.ReadUnhandledAttribute(reader,group); } }