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