BasicProfileChecker.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // System.Web.Services.Description.BasicProfileChecker.cs
  3. //
  4. // Author:
  5. // Lluis Sanchez ([email protected])
  6. //
  7. // Copyright (C) Novell, Inc., 2004
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System.Xml.Schema;
  31. namespace System.Web.Services.Description
  32. {
  33. internal class BasicProfileChecker: ConformanceChecker
  34. {
  35. public static BasicProfileChecker Instance = new BasicProfileChecker ();
  36. public override WsiClaims Claims {
  37. get { return WsiClaims.BP10; }
  38. }
  39. public override void Check (ConformanceCheckContext ctx, Import value)
  40. {
  41. if (value.Location == "" || value.Location == null) {
  42. ctx.ReportRuleViolation (value, BasicProfileRules.R2007);
  43. return;
  44. }
  45. object doc = ctx.GetDocument (value.Location);
  46. if (doc == null) ctx.ReportError (value, "Document '" + value.Location + "' not found");
  47. if (doc is XmlSchema)
  48. ctx.ReportRuleViolation (value, BasicProfileRules.R2002);
  49. ServiceDescription imported = doc as ServiceDescription;
  50. if (imported == null) {
  51. ctx.ReportRuleViolation (value, BasicProfileRules.R2001);
  52. return;
  53. }
  54. // TODO: rule R2003
  55. if (imported.TargetNamespace != value.Namespace)
  56. ctx.ReportRuleViolation (value, BasicProfileRules.R2005);
  57. }
  58. public override void Check (ConformanceCheckContext ctx, ServiceDescription value)
  59. {
  60. }
  61. public override void Check (ConformanceCheckContext ctx, ServiceDescriptionFormatExtension value)
  62. {
  63. if (value.Required)
  64. ctx.ReportRuleViolation (value, BasicProfileRules.R2026);
  65. }
  66. public override void Check (ConformanceCheckContext ctx, XmlSchemaObject value)
  67. {
  68. if (value is XmlSchemaImport) {
  69. XmlSchemaImport import = (XmlSchemaImport) value;
  70. XmlSchema doc = ctx.GetDocument (import.SchemaLocation) as XmlSchema;
  71. if (doc == null) ctx.ReportError (value, "Schema '" + import.SchemaLocation + "' not found");
  72. // TODO: rule R2004, R2010, R2011
  73. }
  74. }
  75. }
  76. internal class BasicProfileRules
  77. {
  78. public static readonly ConformanceRule R2001 = new ConformanceRule (
  79. "R2001",
  80. "A DESCRIPTION MUST only use the WSDL \"import\" statement to import another WSDL description",
  81. "");
  82. public static readonly ConformanceRule R2002 = new ConformanceRule (
  83. "R2002",
  84. "To import XML Schema Definitions, a DESCRIPTION MUST use the XML Schema \"import\" statement",
  85. "");
  86. public static readonly ConformanceRule R2007 = new ConformanceRule (
  87. "R2007",
  88. "A DESCRIPTION MUST specify a non-empty location attribute on the wsdl:import element",
  89. "");
  90. public static readonly ConformanceRule R2005 = new ConformanceRule (
  91. "R2005",
  92. "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",
  93. "");
  94. public static readonly ConformanceRule R2026 = new ConformanceRule (
  95. "R2026",
  96. "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",
  97. "");
  98. }
  99. /*
  100. The following rules cannot be checked:
  101. R2002, R2003, R4004, R4003
  102. There is no access to the unerlying xml
  103. */
  104. }
  105. #endif