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
;
37 using System
.Xml
.Schema
;
39 namespace Mono
.Xml
.Schema
41 internal class XsdWildcard
43 public XsdWildcard (XmlSchemaObject 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
)
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
];
70 xsobj
.error (h
, "Multiple specification of ##any was found.");
76 xsobj
.error (h
, "Multiple specification of ##other was found.");
80 case "##targetNamespace":
81 if (HasValueTargetNamespace
)
82 xsobj
.error (h
, "Multiple specification of ##targetNamespace was found.");
84 HasValueTargetNamespace
= true;
88 xsobj
.error (h
, "Multiple specification of ##local was found.");
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.");
99 ResolvedNamespaces
.Add (ns
);
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
)
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
]))
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;
144 if (this.HasValueOther
&& other
.HasValueOther
&& this.TargetNamespace
!= other
.TargetNamespace
) {
145 // xsobj.error (h, "The Wildcard intersection is not expressible.");
149 if (this.HasValueOther
) {
150 if (other
.HasValueLocal
&& this.TargetNamespace
!= String
.Empty
)
152 if (other
.HasValueTargetNamespace
&& this.TargetNamespace
!= other
.TargetNamespace
)
154 return other
.ValidateWildcardAllowsNamespaceName (this.TargetNamespace
, h
, schema
, false);
156 if (other
.HasValueOther
) {
157 if (this.HasValueLocal
&& other
.TargetNamespace
!= String
.Empty
)
159 if (this.HasValueTargetNamespace
&& other
.TargetNamespace
!= this.TargetNamespace
)
161 return this.ValidateWildcardAllowsNamespaceName (other
.TargetNamespace
, h
, schema
, false);
164 if (this.ResolvedNamespaces
.Count
> 0) {
165 for (int i
= 0; i
< this.ResolvedNamespaces
.Count
; i
++)
166 if (other
.ResolvedNamespaces
.Contains (this.ResolvedNamespaces
[i
]))
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
)
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
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
)
204 if (other
.HasValueAny
)
207 if (HasValueOther
&& other
.HasValueOther
) {
209 if (TargetNamespace
== other
.TargetNamespace
||
210 other
.TargetNamespace
== null || other
.TargetNamespace
== "")
214 if (this.HasValueAny
) {
216 xsobj
.error (h
, "Invalid wildcard subset was found.");
220 if (other
.HasValueOther
) {
222 if ( (this.HasValueTargetNamespace
&& other
.TargetNamespace
== this.TargetNamespace
) ||
223 (this.HasValueLocal
&& (other
.TargetNamespace
== null || other
.TargetNamespace
.Length
== 0)) ) {
225 xsobj
.error (h
, "Invalid wildcard subset was found.");
228 for (int i
= 0; i
< ResolvedNamespaces
.Count
; i
++) {
229 if (ResolvedNamespaces
[i
] == other
.TargetNamespace
) {
231 xsobj
.error (h
, "Invalid wildcard subset was found.");
238 if ((this.HasValueLocal
&& !other
.HasValueLocal
) ||
239 this.HasValueTargetNamespace
&& !other
.HasValueTargetNamespace
) {
241 xsobj
.error (h
, "Invalid wildcard subset was found.");
243 } else if (this.HasValueOther
) {
245 xsobj
.error (h
, "Invalid wildcard subset was found.");
248 for (int i
= 0; i
< this.ResolvedNamespaces
.Count
; i
++)
249 if (!other
.ResolvedNamespaces
.Contains (this.ResolvedNamespaces
[i
])) {
251 xsobj
.error (h
, "Invalid wildcard subset was found.");