Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DiscoveryReference.cs « System.Web.Services.Discovery « System.Web.Services « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a5ab440db1913151727f4ad58c50d527231bff61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// 
// System.Web.Services.Discovery.DiscoveryReference.cs
//
// Author:
//   Dave Bettin (javabettin@yahoo.com)
//   Lluis Sanchez Gual (lluis@ximian.com)
//
// Copyright (C) Dave Bettin, 2002
//

using System.IO;
using System.Xml.Serialization;

namespace System.Web.Services.Discovery {
	public abstract class DiscoveryReference {
		
		#region Fields

		private string defaultFilename;
		private DiscoveryClientProtocol clientProtocol;

		#endregion // Fields

		#region Constructors

		protected DiscoveryReference () 
		{
		}
		
		#endregion // Constructors

		#region Properties

		[XmlIgnore]
		public DiscoveryClientProtocol ClientProtocol {
			get { return clientProtocol; }			
			set { clientProtocol = value; }
			
		}
		
		[XmlIgnore]
		public virtual string DefaultFilename {
			get { return FilenameFromUrl (Url); }			
		}
		
		[XmlIgnore]
		public abstract string Url {
			get;		
			set;
		}
		
		#endregion // Properties

		#region Methods

		protected static string FilenameFromUrl (string url)
		{
			if (url.ToLower().EndsWith ("/wsdl"))
				url = url.Substring (0,url.Length-5);
			else if (url.ToLower().EndsWith ("/soap"))
				url = url.Substring (0,url.Length-5);
			else if (url.ToLower().EndsWith ("/wsdl.jsp"))
				url = url.Substring (0,url.Length-9);
			else if (url.ToLower().EndsWith ("/soap.wsdl"))
				url = url.Substring (0,url.Length-10);
			
			int i = url.LastIndexOf ("/");
			if (i != -1) url = url.Substring (i+1);
			
			i = url.IndexOfAny (new char[] {'.','?','\\'});
			if (i != -1) url = url.Substring (0,i);
			
			System.Text.StringBuilder sb = new System.Text.StringBuilder ();
			for (int n=0; n<url.Length; n++)
				if (Char.IsLetterOrDigit (url[n]) || url[n] == '_') sb.Append (url[n]);
				
			return sb.ToString ();
		}
		
		public abstract object ReadDocument (Stream stream);
		
		public void Resolve () 
		{
			if (clientProtocol == null) 
				throw new InvalidOperationException ("The ClientProtocol property is a null reference.");
			
			if (clientProtocol.Documents.Contains (Url)) 	// Already resolved
				return;
			
			try
			{
				string contentType = null;
				string url = Url;
				Stream stream = clientProtocol.Download (ref url, ref contentType);
				Resolve (contentType, stream);
			}
			catch (Exception ex)
			{
				ReportError (Url, ex);
			}
		}
                
		protected internal abstract void Resolve (string contentType, Stream stream);
		
		public abstract void WriteDocument (object document, Stream stream);

		internal void ReportError (string url, Exception ex)
		{
			if (ex is DiscoveryException) throw ex;
			else throw new DiscoveryException (url, ex);
		}
		
		#endregion // Methods
	}
}