2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[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
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 \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                 protected override string GetKey (object value) \r
102                 {\r
103                         if (!(value is OperationMessage))\r
104                                 throw new InvalidCastException ();\r
105                         return ((OperationMessage) value).Name;\r
106                 }\r
107 \r
108                 public int Add (OperationMessage operationMessage) \r
109                 {\r
110                         Insert (Count, operationMessage);\r
111                         return (Count - 1);\r
112                 }\r
113 \r
114                 public bool Contains (OperationMessage operationMessage)\r
115                 {\r
116                         return List.Contains (operationMessage);\r
117                 }\r
118 \r
119                 public void CopyTo (OperationMessage[] array, int index) \r
120                 {\r
121                         List.CopyTo (array, index);\r
122                 }\r
123 \r
124                 public int IndexOf (OperationMessage operationMessage)\r
125                 {\r
126                         return List.IndexOf (operationMessage);\r
127                 }\r
128 \r
129                 public void Insert (int index, OperationMessage operationMessage)\r
130                 {\r
131                         List.Insert (index, operationMessage);\r
132                 }\r
133 \r
134                 protected override void OnInsert (int index, object value)\r
135                 {\r
136                         if (Count == 0)\r
137                                 return;\r
138                         \r
139                         if (Count == 1 && value.GetType() != this[0].GetType())\r
140                                 return;\r
141 \r
142                                 throw new InvalidOperationException ("The operation object can only contain one input and one output message.");\r
143                 }\r
144 \r
145                 protected override void OnSet (int index, object oldValue, object newValue)\r
146                 {\r
147                         if (oldValue.GetType () != newValue.GetType ())\r
148                                 throw new InvalidOperationException ("The message types of the old and new value are not the same.");\r
149                         base.OnSet (index, oldValue, newValue);\r
150                 }\r
151 \r
152                 protected override void OnValidate (object value)\r
153                 {\r
154                         if (value == null)\r
155                                 throw new ArgumentException("The message object is a null reference.");\r
156                         if (!(value is OperationInput || value is OperationOutput))\r
157                                 throw new ArgumentException ("The message object is not an input or an output message.");\r
158                 }\r
159         \r
160                 public void Remove (OperationMessage operationMessage)\r
161                 {\r
162                         List.Remove (operationMessage);\r
163                 }\r
164 \r
165                 protected override void SetParent (object value, object parent)\r
166                 {\r
167                         ((OperationMessage) value).SetParent ((Operation) parent);\r
168                 }\r
169                         \r
170                 #endregion // Methods\r
171         }\r
172 }\r