This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[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                 #endregion // Properties\r
89 \r
90                 #region Methods\r
91 \r
92                 protected override string GetKey (object value) \r
93                 {\r
94                         if (!(value is OperationMessage))\r
95                                 throw new InvalidCastException ();\r
96                         return ((OperationMessage) value).Name;\r
97                 }\r
98 \r
99                 public int Add (OperationMessage operationMessage) \r
100                 {\r
101                         Insert (Count, operationMessage);\r
102                         return (Count - 1);\r
103                 }\r
104 \r
105                 public bool Contains (OperationMessage operationMessage)\r
106                 {\r
107                         return List.Contains (operationMessage);\r
108                 }\r
109 \r
110                 public void CopyTo (OperationMessage[] array, int index) \r
111                 {\r
112                         List.CopyTo (array, index);\r
113                 }\r
114 \r
115                 public int IndexOf (OperationMessage operationMessage)\r
116                 {\r
117                         return List.IndexOf (operationMessage);\r
118                 }\r
119 \r
120                 public void Insert (int index, OperationMessage operationMessage)\r
121                 {\r
122                         List.Insert (index, operationMessage);\r
123                 }\r
124 \r
125                 protected override void OnInsert (int index, object value)\r
126                 {\r
127                         if (Count == 0)\r
128                                 return;\r
129                         \r
130                         if (Count == 1 && value.GetType() != this[0].GetType())\r
131                                 return;\r
132 \r
133                                 throw new InvalidOperationException ("The operation object can only contain one input and one output message.");\r
134                 }\r
135 \r
136                 protected override void OnSet (int index, object oldValue, object newValue)\r
137                 {\r
138                         if (oldValue.GetType () != newValue.GetType ())\r
139                                 throw new InvalidOperationException ("The message types of the old and new value are not the same.");\r
140                         base.OnSet (index, oldValue, newValue);\r
141                 }\r
142 \r
143                 protected override void OnValidate (object value)\r
144                 {\r
145                         if (value == null)\r
146                                 throw new ArgumentException("The message object is a null reference.");\r
147                         if (!(value is OperationInput || value is OperationOutput))\r
148                                 throw new ArgumentException ("The message object is not an input or an output message.");\r
149                 }\r
150         \r
151                 public void Remove (OperationMessage operationMessage)\r
152                 {\r
153                         List.Remove (operationMessage);\r
154                 }\r
155 \r
156                 protected override void SetParent (object value, object parent)\r
157                 {\r
158                         ((OperationMessage) value).SetParent ((Operation) parent);\r
159                 }\r
160                         \r
161                 #endregion // Methods\r
162         }\r
163 }\r