* ConformanceChecker.cs, BasicProfileChecker.cs: New files that implement
[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.CodeDom.Compiler;\r
35 using System.Web.Services;\r
36 using System.Web.Services.Protocols;\r
37 using System.Web.Services.Description;\r
38 using System.Xml.Serialization;\r
39 using System.Xml;\r
40 using System.Collections;\r
41 using System.Collections.Specialized;\r
42 using System.Configuration;\r
43 \r
44 namespace System.Web.Services.Description {\r
45         public class ServiceDescriptionImporter {\r
46 \r
47                 #region Fields\r
48 \r
49                 string protocolName;\r
50                 XmlSchemas schemas;\r
51                 ServiceDescriptionCollection serviceDescriptions;\r
52                 ServiceDescriptionImportStyle style;\r
53 \r
54                 ArrayList importInfo = new ArrayList ();\r
55                 \r
56 \r
57                 #endregion // Fields\r
58 \r
59                 #region Constructors\r
60         \r
61                 public ServiceDescriptionImporter ()\r
62                 {\r
63                         protocolName = String.Empty;\r
64                         schemas = new XmlSchemas ();\r
65                         serviceDescriptions = new ServiceDescriptionCollection ();\r
66                         style = ServiceDescriptionImportStyle.Client;\r
67                 }\r
68                 \r
69                 #endregion // Constructors\r
70 \r
71                 #region Properties\r
72 \r
73                 public string ProtocolName {\r
74                         get { return protocolName; }\r
75                         set { protocolName = value; }\r
76                 }\r
77 \r
78                 public XmlSchemas Schemas {\r
79                         get { return schemas; }\r
80                 }\r
81 \r
82                 public ServiceDescriptionCollection ServiceDescriptions {\r
83                         get { return serviceDescriptions; }\r
84                 }\r
85 \r
86                 public ServiceDescriptionImportStyle Style {\r
87                         get { return style; }\r
88                         set { style = value; }\r
89                 }\r
90                 \r
91 #if NET_2_0\r
92                 [MonoTODO]\r
93                 [System.Runtime.InteropServices.ComVisible(false)]\r
94                 public CodeGenerationOptions CodeGenerationOptions {\r
95                         get { throw new NotImplementedException (); }\r
96                         set { throw new NotImplementedException (); }\r
97                 }\r
98                 \r
99                 [MonoTODO]\r
100                 [System.Runtime.InteropServices.ComVisible(false)]\r
101                 public ICodeGenerator CodeGenerator {\r
102                         get { throw new NotImplementedException (); }\r
103                         set { throw new NotImplementedException (); }\r
104                 }\r
105 #endif\r
106         \r
107                 #endregion // Properties\r
108 \r
109                 #region Methods\r
110 \r
111                 public void AddServiceDescription (ServiceDescription serviceDescription, string appSettingUrlKey, string appSettingBaseUrl)\r
112                 {\r
113                         if (appSettingUrlKey != null && appSettingUrlKey == string.Empty && style == ServiceDescriptionImportStyle.Server)\r
114                                 throw new InvalidOperationException ("Cannot set appSettingUrlKey if Style is Server");\r
115 \r
116                         ImportInfo info = new ImportInfo ();\r
117                         info.ServiceDescription = serviceDescription;\r
118                         info.AppSettingUrlKey = appSettingUrlKey;\r
119                         info.AppSettingBaseUrl = appSettingBaseUrl;\r
120                         importInfo.Add (info);\r
121                         serviceDescriptions.Add (serviceDescription);\r
122                         \r
123                         if (serviceDescription.Types != null)\r
124                                 schemas.Add (serviceDescription.Types.Schemas);\r
125                 }\r
126 \r
127                 public ServiceDescriptionImportWarnings Import (CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit)\r
128                 {\r
129                         ProtocolImporter importer = GetImporter ();\r
130                         \r
131                         if (!importer.Import (this, codeNamespace, codeCompileUnit, importInfo))\r
132                                 throw new Exception ("None of the supported bindings was found");\r
133                                 \r
134                         return importer.Warnings;\r
135                 }\r
136                 \r
137                 ProtocolImporter GetImporter ()\r
138                 {\r
139                         ArrayList importers = GetSupportedImporters ();\r
140                         if (protocolName == null || protocolName == "") protocolName = "Soap";\r
141                         foreach (ProtocolImporter importer in importers) {\r
142                                 if (importer.ProtocolName == protocolName)\r
143                                         return importer;\r
144                         }\r
145                         \r
146                         throw new Exception ("Protocol " + protocolName + " not supported");\r
147                 }\r
148                 \r
149                 ArrayList GetSupportedImporters ()\r
150                 {\r
151                         ArrayList list = new ArrayList ();\r
152                         list.Add (new SoapProtocolImporter ());\r
153                         list.Add (new HttpGetProtocolImporter ());\r
154                         list.Add (new HttpPostProtocolImporter ());\r
155                         return list;\r
156                 }\r
157                 \r
158 #if NET_2_0\r
159                 [MonoTODO]\r
160                 public static StringCollection GenerateWebReferences (\r
161                         WebReferenceCollection webReferences, \r
162                         CodeGenerationOptions options, \r
163                         ServiceDescriptionImportStyle style, \r
164                         ICodeGenerator codeGenerator)\r
165                 {\r
166                         throw new NotImplementedException ();\r
167                 }\r
168 \r
169                 [MonoTODO]\r
170                 public static StringCollection GenerateWebReferences (\r
171                         WebReferenceCollection webReferences, \r
172                         CodeGenerationOptions options, \r
173                         ServiceDescriptionImportStyle style, \r
174                         ICodeGenerator codeGenerator, \r
175                         CodeCompileUnit codeCompileUnit, \r
176                         bool verbose)\r
177                 {\r
178                         throw new NotImplementedException ();\r
179                 }\r
180 #endif\r
181 \r
182 #endregion\r
183         }\r
184 \r
185         internal class ImportInfo\r
186         {\r
187                 public ServiceDescription ServiceDescription;\r
188                 public string AppSettingUrlKey;\r
189                 public string AppSettingBaseUrl;\r
190         }\r
191 \r
192 }