2 // Mono.Xml.Schema.XsdWildcard.cs
5 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
7 // (C)2003 Atsushi Enomoto
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:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
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.
35 using System.Collections.Specialized;
\r
37 using System.Xml.Schema;
\r
39 namespace Mono.Xml.Schema
\r
41 internal class XsdWildcard
\r
43 public XsdWildcard (XmlSchemaObject wildcard)
\r
48 private XmlSchemaObject xsobj;
\r
50 public XmlSchemaContentProcessing ResolvedProcessing;
\r
51 public string TargetNamespace;
\r
52 public bool HasValueAny;
\r
53 public bool HasValueLocal;
\r
54 public bool HasValueOther;
\r
55 public bool HasValueTargetNamespace;
\r
56 public StringCollection ResolvedNamespaces;
\r
58 public void Compile (string nss,
\r
59 ValidationEventHandler h, XmlSchema schema)
\r
62 string actualNamespace = nss == null ? "##any" : nss;
\r
63 string[] nslist = XmlSchemaUtil.SplitList(actualNamespace);
\r
64 ResolvedNamespaces = new StringCollection ();
65 for (int i = 0; i < nslist.Length; i++) {
66 string ns = nslist [i];
70 xsobj.error (h, "Multiple specification of ##any was found.");
76 xsobj.error (h, "Multiple specification of ##other was found.");
80 case "##targetNamespace":
\r
81 if (HasValueTargetNamespace)
82 xsobj.error (h, "Multiple specification of ##targetNamespace was found.");
84 HasValueTargetNamespace = true;
\r
88 xsobj.error (h, "Multiple specification of ##local was found.");
93 if(!XmlSchemaUtil.CheckAnyUri(ns))
\r
94 xsobj.error(h,"the namespace is not a valid anyURI");
\r
95 else if (ResolvedNamespaces.Contains (ns))
96 xsobj.error (h, "Multiple specification of '" + ns + "' was found.");
99 ResolvedNamespaces.Add (ns);
104 if((nscount&1) == 1 && nscount != 1)
\r
105 xsobj.error (h, "##any if present must be the only namespace attribute");
\r
106 if((nscount&2) == 2 && nscount != 2)
\r
107 xsobj.error (h, "##other if present must be the only namespace attribute");
\r
110 // 3.8.6. Attribute Wildcard Intersection
\r
111 // Only try to examine if their intersection is expressible, and
\r
112 // returns true if the result is empty.
\r
113 public bool ExamineAttributeWildcardIntersection (XmlSchemaAny other,
\r
114 ValidationEventHandler h, XmlSchema schema)
\r
117 if (this.HasValueAny == other.HasValueAny &&
\r
118 this.HasValueLocal == other.HasValueLocal &&
\r
119 this.HasValueOther == other.HasValueOther &&
\r
120 this.HasValueTargetNamespace == other.HasValueTargetNamespace &&
\r
121 this.ResolvedProcessing == other.ResolvedProcessContents) {
\r
122 bool notEqual = false;
\r
123 for (int i = 0; i < this.ResolvedNamespaces.Count; i++) {
\r
124 if (!other.ResolvedNamespaces.Contains (this.ResolvedNamespaces [i]))
\r
131 if (this.HasValueAny)
\r
132 return !other.HasValueAny &&
\r
133 !other.HasValueLocal &&
\r
134 !other.HasValueOther &&
\r
135 !other.HasValueTargetNamespace &&
\r
136 other.ResolvedNamespaces.Count == 0;
\r
137 if (other.HasValueAny)
\r
138 return !this.HasValueAny &&
\r
139 !this.HasValueLocal &&
\r
140 !this.HasValueOther &&
\r
141 !this.HasValueTargetNamespace &&
\r
142 this.ResolvedNamespaces.Count == 0;
\r
144 if (this.HasValueOther && other.HasValueOther && this.TargetNamespace != other.TargetNamespace) {
\r
145 // xsobj.error (h, "The Wildcard intersection is not expressible.");
\r
149 if (this.HasValueOther) {
\r
150 if (other.HasValueLocal && this.TargetNamespace != String.Empty)
\r
152 if (other.HasValueTargetNamespace && this.TargetNamespace != other.TargetNamespace)
\r
154 return other.ValidateWildcardAllowsNamespaceName (this.TargetNamespace, h, schema, false);
\r
156 if (other.HasValueOther) {
\r
157 if (this.HasValueLocal && other.TargetNamespace != String.Empty)
\r
159 if (this.HasValueTargetNamespace && other.TargetNamespace != this.TargetNamespace)
\r
161 return this.ValidateWildcardAllowsNamespaceName (other.TargetNamespace, h, schema, false);
\r
164 if (this.ResolvedNamespaces.Count > 0) {
\r
165 for (int i = 0; i < this.ResolvedNamespaces.Count; i++)
\r
166 if (other.ResolvedNamespaces.Contains (this.ResolvedNamespaces [i]))
\r
172 // 3.10.4 Wildcard Allows Namespace Name. (In fact it is almost copy...)
\r
173 public bool ValidateWildcardAllowsNamespaceName (string ns,
\r
174 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
178 if (HasValueOther && ns != TargetNamespace)
180 if (HasValueTargetNamespace && ns == TargetNamespace)
182 if (HasValueLocal && ns == "")
184 for (int i = 0; i < ResolvedNamespaces.Count; i++)
185 if (ns == ResolvedNamespaces [i])
188 xsobj.error (h, "This wildcard does not allow the namespace: " + ns);
192 // 3.10.6 Wildcard Subset
\r
193 // Other = wider. this = restricted subset
\r
194 internal void ValidateWildcardSubset (XsdWildcard other,
\r
195 ValidationEventHandler h, XmlSchema schema)
\r
197 ValidateWildcardSubset (other, h, schema, true);
\r
200 internal bool ValidateWildcardSubset (XsdWildcard other,
\r
201 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
204 if (other.HasValueAny)
\r
207 if (HasValueOther && other.HasValueOther) {
\r
209 if (TargetNamespace == other.TargetNamespace ||
\r
210 other.TargetNamespace == null || other.TargetNamespace == "")
\r
214 if (this.HasValueAny) {
\r
216 xsobj.error (h, "Invalid wildcard subset was found.");
\r
220 if (other.HasValueOther) {
\r
222 if ( (this.HasValueTargetNamespace && other.TargetNamespace == this.TargetNamespace) ||
\r
223 (this.HasValueLocal && (other.TargetNamespace == null || other.TargetNamespace.Length == 0)) ) {
\r
225 xsobj.error (h, "Invalid wildcard subset was found.");
\r
228 for (int i = 0; i < ResolvedNamespaces.Count; i++) {
\r
229 if (ResolvedNamespaces [i] == other.TargetNamespace) {
\r
231 xsobj.error (h, "Invalid wildcard subset was found.");
\r
238 if ((this.HasValueLocal && !other.HasValueLocal) ||
\r
239 this.HasValueTargetNamespace && !other.HasValueTargetNamespace) {
\r
241 xsobj.error (h, "Invalid wildcard subset was found.");
\r
243 } else if (this.HasValueOther) {
\r
245 xsobj.error (h, "Invalid wildcard subset was found.");
\r
248 for (int i = 0; i < this.ResolvedNamespaces.Count; i++)
\r
249 if (!other.ResolvedNamespaces.Contains (this.ResolvedNamespaces [i])) {
\r
251 xsobj.error (h, "Invalid wildcard subset was found.");
\r