2003-10-25 Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
[mono.git] / mcs / class / System.XML / System.Xml.Schema / XmlSchemaGroupBase.cs
1 // Author: Dwivedi, Ajay kumar\r
2 //            Adwiv@Yahoo.com\r
3 using System;\r
4 using System.Xml.Serialization;\r
5 \r
6 namespace System.Xml.Schema\r
7 {\r
8         /// <summary>\r
9         /// Summary description for XmlSchemaGroupBase.\r
10         /// </summary>\r
11         public abstract class XmlSchemaGroupBase : XmlSchemaParticle\r
12         {\r
13                 private XmlSchemaObjectCollection compiledItems;\r
14 \r
15                 protected XmlSchemaGroupBase()\r
16                 {\r
17                         compiledItems = new XmlSchemaObjectCollection ();\r
18                 }\r
19 \r
20                 [XmlIgnore]\r
21                 public abstract XmlSchemaObjectCollection Items { get; }\r
22 \r
23                 internal XmlSchemaObjectCollection CompiledItems \r
24                 {\r
25                         get{ return compiledItems; }\r
26                 }\r
27 \r
28                 internal override bool ParticleEquals (XmlSchemaParticle other)\r
29                 {\r
30                         XmlSchemaChoice choice = other as XmlSchemaChoice;\r
31                         if (choice == null)\r
32                                 return false;\r
33                         if (this.ValidatedMaxOccurs != choice.ValidatedMaxOccurs ||\r
34                                 this.ValidatedMinOccurs != choice.ValidatedMinOccurs)\r
35                                 return false;\r
36                         if (this.CompiledItems.Count != choice.CompiledItems.Count)\r
37                                 return false;\r
38                         for (int i = 0; i < CompiledItems.Count; i++) {\r
39                                 XmlSchemaParticle p1 = this.CompiledItems [i] as XmlSchemaParticle;\r
40                                 XmlSchemaParticle p2 = choice.CompiledItems [i] as XmlSchemaParticle;\r
41                                 if (!p1.ParticleEquals (p2))\r
42                                         return false;\r
43                         }\r
44                         return true;\r
45                 }\r
46 \r
47                 internal void ValidateNSRecurseCheckCardinality (XmlSchemaAny any,\r
48                         ValidationEventHandler h, XmlSchema schema)\r
49                 {\r
50                         foreach (XmlSchemaParticle p in Items)\r
51                                 p.ValidateDerivationByRestriction (any, h, schema);\r
52                         ValidateOccurenceRangeOK (any, h, schema);\r
53                 }\r
54 \r
55                 internal void ValidateRecurse (XmlSchemaGroupBase baseGroup,\r
56                         ValidationEventHandler h, XmlSchema schema)\r
57                 {\r
58                         int index = 0;\r
59                         for (int i = 0; i < baseGroup.CompiledItems.Count; i++) {\r
60                                 XmlSchemaParticle pb = baseGroup.CompiledItems [i] as XmlSchemaParticle;\r
61                                 if (pb.ActualParticle == XmlSchemaParticle.Empty)\r
62                                         continue;\r
63                                 XmlSchemaParticle pd = null;\r
64                                 while (this.CompiledItems.Count > index) {\r
65                                         pd = this.CompiledItems [index] as XmlSchemaParticle;\r
66                                         index++;\r
67                                         if (pd.ActualParticle != XmlSchemaParticle.Empty)\r
68                                                 break;\r
69                                 }\r
70                                 if (pd != null) {\r
71                                         try {\r
72                                                 pd.ActualParticle.ValidateDerivationByRestriction (pb.ActualParticle, h, schema);\r
73                                         } catch (XmlSchemaException ex) {\r
74                                                 if (!pb.ValidateIsEmptiable ())\r
75                                                         error (h, "Invalid particle derivation by restriction was found. Invalid sub-particle derivation was found.", ex);\r
76                                                 else\r
77                                                         index--; // try the same derived particle and next base particle.\r
78                                         }\r
79                                 } else if (!pb.ValidateIsEmptiable ()) {\r
80                                         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
81                                         return;\r
82                                 }\r
83                         }\r
84                         if (index != this.CompiledItems.Count)\r
85                                 error (h, "Invalid particle derivation by restriction was found. Extraneous derived particle was found.");\r
86                 }\r
87         }\r
88 }\r