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