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.

218 lines
5.5 KiB

  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Diagnostics;
  5. using System.Net;
  6. using System.Web.Services;
  7. using System.Web.Services.Description;
  8. using System.Web.Services.Protocols;
  9. using System.Xml;
  10. using System.Xml.Serialization;
  11. using System.Xml.Xsl;
  12. using System.Xml.XPath;
  13. using System.Text;
  14. using System.Globalization;
  15. using Microsoft.Uddi;
  16. using Microsoft.Uddi.Web;
  17. namespace Microsoft.Uddi
  18. {
  19. public enum UddiVersion
  20. {
  21. V1,
  22. V2,
  23. Negotiate
  24. }
  25. }
  26. namespace Microsoft.Uddi.VersionSupport
  27. {
  28. internal abstract class IUddiVersion
  29. {
  30. public abstract string Generic
  31. { get; }
  32. public abstract string Namespace
  33. { get; }
  34. public abstract string Translate( string xml );
  35. }
  36. internal sealed class UddiVersionSupport
  37. {
  38. internal readonly static UddiVersion[] SupportedVersions;
  39. internal readonly static UddiVersion CurrentVersion;
  40. //
  41. // This is a bit awkward to store the current namespace and generic separately rather than using the UddiVersion class. But, we need
  42. // to use these values in our XmlRoot attribute declaration that each serialize-able class uses. Only const values can be used
  43. // in attribute declarations. Make sure to update these values when you change the current version
  44. //
  45. internal const string CurrentNamespace = "urn:uddi-org:api_v2";
  46. internal const string CurrentGeneric = "2.0";
  47. private static Hashtable UddiVersions;
  48. private UddiVersionSupport()
  49. {
  50. //
  51. // Don't let anyone construct an instance of this class.
  52. //
  53. }
  54. internal static string Translate( string xml, UddiVersion version )
  55. {
  56. //
  57. // Use the current version in this case
  58. //
  59. if( version == UddiVersion.Negotiate )
  60. {
  61. version = CurrentVersion;
  62. }
  63. IUddiVersion uddiVersion = ( IUddiVersion ) UddiVersions[ version ];
  64. return uddiVersion.Translate( xml );
  65. }
  66. static UddiVersionSupport()
  67. {
  68. //
  69. // Increase this array if you want to support more previous versions. Do not include
  70. // the current version in this array.
  71. //
  72. SupportedVersions = new UddiVersion[1];
  73. //
  74. // Add our supported previous versions
  75. //
  76. SupportedVersions[0] = UddiVersion.V1;
  77. //
  78. // Current version is version 2.0
  79. //
  80. CurrentVersion = UddiVersion.V2;
  81. //
  82. // Store instances to versions
  83. //
  84. UddiVersions = new Hashtable();
  85. UddiVersions[ UddiVersion.V1 ] = new UddiVersion1();
  86. UddiVersions[ UddiVersion.V2 ] = new UddiVersion2();
  87. }
  88. }
  89. internal class UddiVersion1 : IUddiVersion
  90. {
  91. private XmlDocument input;
  92. public UddiVersion1()
  93. {
  94. input = new XmlDocument();
  95. }
  96. public override string Generic
  97. {
  98. get { return "1.0"; }
  99. }
  100. public override string Namespace
  101. {
  102. get { return "urn:uddi-org:api"; }
  103. }
  104. public override string Translate( string xml )
  105. {
  106. //
  107. // Load up the input into a DOM so we can make some queries to do replacements. I considered
  108. // using a XSTL stylesheet here, but there didn't appear to be a good way of only replacing select items.
  109. // You pretty much have to take the input, and specify how every element in the output should look (or
  110. // do an exact copy); this results in too much error-prone XSLT code.
  111. //
  112. input.LoadXml( xml );
  113. //
  114. // There are a number of messages that version 1 just does not support. Kick out now if we are trying to
  115. // call any of these messages.
  116. //
  117. //
  118. // Replace generic attribute value and default namespace
  119. //
  120. XmlNodeList nodes = input.SelectNodes( "descendant::*[@generic]" );
  121. foreach( XmlNode node in nodes )
  122. {
  123. node.Attributes.GetNamedItem( "generic" ).Value = Generic;
  124. XmlNode xmlnsAttribute = node.Attributes.GetNamedItem( "xmlns" );
  125. if( null != xmlnsAttribute )
  126. {
  127. xmlnsAttribute.Value = Namespace;
  128. }
  129. }
  130. //
  131. // Remove name@xml:lang values
  132. //
  133. nodes =input.SelectNodes( "descendant::*[@xml:lang]" , new XmlNamespaceManager( input.NameTable ) );
  134. foreach( XmlNode node in nodes )
  135. {
  136. if( node.LocalName.ToLower( CultureInfo.CurrentCulture ).Equals( "name" ) )
  137. {
  138. node.Attributes.RemoveNamedItem( "xml:lang" );
  139. }
  140. }
  141. return input.OuterXml;
  142. }
  143. }
  144. internal class UddiVersion2 : IUddiVersion
  145. {
  146. private XmlDocument input;
  147. public UddiVersion2()
  148. {
  149. input = new XmlDocument();
  150. }
  151. public override string Generic
  152. {
  153. get { return "2.0"; }
  154. }
  155. public override string Namespace
  156. {
  157. get { return "urn:uddi-org:api_v2"; }
  158. }
  159. public override string Translate( string xml )
  160. {
  161. //
  162. // Load up the input into a DOM so we can make some queries to do replacements. I considered
  163. // using a XSTL stylesheet here, but there didn't appear to be a good way of only replacing select items.
  164. // You pretty much have to take the input, and specify how every element in the output should look (or
  165. // do an exact copy); this results in too much error-prone XSLT code.
  166. //
  167. input.LoadXml( xml );
  168. //
  169. // Replace generic attribute value and default namespace
  170. //
  171. XmlNodeList nodes = input.SelectNodes( "descendant::*[@generic]" );
  172. foreach( XmlNode node in nodes )
  173. {
  174. node.Attributes.GetNamedItem( "generic" ).Value = Generic;
  175. XmlNode xmlnsAttribute = node.Attributes.GetNamedItem( "xmlns" );
  176. if( null != xmlnsAttribute )
  177. {
  178. xmlnsAttribute.Value = Namespace;
  179. }
  180. }
  181. return input.OuterXml;
  182. }
  183. }
  184. }