* 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
</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
private XmlSchemaCollection schemas;\r
\r
private XmlNameTable nameTable;\r
- private XmlResolver resolver;\r
\r
internal bool missedSubComponents;\r
\r
/// 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
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
{\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
\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
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
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
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
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
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
\r
#endregion\r
\r
- [MonoTODO]\r
private void Validate(ValidationEventHandler handler)\r
{\r
ValidationId = CompilationId;\r
\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
{\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
/// 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
return errorCount;\r
}\r
\r
- [MonoTODO]\r
internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
{\r
if (IsValidated (schema.CompilationId))\r
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
private static string xmlname = "choice";\r
private decimal minEffectiveTotalRange = -1;\r
\r
- public XmlSchemaChoice()\r
+ public XmlSchemaChoice ()\r
{\r
items = new XmlSchemaObjectCollection();\r
}\r
}\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
return errorCount;\r
}\r
\r
- [MonoTODO]\r
internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
{\r
if (IsValidated (schema.CompilationId))\r
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
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
// 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
\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
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
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
// 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
\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
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
-// 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
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
{\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
{\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
}\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
return errorCount;\r
}\r
\r
- [MonoTODO]\r
internal override int Validate(ValidationEventHandler h, XmlSchema schema)\r
{\r
if (IsValidated (schema.CompilationId))\r
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
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
// 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;
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 ()
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