2 // System.Web.Services.Discovery.DiscoveryReference.cs
\r
5 // Dave Bettin (javabettin@yahoo.com)
\r
6 // Lluis Sanchez Gual (lluis@ximian.com)
\r
8 // Copyright (C) Dave Bettin, 2002
\r
12 using System.Xml.Serialization;
\r
14 namespace System.Web.Services.Discovery {
\r
15 public abstract class DiscoveryReference {
\r
19 private string defaultFilename;
\r
20 private DiscoveryClientProtocol clientProtocol;
\r
22 #endregion // Fields
\r
24 #region Constructors
\r
26 protected DiscoveryReference ()
\r
30 #endregion // Constructors
\r
35 public DiscoveryClientProtocol ClientProtocol {
\r
36 get { return clientProtocol; }
\r
37 set { clientProtocol = value; }
\r
41 public virtual string DefaultFilename {
\r
42 get { return FilenameFromUrl (Url); }
\r
46 public abstract string Url {
\r
51 #endregion // Properties
\r
55 protected static string FilenameFromUrl (string url)
\r
57 int i = url.LastIndexOf ("/");
\r
58 if (i != -1) url = url.Substring (i+1);
\r
60 i = url.IndexOfAny (new char[] {'.','?','\\'});
\r
61 if (i != -1) url = url.Substring (0,i);
\r
63 System.Text.StringBuilder sb = new System.Text.StringBuilder ();
\r
64 for (int n=0; n<url.Length; n++)
\r
65 if (Char.IsLetterOrDigit (url[n]) || url[n] == '_') sb.Append (url[n]);
\r
67 return sb.ToString ();
\r
70 public abstract object ReadDocument (Stream stream);
\r
72 public void Resolve ()
\r
74 if (clientProtocol == null)
\r
75 throw new InvalidOperationException ("The ClientProtocol property is a null reference");
\r
77 if (clientProtocol.Documents.Contains (Url)) // Already resolved
\r
80 string contentType = null;
\r
82 Stream stream = clientProtocol.Download (ref url, ref contentType);
\r
83 Resolve (contentType, stream);
\r
86 protected internal abstract void Resolve (string contentType, Stream stream);
\r
88 public abstract void WriteDocument (object document, Stream stream);
\r
90 #endregion // Methods
\r