New test.
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / ServiceDescriptionCollection.cs
1 // \r
2 // System.Web.Services.Description.ServiceDescriptionCollection.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.Web.Services;\r
33 using System.Xml;\r
34 \r
35 namespace System.Web.Services.Description {\r
36         public sealed class ServiceDescriptionCollection : ServiceDescriptionBaseCollection {\r
37
38 #if !TARGET_JVM //code generation is not supported
39                 ServiceDescriptionImporter importer;
40 #endif
41                 \r
42                 #region Constructors\r
43         \r
44                 public ServiceDescriptionCollection () \r
45                         : base (null)\r
46                 {\r
47                 }\r
48 \r
49                 #endregion // Constructors\r
50 \r
51                 #region Properties\r
52 \r
53                 public ServiceDescription this [int index] {\r
54                         get { \r
55                                 if (index < 0 || index > Count)\r
56                                         throw new ArgumentOutOfRangeException ();\r
57 \r
58                                 return (ServiceDescription) List[index]; \r
59                         }\r
60                         set { List [index] = value; }\r
61                 }\r
62 \r
63                 public ServiceDescription this [string ns] {\r
64                         get { \r
65                                 return (ServiceDescription) Table[ns];\r
66                         }\r
67                 }\r
68 \r
69                 #endregion // Properties\r
70 \r
71                 #region Methods\r
72 #if !TARGET_JVM //code generation is not supported
73                 internal void SetImporter (ServiceDescriptionImporter i)
74                 {
75                         importer = i;
76                 }\r
77 #endif\r
78                 public int Add (ServiceDescription serviceDescription) \r
79                 {\r
80                         return Add (serviceDescription, null, null);\r
81                 }\r
82 \r
83                 internal int Add (ServiceDescription serviceDescription, string appSettingUrlKey, string appSettingBaseUrl)\r
84                 {
85 #if !TARGET_JVM
86                         if (importer != null)\r
87                                 importer.OnServiceDescriptionAdded (serviceDescription, appSettingUrlKey, appSettingBaseUrl);
88 #endif
89                         Insert (Count, serviceDescription);
90                         return (Count - 1);\r
91                 }
92                 \r
93                 public bool Contains (ServiceDescription serviceDescription)\r
94                 {\r
95                         return List.Contains (serviceDescription);\r
96                 }\r
97 \r
98                 public void CopyTo (ServiceDescription[] array, int index) \r
99                 {\r
100                         List.CopyTo (array, index);\r
101                 }\r
102 \r
103                 public Binding GetBinding (XmlQualifiedName name)\r
104                 {\r
105                         ServiceDescription desc = (ServiceDescription) Table[name.Namespace];\r
106                         if (desc != null) {\r
107                                 foreach (Binding binding in desc.Bindings) \r
108                                         if (binding.Name == name.Name)\r
109                                                 return binding;\r
110                         }\r
111                         throw new InvalidOperationException ("Binding '" + name + "' not found");\r
112                 }\r
113 \r
114                 protected override string GetKey (object value) \r
115                 {\r
116                         return ((ServiceDescription) value).TargetNamespace;\r
117                 }\r
118 \r
119                 public Message GetMessage (XmlQualifiedName name)\r
120                 {\r
121                         ServiceDescription desc = (ServiceDescription) Table[name.Namespace];\r
122                         if (desc != null) {\r
123                                 foreach (Message message in desc.Messages) \r
124                                         if (message.Name == name.Name)\r
125                                                 return message;\r
126                         }\r
127                         throw new InvalidOperationException ("Message '" + name + "' not found");\r
128                 }\r
129 \r
130                 public PortType GetPortType (XmlQualifiedName name)\r
131                 {\r
132                         ServiceDescription desc = (ServiceDescription) Table[name.Namespace];\r
133                         if (desc != null) {\r
134                                 foreach (PortType portType in desc.PortTypes) \r
135                                         if (portType.Name == name.Name)\r
136                                                 return portType;\r
137                         }\r
138                         throw new InvalidOperationException ("Port type '" + name + "' not found");\r
139                 }\r
140 \r
141                 public Service GetService (XmlQualifiedName name)\r
142                 {\r
143                         ServiceDescription desc = (ServiceDescription) Table[name.Namespace];\r
144                         if (desc != null) {\r
145                                 foreach (Service service in desc.Services) \r
146                                         if (service.Name == name.Name)\r
147                                                 return service;\r
148                         }\r
149                         throw new InvalidOperationException ("Service '" + name + "' not found");\r
150                 }\r
151 \r
152                 public int IndexOf (ServiceDescription serviceDescription)\r
153                 {\r
154                         return List.IndexOf (serviceDescription);\r
155                 }\r
156 \r
157                 public void Insert (int index, ServiceDescription serviceDescription)\r
158                 {\r
159                         List.Insert (index, serviceDescription);\r
160                 }\r
161         \r
162                 public void Remove (ServiceDescription serviceDescription)\r
163                 {\r
164                         List.Remove (serviceDescription);\r
165                 }\r
166 \r
167                 #endregion // Methods\r
168         }\r
169 }