* ConformanceChecker.cs, BasicProfileChecker.cs: New files that implement
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / BasicProfileChecker.cs
1 // 
2 // System.Web.Services.Description.BasicProfileChecker.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.Xml.Schema;
34
35 namespace System.Web.Services.Description 
36 {
37         internal class BasicProfileChecker: ConformanceChecker
38         {
39                 public static BasicProfileChecker Instance = new BasicProfileChecker ();
40                 
41                 public override WsiClaims Claims { 
42                         get { return WsiClaims.BP10; }
43                 }
44                 
45                 public override void Check (ConformanceCheckContext ctx, Import value) 
46                 {
47                         if (value.Location == "" || value.Location == null) {
48                                 ctx.ReportRuleViolation (value, BasicProfileRules.R2007);
49                                 return;
50                         }
51                         
52                         object doc = ctx.GetDocument (value.Location);
53                         if (doc == null) ctx.ReportError (value, "Document '" + value.Location + "' not found");
54                         
55                         if (doc is XmlSchema)
56                                 ctx.ReportRuleViolation (value, BasicProfileRules.R2002);
57                                 
58                         ServiceDescription imported = doc as ServiceDescription;
59                         if (imported == null) {
60                                 ctx.ReportRuleViolation (value, BasicProfileRules.R2001);
61                                 return;
62                         }
63                                 
64                         // TODO: rule R2003
65                         
66                         if (imported.TargetNamespace != value.Namespace)
67                                 ctx.ReportRuleViolation (value, BasicProfileRules.R2005);
68                 }
69                 
70                 public override void Check (ConformanceCheckContext ctx, ServiceDescription value)
71                 {
72                         
73                 }
74                 
75                 public override void Check (ConformanceCheckContext ctx, ServiceDescriptionFormatExtension value)
76                 {
77                         if (value.Required)
78                                 ctx.ReportRuleViolation (value, BasicProfileRules.R2026);
79                 }
80                 
81                 public override void Check (ConformanceCheckContext ctx, XmlSchemaObject value)
82                 {
83                         if (value is XmlSchemaImport) {
84                                 XmlSchemaImport import = (XmlSchemaImport) value;
85                                 XmlSchema doc = ctx.GetDocument (import.SchemaLocation) as XmlSchema;
86                                 if (doc == null) ctx.ReportError (value, "Schema '" + import.SchemaLocation + "' not found");
87                                 
88                                 // TODO: rule R2004, R2010, R2011
89                                 
90                         }
91                 }
92         }
93         
94         internal class BasicProfileRules
95         {
96                 public static readonly ConformanceRule R2001 = new ConformanceRule (
97                         "R2001", 
98                         "A DESCRIPTION MUST only use the WSDL \"import\" statement to import another WSDL description",
99                         "");
100                         
101                 public static readonly ConformanceRule R2002 = new ConformanceRule (
102                         "R2002", 
103                         "To import XML Schema Definitions, a DESCRIPTION MUST use the XML Schema \"import\" statement",
104                         "");
105                         
106                 public static readonly ConformanceRule R2007 = new ConformanceRule (
107                         "R2007", 
108                         "A DESCRIPTION MUST specify a non-empty location attribute on the wsdl:import element",
109                         "");
110                         
111                 public static readonly ConformanceRule R2005 = new ConformanceRule (
112                         "R2005", 
113                         "The targetNamespace attribute on the wsdl:definitions element of a description that is being imported MUST have same the value as the namespace attribute on the wsdl:import element in the importing DESCRIPTION",
114                         "");
115                         
116                 public static readonly ConformanceRule R2026 = new ConformanceRule (
117                         "R2026", 
118                         "A DESCRIPTION SHOULD NOT include extension elements with a wsdl:required attribute value of \"true\" on any WSDL construct (wsdl:binding,  wsdl:portType, wsdl:message, wsdl:types or wsdl:import) that claims conformance to the Profile",
119                         "");
120         }
121         
122         /* 
123                 The following rules cannot be checked:
124                 R2002, R2003, R4004, R4003
125                         There is no access to the unerlying xml 
126         */
127 }
128
129 #endif