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