2 // Mono.Xml.Schema.XsdWildcard.cs
\r
5 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
\r
7 // (C)2003 Atsushi Enomoto
\r
10 // This class represents common part of xs:any and xs:anyAttribute
\r
15 // Permission is hereby granted, free of charge, to any person obtaining
\r
16 // a copy of this software and associated documentation files (the
\r
17 // "Software"), to deal in the Software without restriction, including
\r
18 // without limitation the rights to use, copy, modify, merge, publish,
\r
19 // distribute, sublicense, and/or sell copies of the Software, and to
\r
20 // permit persons to whom the Software is furnished to do so, subject to
\r
21 // the following conditions:
\r
23 // The above copyright notice and this permission notice shall be
\r
24 // included in all copies or substantial portions of the Software.
\r
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
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 SkipCompile;
\r
53 public bool HasValueAny;
\r
54 public bool HasValueLocal;
\r
55 public bool HasValueOther;
\r
56 public bool HasValueTargetNamespace;
\r
57 public StringCollection ResolvedNamespaces;
\r
61 HasValueAny = false;
\r
62 HasValueLocal = false;
\r
63 HasValueOther = false;
\r
64 HasValueTargetNamespace = false;
\r
65 ResolvedNamespaces = new StringCollection ();
\r
68 public void Compile (string nss,
\r
69 ValidationEventHandler h, XmlSchema schema)
\r
72 return; // used by XmlSchemaAny.AnyTypeContent.
\r
76 string actualNamespace = nss == null ? "##any" : nss;
\r
77 string[] nslist = XmlSchemaUtil.SplitList(actualNamespace);
\r
78 for (int i = 0; i < nslist.Length; i++) {
\r
79 string ns = nslist [i];
\r
83 xsobj.error (h, "Multiple specification of ##any was found.");
\r
89 xsobj.error (h, "Multiple specification of ##other was found.");
\r
91 HasValueOther = true;
\r
93 case "##targetNamespace":
\r
94 if (HasValueTargetNamespace)
\r
95 xsobj.error (h, "Multiple specification of ##targetNamespace was found.");
\r
97 HasValueTargetNamespace = true;
\r
101 xsobj.error (h, "Multiple specification of ##local was found.");
\r
103 HasValueLocal = true;
\r
106 if(!XmlSchemaUtil.CheckAnyUri(ns))
\r
107 xsobj.error(h,"the namespace is not a valid anyURI");
\r
108 else if (ResolvedNamespaces.Contains (ns))
\r
109 xsobj.error (h, "Multiple specification of '" + ns + "' was found.");
\r
112 ResolvedNamespaces.Add (ns);
\r
117 if((nscount&1) == 1 && nscount != 1)
\r
118 xsobj.error (h, "##any if present must be the only namespace attribute");
\r
119 if((nscount&2) == 2 && nscount != 2)
\r
120 xsobj.error (h, "##other if present must be the only namespace attribute");
\r
123 // 3.8.6. Attribute Wildcard Intersection
\r
124 // Only try to examine if their intersection is expressible, and
\r
125 // returns true if the result is empty.
\r
126 public bool ExamineAttributeWildcardIntersection (XmlSchemaAny other,
\r
127 ValidationEventHandler h, XmlSchema schema)
\r
130 if (this.HasValueAny == other.HasValueAny &&
\r
131 this.HasValueLocal == other.HasValueLocal &&
\r
132 this.HasValueOther == other.HasValueOther &&
\r
133 this.HasValueTargetNamespace == other.HasValueTargetNamespace &&
\r
134 this.ResolvedProcessing == other.ResolvedProcessContents) {
\r
135 bool notEqual = false;
\r
136 for (int i = 0; i < this.ResolvedNamespaces.Count; i++) {
\r
137 if (!other.ResolvedNamespaces.Contains (this.ResolvedNamespaces [i]))
\r
144 if (this.HasValueAny)
\r
145 return !other.HasValueAny &&
\r
146 !other.HasValueLocal &&
\r
147 !other.HasValueOther &&
\r
148 !other.HasValueTargetNamespace &&
\r
149 other.ResolvedNamespaces.Count == 0;
\r
150 if (other.HasValueAny)
\r
151 return !this.HasValueAny &&
\r
152 !this.HasValueLocal &&
\r
153 !this.HasValueOther &&
\r
154 !this.HasValueTargetNamespace &&
\r
155 this.ResolvedNamespaces.Count == 0;
\r
157 if (this.HasValueOther && other.HasValueOther && this.TargetNamespace != other.TargetNamespace) {
\r
158 // xsobj.error (h, "The Wildcard intersection is not expressible.");
\r
162 if (this.HasValueOther) {
\r
163 if (other.HasValueLocal && this.TargetNamespace != String.Empty)
\r
165 if (other.HasValueTargetNamespace && this.TargetNamespace != other.TargetNamespace)
\r
167 return other.ValidateWildcardAllowsNamespaceName (this.TargetNamespace, h, schema, false);
\r
169 if (other.HasValueOther) {
\r
170 if (this.HasValueLocal && other.TargetNamespace != String.Empty)
\r
172 if (this.HasValueTargetNamespace && other.TargetNamespace != this.TargetNamespace)
\r
174 return this.ValidateWildcardAllowsNamespaceName (other.TargetNamespace, h, schema, false);
\r
177 if (this.ResolvedNamespaces.Count > 0) {
\r
178 for (int i = 0; i < this.ResolvedNamespaces.Count; i++)
\r
179 if (other.ResolvedNamespaces.Contains (this.ResolvedNamespaces [i]))
\r
185 // 3.10.4 Wildcard Allows Namespace Name. (In fact it is almost copy...)
\r
186 public bool ValidateWildcardAllowsNamespaceName (string ns,
\r
187 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
191 if (HasValueOther && ns != TargetNamespace)
\r
193 if (HasValueTargetNamespace && ns == TargetNamespace)
\r
195 if (HasValueLocal && ns == "")
\r
197 for (int i = 0; i < ResolvedNamespaces.Count; i++)
\r
198 if (ns == ResolvedNamespaces [i])
\r
201 xsobj.error (h, "This wildcard does not allow the namespace: " + ns);
\r
205 // 3.10.6 Wildcard Subset
\r
206 // Other = wider. this = restricted subset
\r
207 internal void ValidateWildcardSubset (XsdWildcard other,
\r
208 ValidationEventHandler h, XmlSchema schema)
\r
210 ValidateWildcardSubset (other, h, schema, true);
\r
213 internal bool ValidateWildcardSubset (XsdWildcard other,
\r
214 ValidationEventHandler h, XmlSchema schema, bool raiseError)
\r
217 if (other.HasValueAny)
\r
220 if (HasValueOther && other.HasValueOther) {
\r
222 if (TargetNamespace == other.TargetNamespace ||
\r
223 other.TargetNamespace == null || other.TargetNamespace == "")
\r
227 if (this.HasValueAny) {
\r
229 xsobj.error (h, "Invalid wildcard subset was found.");
\r
233 if (other.HasValueOther) {
\r
235 if ( (this.HasValueTargetNamespace && other.TargetNamespace == this.TargetNamespace) ||
\r
236 (this.HasValueLocal && (other.TargetNamespace == null || other.TargetNamespace.Length == 0)) ) {
\r
238 xsobj.error (h, "Invalid wildcard subset was found.");
\r
241 for (int i = 0; i < ResolvedNamespaces.Count; i++) {
\r
242 if (ResolvedNamespaces [i] == other.TargetNamespace) {
\r
244 xsobj.error (h, "Invalid wildcard subset was found.");
\r
251 if ((this.HasValueLocal && !other.HasValueLocal) ||
\r
252 this.HasValueTargetNamespace && !other.HasValueTargetNamespace) {
\r
254 xsobj.error (h, "Invalid wildcard subset was found.");
\r
256 } else if (this.HasValueOther) {
\r
258 xsobj.error (h, "Invalid wildcard subset was found.");
\r
261 for (int i = 0; i < this.ResolvedNamespaces.Count; i++)
\r
262 if (!other.ResolvedNamespaces.Contains (this.ResolvedNamespaces [i])) {
\r
264 xsobj.error (h, "Invalid wildcard subset was found.");
\r