2010-04-15 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Web.Services / System.Web.Services.Description / WebServicesInteroperability.cs
blobc25f3349a3e16cb598f1fe5f3aec5b6b90af81c3
1 //
2 // System.Web.Services.Description.WebServicesInteroperability.cs
3 //
4 // Author:
5 // Lluis Sanchez (lluis@novell.com)
6 //
7 // Copyright (C) Novell, Inc., 2004
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #if NET_2_0
33 using System.Collections;
34 using System.Xml.Schema;
36 namespace System.Web.Services.Description
38 public sealed class WebServicesInteroperability
40 private WebServicesInteroperability ()
44 public static bool CheckConformance (WsiProfiles claims, ServiceDescription service, BasicProfileViolationCollection violations)
46 ServiceDescriptionCollection col = new ServiceDescriptionCollection ();
47 col.Add (service);
48 ConformanceCheckContext ctx = new ConformanceCheckContext (col, violations);
49 return Check (claims, ctx, col);
52 public static bool CheckConformance (WsiProfiles claims, ServiceDescriptionCollection services, BasicProfileViolationCollection violations)
54 ConformanceCheckContext ctx = new ConformanceCheckContext (services, violations);
55 return Check (claims, ctx, services);
58 public static bool CheckConformance (WsiProfiles claims, WebReference webReference, BasicProfileViolationCollection violations)
60 ConformanceCheckContext ctx = new ConformanceCheckContext (webReference, violations);
61 return Check (claims, ctx, webReference.Documents.Values);
64 static bool Check (WsiProfiles claims, ConformanceCheckContext ctx, IEnumerable documents)
66 ConformanceChecker[] checkers = GetCheckers (claims);
67 if (checkers == null) return true;
69 foreach (object doc in documents) {
70 if (!(doc is ServiceDescription)) continue;
72 foreach (ConformanceChecker c in checkers)
73 Check (ctx, c, (ServiceDescription)doc);
76 return ctx.Violations.Count == 0;
79 internal static ConformanceChecker[] GetCheckers (WsiProfiles claims)
81 if ((claims & WsiProfiles.BasicProfile1_1) != 0)
82 return new ConformanceChecker[] { BasicProfileChecker.Instance };
83 return null;
86 internal static void Check (ConformanceCheckContext ctx, ConformanceChecker checker, Binding b)
88 checker.Check (ctx, b);
89 CheckExtensions (ctx, checker, b.Extensions);
91 foreach (OperationBinding oper in b.Operations) {
92 CheckExtensions (ctx, checker, oper.Extensions);
94 foreach (MessageBinding mb in oper.Faults) {
95 checker.Check (ctx, mb);
96 CheckExtensions (ctx, checker, mb.Extensions);
99 checker.Check (ctx, oper.Input);
100 CheckExtensions (ctx, checker, oper.Input.Extensions);
102 checker.Check (ctx, oper.Output);
103 CheckExtensions (ctx, checker, oper.Output.Extensions);
107 static void Check (ConformanceCheckContext ctx, ConformanceChecker checker, ServiceDescription sd)
109 ctx.ServiceDescription = sd;
110 ctx.Checker = checker;
112 checker.Check (ctx, sd);
113 CheckExtensions (ctx, checker, sd.Extensions);
115 foreach (Import i in sd.Imports) {
116 checker.Check (ctx, i);
119 foreach (Service s in sd.Services) {
120 checker.Check (ctx, s);
121 foreach (Port p in s.Ports) {
122 checker.Check (ctx, p);
123 CheckExtensions (ctx, checker, p.Extensions);
127 checker.Check (ctx, sd.Bindings);
128 foreach (Binding b in sd.Bindings)
129 Check (ctx, checker, b);
131 foreach (PortType pt in sd.PortTypes)
133 checker.Check (ctx, pt);
135 foreach (Operation oper in pt.Operations) {
136 checker.Check (ctx, oper);
137 foreach (OperationMessage msg in oper.Messages)
138 checker.Check (ctx, msg);
140 foreach (OperationMessage msg in oper.Faults)
141 checker.Check (ctx, msg);
145 foreach (Message msg in sd.Messages)
147 checker.Check (ctx, msg);
148 foreach (MessagePart part in msg.Parts)
149 checker.Check (ctx, part);
152 if (sd.Types != null) {
153 checker.Check (ctx, sd.Types);
154 if (sd.Types.Schemas != null) {
155 foreach (XmlSchema s in sd.Types.Schemas) {
156 ctx.CurrentSchema = s;
157 checker.Check (ctx, s);
158 CheckObjects (ctx, checker, new Hashtable (), s.Items);
164 static void CheckObjects (ConformanceCheckContext ctx, ConformanceChecker checker, Hashtable visitedObjects, XmlSchemaObjectCollection col)
166 foreach (XmlSchemaObject item in col)
167 Check (ctx, checker, visitedObjects, item);
170 static void Check (ConformanceCheckContext ctx, ConformanceChecker checker, Hashtable visitedObjects, XmlSchemaObject value)
172 if (value == null) return;
174 if (visitedObjects.Contains (value)) return;
175 visitedObjects.Add (value, value);
177 if (value is XmlSchemaImport) {
178 XmlSchemaImport so = (XmlSchemaImport) value;
179 checker.Check (ctx, so);
181 else if (value is XmlSchemaAll) {
182 XmlSchemaAll so = (XmlSchemaAll) value;
183 checker.Check (ctx, so);
184 CheckObjects (ctx, checker, visitedObjects, so.Items);
186 else if (value is XmlSchemaAnnotation) {
187 XmlSchemaAnnotation so = (XmlSchemaAnnotation) value;
188 checker.Check (ctx, so);
189 CheckObjects (ctx, checker, visitedObjects, so.Items);
191 else if (value is XmlSchemaAttribute) {
192 XmlSchemaAttribute so = (XmlSchemaAttribute) value;
193 checker.Check (ctx, so);
195 else if (value is XmlSchemaAttributeGroup) {
196 XmlSchemaAttributeGroup so = (XmlSchemaAttributeGroup) value;
197 checker.Check (ctx, so);
198 CheckObjects (ctx, checker, visitedObjects, so.Attributes);
199 Check (ctx, checker, visitedObjects, so.AnyAttribute);
200 Check (ctx, checker, visitedObjects, so.RedefinedAttributeGroup);
202 else if (value is XmlSchemaAttributeGroupRef) {
203 XmlSchemaAttributeGroupRef so = (XmlSchemaAttributeGroupRef) value;
204 checker.Check (ctx, so);
206 else if (value is XmlSchemaChoice) {
207 XmlSchemaChoice so = (XmlSchemaChoice) value;
208 checker.Check (ctx, so);
209 CheckObjects (ctx, checker, visitedObjects, so.Items);
211 else if (value is XmlSchemaComplexContent) {
212 XmlSchemaComplexContent so = (XmlSchemaComplexContent) value;
213 checker.Check (ctx, so);
214 Check (ctx, checker, visitedObjects, so.Content);
216 else if (value is XmlSchemaComplexContentExtension) {
217 XmlSchemaComplexContentExtension so = (XmlSchemaComplexContentExtension) value;
218 checker.Check (ctx, so);
219 Check (ctx, checker, visitedObjects, so.Particle);
220 CheckObjects (ctx, checker, visitedObjects, so.Attributes);
221 Check (ctx, checker, visitedObjects, so.AnyAttribute);
223 else if (value is XmlSchemaComplexContentRestriction) {
224 XmlSchemaComplexContentRestriction so = (XmlSchemaComplexContentRestriction) value;
225 checker.Check (ctx, so);
226 Check (ctx, checker, visitedObjects, so.Particle);
227 CheckObjects (ctx, checker, visitedObjects, so.Attributes);
228 Check (ctx, checker, visitedObjects, so.AnyAttribute);
230 else if (value is XmlSchemaComplexType) {
231 XmlSchemaComplexType so = (XmlSchemaComplexType) value;
232 checker.Check (ctx, so);
233 Check (ctx, checker, visitedObjects, so.ContentModel);
234 Check (ctx, checker, visitedObjects, so.Particle);
235 CheckObjects (ctx, checker, visitedObjects, so.Attributes);
236 Check (ctx, checker, visitedObjects, so.AnyAttribute);
237 Check (ctx, checker, visitedObjects, so.ContentTypeParticle);
238 Check (ctx, checker, visitedObjects, so.AttributeWildcard);
240 else if (value is XmlSchemaElement) {
241 XmlSchemaElement so = (XmlSchemaElement) value;
242 checker.Check (ctx, so);
243 Check (ctx, checker, visitedObjects, so.SchemaType);
244 CheckObjects (ctx, checker, visitedObjects, so.Constraints);
246 else if (value is XmlSchemaGroup) {
247 XmlSchemaGroup so = (XmlSchemaGroup) value;
248 checker.Check (ctx, so);
249 Check (ctx, checker, visitedObjects, so.Particle);
251 else if (value is XmlSchemaGroupRef) {
252 XmlSchemaGroupRef so = (XmlSchemaGroupRef) value;
253 checker.Check (ctx, so);
255 else if (value is XmlSchemaIdentityConstraint) {
256 XmlSchemaIdentityConstraint so = (XmlSchemaIdentityConstraint) value;
257 checker.Check (ctx, so);
258 CheckObjects (ctx, checker, visitedObjects, so.Fields);
259 Check (ctx, checker, visitedObjects, so.Selector);
261 else if (value is XmlSchemaKeyref) {
262 XmlSchemaKeyref so = (XmlSchemaKeyref) value;
263 checker.Check (ctx, so);
265 else if (value is XmlSchemaRedefine) {
266 XmlSchemaRedefine so = (XmlSchemaRedefine) value;
267 checker.Check (ctx, so);
268 CheckObjects (ctx, checker, visitedObjects, so.Items);
270 else if (value is XmlSchemaSequence) {
271 XmlSchemaSequence so = (XmlSchemaSequence) value;
272 checker.Check (ctx, so);
273 CheckObjects (ctx, checker, visitedObjects, so.Items);
275 else if (value is XmlSchemaSimpleContent) {
276 XmlSchemaSimpleContent so = (XmlSchemaSimpleContent) value;
277 checker.Check (ctx, so);
278 Check (ctx, checker, visitedObjects, so.Content);
280 else if (value is XmlSchemaSimpleContentExtension) {
281 XmlSchemaSimpleContentExtension so = (XmlSchemaSimpleContentExtension) value;
282 checker.Check (ctx, so);
283 CheckObjects (ctx, checker, visitedObjects, so.Attributes);
284 Check (ctx, checker, visitedObjects, so.AnyAttribute);
286 else if (value is XmlSchemaSimpleContentRestriction) {
287 XmlSchemaSimpleContentRestriction so = (XmlSchemaSimpleContentRestriction) value;
288 checker.Check (ctx, so);
289 CheckObjects (ctx, checker, visitedObjects, so.Attributes);
290 Check (ctx, checker, visitedObjects, so.AnyAttribute);
291 CheckObjects (ctx, checker, visitedObjects, so.Facets);
293 else if (value is XmlSchemaSimpleType) {
294 XmlSchemaSimpleType so = (XmlSchemaSimpleType) value;
295 checker.Check (ctx, so);
296 Check (ctx, checker, visitedObjects, so.Content);
298 else if (value is XmlSchemaSimpleTypeList) {
299 XmlSchemaSimpleTypeList so = (XmlSchemaSimpleTypeList) value;
300 checker.Check (ctx, so);
302 else if (value is XmlSchemaSimpleTypeRestriction) {
303 XmlSchemaSimpleTypeRestriction so = (XmlSchemaSimpleTypeRestriction) value;
304 checker.Check (ctx, so);
305 CheckObjects (ctx, checker, visitedObjects, so.Facets);
307 else if (value is XmlSchemaSimpleTypeUnion) {
308 XmlSchemaSimpleTypeUnion so = (XmlSchemaSimpleTypeUnion) value;
309 checker.Check (ctx, so);
314 static void CheckExtensions (ConformanceCheckContext ctx, ConformanceChecker checker, ServiceDescriptionFormatExtensionCollection extensions)
316 foreach (object o in extensions) {
317 ServiceDescriptionFormatExtension ext = o as ServiceDescriptionFormatExtension;
318 if (ext != null)
319 checker.Check (ctx, ext);
325 #endif