Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / OperationMessageCollection.cs
1 // 
2 // System.Web.Services.Description.OperationMessageCollection.cs
3 //
4 // Author:
5 //   Tim Coleman (tim@timcoleman.com)
6 //
7 // Copyright (C) Tim Coleman, 2002
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Web.Services;
32
33 namespace System.Web.Services.Description {
34         public sealed class OperationMessageCollection : ServiceDescriptionBaseCollection {
35
36                 #region Constructors
37
38                 internal OperationMessageCollection (Operation operation)
39                         : base (operation)
40                 {
41                 }
42
43                 #endregion // Constructors
44
45                 #region Properties
46
47                 public OperationFlow Flow {
48                         get { 
49                                 switch (Count) {
50                                 case 1: 
51                                         if (this[0] is OperationInput)
52                                                 return OperationFlow.OneWay;
53                                         else
54                                                 return OperationFlow.Notification;
55                                 case 2:
56                                         if (this[0] is OperationInput)
57                                                 return OperationFlow.RequestResponse;
58                                         else
59                                                 return OperationFlow.SolicitResponse;
60                                 }
61                                 return OperationFlow.None;
62                         }
63                 }
64
65                 public OperationInput Input {
66                         get { 
67                                 foreach (object message in List)
68                                         if (message is OperationInput)
69                                                 return (OperationInput) message;
70                                 return null;
71                         }
72                 }
73         
74                 public OperationMessage this [int index] {
75                         get { return (OperationMessage) List[index]; }
76                         set { List[index] = value; }
77                 }
78
79                 public OperationOutput Output {
80                         get { 
81                                 foreach (object message in List)
82                                         if (message is OperationOutput)
83                                                 return (OperationOutput) message;
84                                 return null;
85                         }
86                 }
87
88                 internal OperationFault Fault {
89                         get { 
90                                 foreach (object message in List)
91                                         if (message is OperationFault)
92                                                 return (OperationFault) message;
93                                 return null;
94                         }
95                 }
96
97                 #endregion // Properties
98
99                 #region Methods
100
101                 public int Add (OperationMessage operationMessage) 
102                 {
103                         Insert (Count, operationMessage);
104                         return (Count - 1);
105                 }
106
107                 public bool Contains (OperationMessage operationMessage)
108                 {
109                         return List.Contains (operationMessage);
110                 }
111
112                 public void CopyTo (OperationMessage[] array, int index) 
113                 {
114                         List.CopyTo (array, index);
115                 }
116
117                 internal OperationMessage Find (string name)
118                 {
119                         foreach (OperationMessage m in List)
120                                 if (m.Name == name)
121                                         return m;
122                         return null;
123                 }
124
125                 public int IndexOf (OperationMessage operationMessage)
126                 {
127                         return List.IndexOf (operationMessage);
128                 }
129
130                 public void Insert (int index, OperationMessage operationMessage)
131                 {
132                         List.Insert (index, operationMessage);
133                 }
134
135                 protected override void OnInsert (int index, object value)
136                 {
137                         if (Count == 0)
138                                 return;
139                         
140                         if (Count == 1 && value.GetType() != this[0].GetType())
141                                 return;
142
143                                 throw new InvalidOperationException ("The operation object can only contain one input and one output message.");
144                 }
145
146                 protected override void OnSet (int index, object oldValue, object newValue)
147                 {
148                         if (oldValue.GetType () != newValue.GetType ())
149                                 throw new InvalidOperationException ("The message types of the old and new value are not the same.");
150                         base.OnSet (index, oldValue, newValue);
151                 }
152
153                 protected override void OnValidate (object value)
154                 {
155                         if (value == null)
156                                 throw new ArgumentException("The message object is a null reference.");
157                         if (!(value is OperationInput || value is OperationOutput))
158                                 throw new ArgumentException ("The message object is not an input or an output message.");
159                 }
160         
161                 public void Remove (OperationMessage operationMessage)
162                 {
163                         List.Remove (operationMessage);
164                 }
165
166                 protected override void SetParent (object value, object parent)
167                 {
168                         ((OperationMessage) value).SetParent ((Operation) parent);
169                 }
170                         
171                 #endregion // Methods
172         }
173 }