* ConformanceChecker.cs, BasicProfileChecker.cs: New files that implement
[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
35 namespace System.Web.Services.Description 
36 {
37         public sealed class WebServicesInteroperability
38         {
39                 private WebServicesInteroperability ()
40                 {
41                 }
42                 
43                 [MonoTODO]
44                 public static bool CheckConformance (WsiClaims claims, ServiceDescription service, BasicProfileViolationCollection violations)
45                 {
46                         ServiceDescriptionCollection col = new ServiceDescriptionCollection ();
47                         col.Add (service);
48                         ConformanceCheckContext ctx = new ConformanceCheckContext (col, violations);
49                         return Check (claims, ctx, col);
50                 }
51
52                 [MonoTODO]
53                 public static bool CheckConformance (WsiClaims claims, ServiceDescriptionCollection services, BasicProfileViolationCollection violations)
54                 {
55                         ConformanceCheckContext ctx = new ConformanceCheckContext (services, violations);
56                         return Check (claims, ctx, services);
57                 }
58
59                 [MonoTODO]
60                 public static bool CheckConformance (WsiClaims claims, WebReference webReference, BasicProfileViolationCollection violations)
61                 {
62                         ConformanceCheckContext ctx = new ConformanceCheckContext (webReference, violations);
63                         return Check (claims, ctx, webReference.Documents);
64                 }
65                 
66                 static bool Check (WsiClaims claims, ConformanceCheckContext ctx, IEnumerable documents)
67                 {
68                         ConformanceChecker[] checkers = GetCheckers (claims);
69                         if (checkers == null) return true;
70                         
71                         foreach (object doc in documents) {
72                                 if (!(doc is ServiceDescription)) continue;
73                                 
74                                 foreach (ConformanceChecker c in checkers)
75                                         Check (ctx, c, (ServiceDescription)doc);
76                         }
77                                 
78                         return ctx.Violations.Count == 0;
79                 }
80                 
81                 static ConformanceChecker[] GetCheckers (WsiClaims claims)
82                 {
83                         if ((claims & WsiClaims.BP10) != 0)
84                                 return new ConformanceChecker[] { BasicProfileChecker.Instance };
85                         return null;
86                 }
87                 
88                 static void Check (ConformanceCheckContext ctx, ConformanceChecker checker, ServiceDescription sd)
89                 {
90                         ctx.ServiceDescription = sd;
91                         ctx.Checker = checker;
92                         
93                         checker.Check (ctx, sd);
94                         CheckExtensions (ctx, checker, sd.Extensions);
95                         
96                         foreach (Service s in sd.Services) {
97                                 checker.Check (ctx, s);
98                                 foreach (Port p in s.Ports) {
99                                         checker.Check (ctx, p);
100                                         CheckExtensions (ctx, checker, p.Extensions);
101                                 }
102                         }
103                         
104                         foreach (Binding b in sd.Bindings)
105                         {
106                                 checker.Check (ctx, b);
107                                 CheckExtensions (ctx, checker, b.Extensions);
108                                 
109                                 foreach (OperationBinding oper in b.Operations) {
110                                         CheckExtensions (ctx, checker, oper.Extensions);
111                                         
112                                         foreach (MessageBinding mb in oper.Faults) {
113                                                 checker.Check (ctx, mb);
114                                                 CheckExtensions (ctx, checker, mb.Extensions);
115                                         }
116                                         
117                                         checker.Check (ctx, oper.Input);
118                                         CheckExtensions (ctx, checker, oper.Input.Extensions);
119                                         
120                                         checker.Check (ctx, oper.Output);
121                                         CheckExtensions (ctx, checker, oper.Output.Extensions);
122                                 }
123                         }
124                         
125                         foreach (PortType pt in sd.PortTypes)
126                         {
127                                 checker.Check (ctx, pt);
128                                 
129                                 foreach (Operation oper in pt.Operations) {
130                                         checker.Check (ctx, oper);
131                                         foreach (OperationMessage msg in oper.Messages)
132                                                 checker.Check (ctx, msg);
133                                         
134                                         foreach (OperationMessage msg in oper.Faults)
135                                                 checker.Check (ctx, msg);
136                                 }
137                         }
138                         
139                         foreach (Message msg in sd.Messages)
140                         {
141                                 checker.Check (ctx, msg);
142                                 foreach (MessagePart part in msg.Parts)
143                                         checker.Check (ctx, part);
144                         }
145                 }
146                 
147                 static void CheckExtensions (ConformanceCheckContext ctx, ConformanceChecker checker, ServiceDescriptionFormatExtensionCollection extensions)
148                 {
149                         foreach (ServiceDescriptionFormatExtension ext in extensions)
150                                 checker.Check (ctx, ext);
151                 }
152         }
153 }
154
155 #endif