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