Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.7 KiB

  1. using System;
  2. using System.IO;
  3. using System.Xml;
  4. using System.Xml.Schema;
  5. using System.Xml.Serialization;
  6. using UDDI.Diagnostics;
  7. namespace UDDI
  8. {
  9. /// ********************************************************************
  10. /// public class SchemaCollection
  11. /// --------------------------------------------------------------------
  12. /// <summary>
  13. /// </summary>
  14. /// ********************************************************************
  15. ///
  16. public class SchemaCollection
  17. {
  18. private static XmlSchemaCollection xsc = new XmlSchemaCollection();
  19. private static bool initialized = false;
  20. static SchemaCollection()
  21. {
  22. Debug.VerifySetting( "InstallRoot" );
  23. string installRoot = Config.GetString( "InstallRoot" );
  24. AddSchema( "urn:uddi-org:api", installRoot + "uddi_v1.xsd" );
  25. AddSchema( "urn:uddi-org:api_v2", installRoot + "uddi_v2.xsd" );
  26. AddSchema( "urn:uddi-org:repl", installRoot + "uddi_v2replication.xsd" );
  27. AddSchema( "urn:uddi-microsoft-com:api_v2_extensions", installRoot + "extensions.xsd" );
  28. Debug.Verify( 4 == xsc.Count, "UDDI_ERROR_FATALERROR_SCHEAMAS_LOADING" );
  29. initialized = true;
  30. }
  31. public static void AddSchema( string ns, string filename )
  32. {
  33. Debug.Verify(
  34. File.Exists( filename ),
  35. "UDDI_ERROR_FATALERROR_SCHEMEMISSING",
  36. ErrorType.E_fatalError,
  37. filename
  38. );
  39. xsc.Add( ns, filename );
  40. }
  41. public static void Validate( object obj )
  42. {
  43. Debug.Verify( initialized, "UDDI_ERROR_FATALERROR_SCHEAMAS_LOADING" );
  44. MemoryStream stream = new MemoryStream();
  45. XmlSerializer serializer = new XmlSerializer( obj.GetType() );
  46. serializer.Serialize( stream, obj );
  47. stream.Seek( 0, SeekOrigin.Begin );
  48. XmlTextReader reader = new XmlTextReader( stream );
  49. LocalValidate( reader );
  50. }
  51. public static void Validate( Stream stream )
  52. {
  53. Debug.Verify( initialized, "UDDI_ERROR_FATALERROR_SCHEAMAS_LOADING" );
  54. //
  55. // Rewind stream and validate
  56. //
  57. stream.Seek( 0, SeekOrigin.Begin );
  58. XmlTextReader reader = new XmlTextReader( stream );
  59. LocalValidate( reader );
  60. //
  61. // Rewind stream again, so someone else can use it
  62. //
  63. stream.Seek( 0, SeekOrigin.Begin );
  64. }
  65. public static void ValidateFile( string filename )
  66. {
  67. Debug.Verify( initialized, "UDDI_ERROR_FATALERROR_SCHEAMAS_LOADING" );
  68. XmlTextReader reader = new XmlTextReader( filename );
  69. LocalValidate( reader );
  70. }
  71. private static void LocalValidate( XmlTextReader reader )
  72. {
  73. XmlValidatingReader validator = new XmlValidatingReader( reader );
  74. validator.Schemas.Add( xsc );
  75. while( validator.Read()){}
  76. }
  77. }
  78. }