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