f022aee601ff169735bfb063e3cd02170c8f8a42
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / WebServicesInteroperability.cs
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 //
9
10 //
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.
29 //
30
31 #if NET_2_0
32
33 using System.Collections;
34 using System.Xml.Schema;
35
36 namespace System.Web.Services.Description 
37 {
38         public sealed class WebServicesInteroperability
39         {
40                 private WebServicesInteroperability ()
41                 {
42                 }
43                 
44                 [MonoTODO]
45                 public static bool CheckConformance (WsiClaims claims, ServiceDescription service, BasicProfileViolationCollection violations)
46                 {
47                         ServiceDescriptionCollection col = new ServiceDescriptionCollection ();
48                         col.Add (service);
49                         ConformanceCheckContext ctx = new ConformanceCheckContext (col, violations);
50                         return Check (claims, ctx, col);
51                 }
52
53                 [MonoTODO]
54                 public static bool CheckConformance (WsiClaims claims, ServiceDescriptionCollection services, BasicProfileViolationCollection violations)
55                 {
56                         ConformanceCheckContext ctx = new ConformanceCheckContext (services, violations);
57                         return Check (claims, ctx, services);
58                 }
59
60                 [MonoTODO]
61                 public static bool CheckConformance (WsiClaims claims, WebReference webReference, BasicProfileViolationCollection violations)
62                 {
63                         ConformanceCheckContext ctx = new ConformanceCheckContext (webReference, violations);
64                         return Check (claims, ctx, webReference.Documents.Values);
65                 }
66                 
67                 static bool Check (WsiClaims claims, ConformanceCheckContext ctx, IEnumerable documents)
68                 {
69                         ConformanceChecker[] checkers = GetCheckers (claims);
70                         if (checkers == null) return true;
71                         
72                         foreach (object doc in documents) {
73                                 if (!(doc is ServiceDescription)) continue;
74                                 
75                                 foreach (ConformanceChecker c in checkers)
76                                         Check (ctx, c, (ServiceDescription)doc);
77                         }
78                                 
79                         return ctx.Violations.Count == 0;
80                 }
81                 
82                 static ConformanceChecker[] GetCheckers (WsiClaims claims)
83                 {
84                         if ((claims & WsiClaims.BP10) != 0)
85                                 return new ConformanceChecker[] { BasicProfileChecker.Instance };
86                         return null;
87                 }
88                 
89                 static void Check (ConformanceCheckContext ctx, ConformanceChecker checker, ServiceDescription sd)
90                 {
91                         ctx.ServiceDescription = sd;
92                         ctx.Checker = checker;
93                         
94                         checker.Check (ctx, sd);
95                         CheckExtensions (ctx, checker, sd.Extensions);
96                         
97                         foreach (Import i in sd.Imports) {
98                                 checker.Check (ctx, i);
99                         }
100                         
101                         foreach (Service s in sd.Services) {
102                                 checker.Check (ctx, s);
103                                 foreach (Port p in s.Ports) {
104                                         checker.Check (ctx, p);
105                                         CheckExtensions (ctx, checker, p.Extensions);
106                                 }
107                         }
108                         
109                         foreach (Binding b in sd.Bindings)
110                         {
111                                 checker.Check (ctx, b);
112                                 CheckExtensions (ctx, checker, b.Extensions);
113                                 
114                                 foreach (OperationBinding oper in b.Operations) {
115                                         CheckExtensions (ctx, checker, oper.Extensions);
116                                         
117                                         foreach (MessageBinding mb in oper.Faults) {
118                                                 checker.Check (ctx, mb);
119                                                 CheckExtensions (ctx, checker, mb.Extensions);
120                                         }
121                                         
122                                         checker.Check (ctx, oper.Input);
123                                         CheckExtensions (ctx, checker, oper.Input.Extensions);
124                                         
125                                         checker.Check (ctx, oper.Output);
126                                         CheckExtensions (ctx, checker, oper.Output.Extensions);
127                                 }
128                         }
129                         
130                         foreach (PortType pt in sd.PortTypes)
131                         {
132                                 checker.Check (ctx, pt);
133                                 
134                                 foreach (Operation oper in pt.Operations) {
135                                         checker.Check (ctx, oper);
136                                         foreach (OperationMessage msg in oper.Messages)
137                                                 checker.Check (ctx, msg);
138                                         
139                                         foreach (OperationMessage msg in oper.Faults)
140                                                 checker.Check (ctx, msg);
141                                 }
142                         }
143                         
144                         foreach (Message msg in sd.Messages)
145                         {
146                                 checker.Check (ctx, msg);
147                                 foreach (MessagePart part in msg.Parts)
148                                         checker.Check (ctx, part);
149                         }
150                         
151                         if (sd.Types != null) {
152                                 checker.Check (ctx, sd.Types);
153                                 if (sd.Types.Schemas != null) {
154                                         foreach (XmlSchema s in sd.Types.Schemas) {
155                                                 ctx.CurrentSchema = s;
156                                                 checker.Check (ctx, s);
157                                                 CheckObjects (ctx, checker, new Hashtable (), s.Items);
158                                         }
159                                 }
160                         }
161                 }
162                 
163                 static void CheckObjects (ConformanceCheckContext ctx, ConformanceChecker checker, Hashtable visitedObjects, XmlSchemaObjectCollection col)
164                 {
165                         foreach (XmlSchemaObject item in col)
166                                 Check (ctx, checker, visitedObjects, item);
167                 }
168                 
169                 static void Check (ConformanceCheckContext ctx, ConformanceChecker checker, Hashtable visitedObjects, XmlSchemaObject value)
170                 {
171                         if (value == null) return;
172                         
173                         if (visitedObjects.Contains (value)) return;
174                         visitedObjects.Add (value, value);
175                         
176                         if (value is XmlSchemaImport) {
177                                 XmlSchemaImport so = (XmlSchemaImport) value;
178                                 checker.Check (ctx, so);
179                         }
180                         else if (value is XmlSchemaAll) {
181                                 XmlSchemaAll so = (XmlSchemaAll) value;
182                                 checker.Check (ctx, so);
183                                 CheckObjects (ctx, checker, visitedObjects, so.Items);
184                         }
185                         else if (value is XmlSchemaAnnotation) {
186                                 XmlSchemaAnnotation so = (XmlSchemaAnnotation) value;
187                                 checker.Check (ctx, so);
188                                 CheckObjects (ctx, checker, visitedObjects, so.Items);
189                         }
190                         else if (value is XmlSchemaAttribute) {
191                                 XmlSchemaAttribute so = (XmlSchemaAttribute) value;
192                                 checker.Check (ctx, so);
193                         }
194                         else if (value is XmlSchemaAttributeGroup) {
195                                 XmlSchemaAttributeGroup so = (XmlSchemaAttributeGroup) value;
196                                 checker.Check (ctx, so);
197                                 CheckObjects (ctx, checker, visitedObjects, so.Attributes);
198                                 Check (ctx, checker, visitedObjects, so.AnyAttribute);
199                                 Check (ctx, checker, visitedObjects, so.RedefinedAttributeGroup);
200                         }
201                         else if (value is XmlSchemaAttributeGroupRef) {
202                                 XmlSchemaAttributeGroupRef so = (XmlSchemaAttributeGroupRef) value;
203                                 checker.Check (ctx, so);
204                         }
205                         else if (value is XmlSchemaChoice) {
206                                 XmlSchemaChoice so = (XmlSchemaChoice) value;
207                                 checker.Check (ctx, so);
208                                 CheckObjects (ctx, checker, visitedObjects, so.Items);
209                         }
210                         else if (value is XmlSchemaComplexContent) {
211                                 XmlSchemaComplexContent so = (XmlSchemaComplexContent) value;
212                                 checker.Check (ctx, so);
213                                 Check (ctx, checker, visitedObjects, so.Content);
214                         }
215                         else if (value is XmlSchemaComplexContentExtension) {
216                                 XmlSchemaComplexContentExtension so = (XmlSchemaComplexContentExtension) value;
217                                 checker.Check (ctx, so);
218                                 Check (ctx, checker, visitedObjects, so.Particle);
219                                 CheckObjects (ctx, checker, visitedObjects, so.Attributes);
220                                 Check (ctx, checker, visitedObjects, so.AnyAttribute);
221                         }
222                         else if (value is XmlSchemaComplexContentRestriction) {
223                                 XmlSchemaComplexContentRestriction so = (XmlSchemaComplexContentRestriction) value;
224                                 checker.Check (ctx, so);
225                                 Check (ctx, checker, visitedObjects, so.Particle);
226                                 CheckObjects (ctx, checker, visitedObjects, so.Attributes);
227                                 Check (ctx, checker, visitedObjects, so.AnyAttribute);
228                         }
229                         else if (value is XmlSchemaComplexType) {
230                                 XmlSchemaComplexType so = (XmlSchemaComplexType) value;
231                                 checker.Check (ctx, so);
232                                 Check (ctx, checker, visitedObjects, so.ContentModel);
233                                 Check (ctx, checker, visitedObjects, so.Particle);
234                                 CheckObjects (ctx, checker, visitedObjects, so.Attributes);
235                                 Check (ctx, checker, visitedObjects, so.AnyAttribute);
236                                 Check (ctx, checker, visitedObjects, so.ContentTypeParticle);
237                                 Check (ctx, checker, visitedObjects, so.AttributeWildcard);
238                         }
239                         else if (value is XmlSchemaElement) {
240                                 XmlSchemaElement so = (XmlSchemaElement) value;
241                                 checker.Check (ctx, so);
242                                 Check (ctx, checker, visitedObjects, so.SchemaType);
243                                 CheckObjects (ctx, checker, visitedObjects, so.Constraints);
244                         }
245                         else if (value is XmlSchemaGroup) {
246                                 XmlSchemaGroup so = (XmlSchemaGroup) value;
247                                 checker.Check (ctx, so);
248                                 Check (ctx, checker, visitedObjects, so.Particle);
249                         }
250                         else if (value is XmlSchemaGroupRef) {
251                                 XmlSchemaGroupRef so = (XmlSchemaGroupRef) value;
252                                 checker.Check (ctx, so);
253                         }
254                         else if (value is XmlSchemaIdentityConstraint) {
255                                 XmlSchemaIdentityConstraint so = (XmlSchemaIdentityConstraint) value;
256                                 checker.Check (ctx, so);
257                                 CheckObjects (ctx, checker, visitedObjects, so.Fields);
258                                 Check (ctx, checker, visitedObjects, so.Selector);
259                         }
260                         else if (value is XmlSchemaKeyref) {
261                                 XmlSchemaKeyref so = (XmlSchemaKeyref) value;
262                                 checker.Check (ctx, so);
263                         }
264                         else if (value is XmlSchemaRedefine) {
265                                 XmlSchemaRedefine so = (XmlSchemaRedefine) value;
266                                 checker.Check (ctx, so);
267                                 CheckObjects (ctx, checker, visitedObjects, so.Items);
268                         }
269                         else if (value is XmlSchemaSequence) {
270                                 XmlSchemaSequence so = (XmlSchemaSequence) value;
271                                 checker.Check (ctx, so);
272                                 CheckObjects (ctx, checker, visitedObjects, so.Items);
273                         }
274                         else if (value is XmlSchemaSimpleContent) {
275                                 XmlSchemaSimpleContent so = (XmlSchemaSimpleContent) value;
276                                 checker.Check (ctx, so);
277                                 Check (ctx, checker, visitedObjects, so.Content);
278                         }
279                         else if (value is XmlSchemaSimpleContentExtension) {
280                                 XmlSchemaSimpleContentExtension so = (XmlSchemaSimpleContentExtension) value;
281                                 checker.Check (ctx, so);
282                                 CheckObjects (ctx, checker, visitedObjects, so.Attributes);
283                                 Check (ctx, checker, visitedObjects, so.AnyAttribute);
284                         }
285                         else if (value is XmlSchemaSimpleContentRestriction) {
286                                 XmlSchemaSimpleContentRestriction so = (XmlSchemaSimpleContentRestriction) value;
287                                 checker.Check (ctx, so);
288                                 CheckObjects (ctx, checker, visitedObjects, so.Attributes);
289                                 Check (ctx, checker, visitedObjects, so.AnyAttribute);
290                                 CheckObjects (ctx, checker, visitedObjects, so.Facets);
291                         }
292                         else if (value is XmlSchemaSimpleType) {
293                                 XmlSchemaSimpleType so = (XmlSchemaSimpleType) value;
294                                 checker.Check (ctx, so);
295                                 Check (ctx, checker, visitedObjects, so.Content);
296                         }
297                         else if (value is XmlSchemaSimpleTypeList) {
298                                 XmlSchemaSimpleTypeList so = (XmlSchemaSimpleTypeList) value;
299                                 checker.Check (ctx, so);
300                         }
301                         else if (value is XmlSchemaSimpleTypeRestriction) {
302                                 XmlSchemaSimpleTypeRestriction so = (XmlSchemaSimpleTypeRestriction) value;
303                                 checker.Check (ctx, so);
304                                 CheckObjects (ctx, checker, visitedObjects, so.Facets);
305                         }
306                         else if (value is XmlSchemaSimpleTypeUnion) {
307                                 XmlSchemaSimpleTypeUnion so = (XmlSchemaSimpleTypeUnion) value;
308                                 checker.Check (ctx, so);
309                         }
310                 }
311                                 
312                 
313                 static void CheckExtensions (ConformanceCheckContext ctx, ConformanceChecker checker, ServiceDescriptionFormatExtensionCollection extensions)
314                 {
315                         foreach (ServiceDescriptionFormatExtension ext in extensions)
316                                 checker.Check (ctx, ext);
317                 }
318         }
319 }
320
321 #endif