SchemaReference.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // System.Web.Services.Discovery.SchemaReference.cs
  3. //
  4. // Author:
  5. // Dave Bettin ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // Copyright (C) Dave Bettin, 2002
  9. //
  10. using System.ComponentModel;
  11. using System.IO;
  12. using System.Xml.Schema;
  13. using System.Xml.Serialization;
  14. namespace System.Web.Services.Discovery {
  15. [XmlRootAttribute("schemaRef", Namespace="http://schemas/xmlsoap.org/disco/schema/", IsNullable=true)]
  16. public sealed class SchemaReference : DiscoveryReference {
  17. #region Fields
  18. public const string Namespace = "http://schemas/xmlsoap.org/disco/schema/";
  19. private string defaultFilename;
  20. private string href;
  21. private string targetNamespace;
  22. private XmlSchema schema;
  23. #endregion // Fields
  24. #region Constructors
  25. public SchemaReference ()
  26. {
  27. }
  28. public SchemaReference (string href) : this()
  29. {
  30. this.href = href;
  31. }
  32. #endregion // Constructors
  33. #region Properties
  34. [XmlIgnore]
  35. public override string DefaultFilename {
  36. get { return FilenameFromUrl (Url) + ".xsd"; }
  37. }
  38. [XmlAttribute("ref")]
  39. public string Ref {
  40. get { return href; }
  41. set { href = value; }
  42. }
  43. [XmlIgnore]
  44. public override string Url {
  45. get { return href; }
  46. set { href = value; }
  47. }
  48. [DefaultValue("")]
  49. [XmlAttribute("targetNamespace")]
  50. public string TargetNamespace {
  51. get { return targetNamespace; }
  52. set { targetNamespace = targetNamespace; }
  53. }
  54. [XmlIgnore]
  55. public XmlSchema Schema {
  56. get {
  57. if (ClientProtocol == null)
  58. throw new InvalidOperationException ("The ClientProtocol property is a null reference");
  59. XmlSchema doc = ClientProtocol.Documents [Url] as XmlSchema;
  60. if (doc == null)
  61. throw new Exception ("The Documents property of ClientProtocol does not contain a schema with the url " + Url);
  62. return doc;
  63. }
  64. }
  65. #endregion // Properties
  66. #region Methods
  67. public override object ReadDocument (Stream stream)
  68. {
  69. return XmlSchema.Read (stream, null);
  70. }
  71. protected internal override void Resolve (string contentType, Stream stream)
  72. {
  73. XmlSchema doc = XmlSchema.Read (stream, null);
  74. ClientProtocol.Documents.Add (Url, doc);
  75. if (!ClientProtocol.References.Contains (Url))
  76. ClientProtocol.References.Add (this);
  77. }
  78. public override void WriteDocument (object document, Stream stream)
  79. {
  80. ((XmlSchema)document).Write (stream);
  81. }
  82. #endregion // Methods
  83. }
  84. }