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