2 // System.Web.Services.Description.ConformanceChecker.cs
5 // Lluis Sanchez (lluis@novell.com)
7 // Copyright (C) Novell, Inc., 2004
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
33 using System.Xml.Schema;
35 namespace System.Web.Services.Description
37 internal abstract class ConformanceChecker
39 public abstract WsiClaims Claims { get; }
40 public virtual void Check (ConformanceCheckContext ctx, Binding value) { }
41 public virtual void Check (ConformanceCheckContext ctx, MessageBinding value) { }
42 public virtual void Check (ConformanceCheckContext ctx, Import value) { }
43 public virtual void Check (ConformanceCheckContext ctx, Message value) { }
44 public virtual void Check (ConformanceCheckContext ctx, MessagePart value) { }
45 public virtual void Check (ConformanceCheckContext ctx, Operation value) { }
46 public virtual void Check (ConformanceCheckContext ctx, OperationBinding value) { }
47 public virtual void Check (ConformanceCheckContext ctx, OperationMessage value) { }
48 public virtual void Check (ConformanceCheckContext ctx, Port value) { }
49 public virtual void Check (ConformanceCheckContext ctx, PortType value) { }
50 public virtual void Check (ConformanceCheckContext ctx, Service value) { }
51 public virtual void Check (ConformanceCheckContext ctx, ServiceDescription value) { }
52 public virtual void Check (ConformanceCheckContext ctx, Types value) { }
53 public virtual void Check (ConformanceCheckContext ctx, ServiceDescriptionFormatExtension value) {}
54 public virtual void Check (ConformanceCheckContext ctx, XmlSchemaObject value) {}
57 internal class ConformanceRule
59 public string NormativeStatement;
60 public string Details;
61 public string Recommendation;
63 public ConformanceRule (string name, string desc, string rec)
65 NormativeStatement = name;
71 internal class ConformanceCheckContext
73 BasicProfileViolationCollection violations;
74 ServiceDescriptionCollection collection;
75 WebReference webReference;
76 ConformanceChecker checker;
77 public ServiceDescription ServiceDescription;
79 public ConformanceCheckContext (ServiceDescriptionCollection collection, BasicProfileViolationCollection violations)
81 this.collection = collection;
82 this.violations = violations;
85 public ConformanceCheckContext (WebReference webReference, BasicProfileViolationCollection violations)
87 this.webReference = webReference;
88 this.violations = violations;
91 public ConformanceChecker Checker {
92 get { return checker; }
93 set { checker = value; }
96 public BasicProfileViolationCollection Violations {
97 get { return violations; }
100 public object GetDocument (string url)
102 if (collection != null)
105 return webReference.Documents [url];
108 public void ReportError (object currentObject, string msg)
110 throw new InvalidOperationException (msg + " (" + GetDescription (currentObject) + ")");
113 public void ReportRuleViolation (object currentObject, ConformanceRule rule)
115 BasicProfileViolation v = null;
116 foreach (BasicProfileViolation bpv in violations) {
117 if (bpv.NormativeStatement == rule.NormativeStatement) {
124 v = new BasicProfileViolation (checker.Claims, rule);
128 v.Elements.Add (GetDescription (currentObject));
131 string GetDescription (object obj)
133 if (obj is ServiceDescription) {
134 return "Service Description '" + ServiceDescription.TargetNamespace + "'";
136 else if (obj is Binding || obj is Message || obj is PortType || obj is Service) {
137 return GetNamedItemDescription (obj, ServiceDescription);
139 else if (obj is Import) {
140 return GetItemDescription (obj, ServiceDescription, ((Import)obj).Location);
142 else if (obj is MessageBinding) {
143 return GetNamedItemDescription (obj, ((MessageBinding)obj).OperationBinding);
145 else if (obj is MessagePart) {
146 return GetNamedItemDescription (obj, ((MessagePart)obj).Message);
148 else if (obj is Operation) {
149 return GetNamedItemDescription (obj, ((Operation)obj).PortType);
151 else if (obj is OperationBinding) {
152 return GetNamedItemDescription (obj, ((OperationBinding)obj).Binding);
154 else if (obj is OperationMessage) {
155 return GetNamedItemDescription (obj, ((OperationMessage)obj).Operation);
157 else if (obj is Port) {
158 return GetNamedItemDescription (obj, ((Port)obj).Service);
160 else if (obj is ServiceDescriptionFormatExtension) {
161 ServiceDescriptionFormatExtension ext = (ServiceDescriptionFormatExtension) obj;
162 return GetItemDescription (ext, ext.Parent, ext.GetType().Name);
164 return obj.GetType().Name;
167 string GetNamedItemDescription (object item, object parent)
169 return item.GetType().Name + " '" + ((NamedItem)item).Name + "', in " + GetDescription (parent);
172 string GetItemDescription (object item, object parent, string name)
174 return item.GetType().Name + " '" + name + "' in " + GetDescription (parent);