(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.XML / Mono.Xml.Schema / XsdWildcard.cs
blobab9c3c8c0baef73333cba5a0784b87d3faa22644
1 //
2 // Mono.Xml.Schema.XsdWildcard.cs
3 //
4 // Author:
5 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
6 //
7 // (C)2003 Atsushi Enomoto
8 //
9 //
10 // This class represents common part of xs:any and xs:anyAttribute
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 //
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 //
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System;
35 using System.Collections.Specialized;
36 using System.Xml;
37 using System.Xml.Schema;
39 namespace Mono.Xml.Schema
41 internal class XsdWildcard
43 public XsdWildcard (XmlSchemaObject wildcard)
45 xsobj = wildcard;
48 private XmlSchemaObject xsobj;
50 public XmlSchemaContentProcessing ResolvedProcessing;
51 public string TargetNamespace;
52 public bool HasValueAny;
53 public bool HasValueLocal;
54 public bool HasValueOther;
55 public bool HasValueTargetNamespace;
56 public StringCollection ResolvedNamespaces;
58 public void Compile (string nss,
59 ValidationEventHandler h, XmlSchema schema)
61 int nscount = 0;
62 string actualNamespace = nss == null ? "##any" : nss;
63 string[] nslist = XmlSchemaUtil.SplitList(actualNamespace);
64 ResolvedNamespaces = new StringCollection ();
65 for (int i = 0; i < nslist.Length; i++) {
66 string ns = nslist [i];
67 switch(ns) {
68 case "##any":
69 if (HasValueAny)
70 xsobj.error (h, "Multiple specification of ##any was found.");
71 nscount |= 1;
72 HasValueAny = true;
73 break;
74 case "##other":
75 if (HasValueOther)
76 xsobj.error (h, "Multiple specification of ##other was found.");
77 nscount |= 2;
78 HasValueOther = true;
79 break;
80 case "##targetNamespace":
81 if (HasValueTargetNamespace)
82 xsobj.error (h, "Multiple specification of ##targetNamespace was found.");
83 nscount |= 4;
84 HasValueTargetNamespace = true;
85 break;
86 case "##local":
87 if (HasValueLocal)
88 xsobj.error (h, "Multiple specification of ##local was found.");
89 nscount |= 8;
90 HasValueLocal = true;
91 break;
92 default:
93 if(!XmlSchemaUtil.CheckAnyUri(ns))
94 xsobj.error(h,"the namespace is not a valid anyURI");
95 else if (ResolvedNamespaces.Contains (ns))
96 xsobj.error (h, "Multiple specification of '" + ns + "' was found.");
97 else {
98 nscount |= 16;
99 ResolvedNamespaces.Add (ns);
101 break;
104 if((nscount&1) == 1 && nscount != 1)
105 xsobj.error (h, "##any if present must be the only namespace attribute");
106 if((nscount&2) == 2 && nscount != 2)
107 xsobj.error (h, "##other if present must be the only namespace attribute");
110 // 3.8.6. Attribute Wildcard Intersection
111 // Only try to examine if their intersection is expressible, and
112 // returns true if the result is empty.
113 public bool ExamineAttributeWildcardIntersection (XmlSchemaAny other,
114 ValidationEventHandler h, XmlSchema schema)
116 // 1.
117 if (this.HasValueAny == other.HasValueAny &&
118 this.HasValueLocal == other.HasValueLocal &&
119 this.HasValueOther == other.HasValueOther &&
120 this.HasValueTargetNamespace == other.HasValueTargetNamespace &&
121 this.ResolvedProcessing == other.ResolvedProcessContents) {
122 bool notEqual = false;
123 for (int i = 0; i < this.ResolvedNamespaces.Count; i++) {
124 if (!other.ResolvedNamespaces.Contains (this.ResolvedNamespaces [i]))
125 notEqual = true;
127 if (!notEqual)
128 return false;
130 // 2.
131 if (this.HasValueAny)
132 return !other.HasValueAny &&
133 !other.HasValueLocal &&
134 !other.HasValueOther &&
135 !other.HasValueTargetNamespace &&
136 other.ResolvedNamespaces.Count == 0;
137 if (other.HasValueAny)
138 return !this.HasValueAny &&
139 !this.HasValueLocal &&
140 !this.HasValueOther &&
141 !this.HasValueTargetNamespace &&
142 this.ResolvedNamespaces.Count == 0;
143 // 5.
144 if (this.HasValueOther && other.HasValueOther && this.TargetNamespace != other.TargetNamespace) {
145 // xsobj.error (h, "The Wildcard intersection is not expressible.");
146 return false;
148 // 3.
149 if (this.HasValueOther) {
150 if (other.HasValueLocal && this.TargetNamespace != String.Empty)
151 return false;
152 if (other.HasValueTargetNamespace && this.TargetNamespace != other.TargetNamespace)
153 return false;
154 return other.ValidateWildcardAllowsNamespaceName (this.TargetNamespace, h, schema, false);
156 if (other.HasValueOther) {
157 if (this.HasValueLocal && other.TargetNamespace != String.Empty)
158 return false;
159 if (this.HasValueTargetNamespace && other.TargetNamespace != this.TargetNamespace)
160 return false;
161 return this.ValidateWildcardAllowsNamespaceName (other.TargetNamespace, h, schema, false);
163 // 4.
164 if (this.ResolvedNamespaces.Count > 0) {
165 for (int i = 0; i < this.ResolvedNamespaces.Count; i++)
166 if (other.ResolvedNamespaces.Contains (this.ResolvedNamespaces [i]))
167 return false;
169 return true;
172 // 3.10.4 Wildcard Allows Namespace Name. (In fact it is almost copy...)
173 public bool ValidateWildcardAllowsNamespaceName (string ns,
174 ValidationEventHandler h, XmlSchema schema, bool raiseError)
176 if (HasValueAny)
177 return true;
178 if (HasValueOther && ns != TargetNamespace)
179 return true;
180 if (HasValueTargetNamespace && ns == TargetNamespace)
181 return true;
182 if (HasValueLocal && ns == "")
183 return true;
184 for (int i = 0; i < ResolvedNamespaces.Count; i++)
185 if (ns == ResolvedNamespaces [i])
186 return true;
187 if (raiseError)
188 xsobj.error (h, "This wildcard does not allow the namespace: " + ns);
189 return false;
192 // 3.10.6 Wildcard Subset
193 // Other = wider. this = restricted subset
194 internal void ValidateWildcardSubset (XsdWildcard other,
195 ValidationEventHandler h, XmlSchema schema)
197 ValidateWildcardSubset (other, h, schema, true);
200 internal bool ValidateWildcardSubset (XsdWildcard other,
201 ValidationEventHandler h, XmlSchema schema, bool raiseError)
203 // 1.
204 if (other.HasValueAny)
205 return true;
206 // 2.
207 if (HasValueOther && other.HasValueOther) {
208 // 2.1 and 2.2
209 if (TargetNamespace == other.TargetNamespace ||
210 other.TargetNamespace == null || other.TargetNamespace == "")
211 return true;
213 // 3.1. (not)
214 if (this.HasValueAny) {
215 if (raiseError)
216 xsobj.error (h, "Invalid wildcard subset was found.");
217 return false;
219 // 3.2
220 if (other.HasValueOther) {
221 // 3.2.2
222 if ( (this.HasValueTargetNamespace && other.TargetNamespace == this.TargetNamespace) ||
223 (this.HasValueLocal && (other.TargetNamespace == null || other.TargetNamespace.Length == 0)) ) {
224 if (raiseError)
225 xsobj.error (h, "Invalid wildcard subset was found.");
226 return false;
227 } else {
228 for (int i = 0; i < ResolvedNamespaces.Count; i++) {
229 if (ResolvedNamespaces [i] == other.TargetNamespace) {
230 if (raiseError)
231 xsobj.error (h, "Invalid wildcard subset was found.");
232 return false;
236 } else {
237 // 3.2.1
238 if ((this.HasValueLocal && !other.HasValueLocal) ||
239 this.HasValueTargetNamespace && !other.HasValueTargetNamespace) {
240 if (raiseError)
241 xsobj.error (h, "Invalid wildcard subset was found.");
242 return false;
243 } else if (this.HasValueOther) {
244 if (raiseError)
245 xsobj.error (h, "Invalid wildcard subset was found.");
246 return false;
247 } else {
248 for (int i = 0; i < this.ResolvedNamespaces.Count; i++)
249 if (!other.ResolvedNamespaces.Contains (this.ResolvedNamespaces [i])) {
250 if (raiseError)
251 xsobj.error (h, "Invalid wildcard subset was found.");
252 return false;
256 return true;