This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / ServiceDescriptionImporter.cs
1 // \r
2 // System.Web.Services.Description.ServiceDescriptionImporter.cs\r
3 //\r
4 // Author:\r
5 //   Tim Coleman (tim@timcoleman.com)\r
6 //   Lluis Sanchez Gual (lluis@ximian.com)\r
7 //\r
8 // Copyright (C) Tim Coleman, 2002\r
9 //\r
10
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31 \r
32 using System;\r
33 using System.CodeDom;\r
34 using System.Web.Services;\r
35 using System.Web.Services.Protocols;\r
36 using System.Web.Services.Description;\r
37 using System.Xml.Serialization;\r
38 using System.Xml;\r
39 using System.Collections;\r
40 using System.Configuration;\r
41 \r
42 namespace System.Web.Services.Description {\r
43         public class ServiceDescriptionImporter {\r
44 \r
45                 #region Fields\r
46 \r
47                 string protocolName;\r
48                 XmlSchemas schemas;\r
49                 ServiceDescriptionCollection serviceDescriptions;\r
50                 ServiceDescriptionImportStyle style;\r
51 \r
52                 ArrayList importInfo = new ArrayList ();\r
53                 \r
54 \r
55                 #endregion // Fields\r
56 \r
57                 #region Constructors\r
58         \r
59                 public ServiceDescriptionImporter ()\r
60                 {\r
61                         protocolName = String.Empty;\r
62                         schemas = new XmlSchemas ();\r
63                         serviceDescriptions = new ServiceDescriptionCollection ();\r
64                         style = ServiceDescriptionImportStyle.Client;\r
65                 }\r
66                 \r
67                 #endregion // Constructors\r
68 \r
69                 #region Properties\r
70 \r
71                 public string ProtocolName {\r
72                         get { return protocolName; }\r
73                         set { protocolName = value; }\r
74                 }\r
75 \r
76                 public XmlSchemas Schemas {\r
77                         get { return schemas; }\r
78                 }\r
79 \r
80                 public ServiceDescriptionCollection ServiceDescriptions {\r
81                         get { return serviceDescriptions; }\r
82                 }\r
83 \r
84                 public ServiceDescriptionImportStyle Style {\r
85                         get { return style; }\r
86                         set { style = value; }\r
87                 }\r
88         \r
89                 #endregion // Properties\r
90 \r
91                 #region Methods\r
92 \r
93                 public void AddServiceDescription (ServiceDescription serviceDescription, string appSettingUrlKey, string appSettingBaseUrl)\r
94                 {\r
95                         if (appSettingUrlKey != null && appSettingUrlKey == string.Empty && style == ServiceDescriptionImportStyle.Server)\r
96                                 throw new InvalidOperationException ("Cannot set appSettingUrlKey if Style is Server");\r
97 \r
98                         ImportInfo info = new ImportInfo ();\r
99                         info.ServiceDescription = serviceDescription;\r
100                         info.AppSettingUrlKey = appSettingUrlKey;\r
101                         info.AppSettingBaseUrl = appSettingBaseUrl;\r
102                         importInfo.Add (info);\r
103                         serviceDescriptions.Add (serviceDescription);\r
104                         \r
105                         if (serviceDescription.Types != null)\r
106                                 schemas.Add (serviceDescription.Types.Schemas);\r
107                 }\r
108 \r
109                 public ServiceDescriptionImportWarnings Import (CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit)\r
110                 {\r
111                         ProtocolImporter importer = GetImporter ();\r
112                         \r
113                         if (!importer.Import (this, codeNamespace, codeCompileUnit, importInfo))\r
114                                 throw new Exception ("None of the supported bindings was found");\r
115                                 \r
116                         return importer.Warnings;\r
117                 }\r
118                 \r
119                 ProtocolImporter GetImporter ()\r
120                 {\r
121                         ArrayList importers = GetSupportedImporters ();\r
122                         if (protocolName == null || protocolName == "") protocolName = "Soap";\r
123                         foreach (ProtocolImporter importer in importers) {\r
124                                 if (importer.ProtocolName == protocolName)\r
125                                         return importer;\r
126                         }\r
127                         \r
128                         throw new Exception ("Protocol " + protocolName + " not supported");\r
129                 }\r
130                 \r
131                 ArrayList GetSupportedImporters ()\r
132                 {\r
133                         ArrayList list = new ArrayList ();\r
134                         list.Add (new SoapProtocolImporter ());\r
135                         list.Add (new HttpGetProtocolImporter ());\r
136                         list.Add (new HttpPostProtocolImporter ());\r
137                         return list;\r
138                 }\r
139                 \r
140 #endregion\r
141         }\r
142 \r
143         internal class ImportInfo\r
144         {\r
145                 public ServiceDescription ServiceDescription;\r
146                 public string AppSettingUrlKey;\r
147                 public string AppSettingBaseUrl;\r
148         }\r
149 \r
150 }