002-08-19 Tim Coleman <tim@timcoleman.com>
[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 using System.Web.Services;\r
11 \r
12 namespace System.Web.Services.Description {\r
13         public sealed class OperationMessageCollection : ServiceDescriptionBaseCollection {\r
14 \r
15                 #region Constructors\r
16 \r
17                 internal OperationMessageCollection (Operation operation)\r
18                         : base (operation)\r
19                 {\r
20                 }\r
21 \r
22                 #endregion // Constructors\r
23 \r
24                 #region Properties\r
25 \r
26                 public OperationFlow Flow {\r
27                         get { \r
28                                 switch (Count) {\r
29                                 case 1: \r
30                                         if (this[0] is OperationInput)\r
31                                                 return OperationFlow.OneWay;\r
32                                         else\r
33                                                 return OperationFlow.Notification;\r
34                                 case 2:\r
35                                         if (this[0] is OperationInput)\r
36                                                 return OperationFlow.RequestResponse;\r
37                                         else\r
38                                                 return OperationFlow.SolicitResponse;\r
39                                 }\r
40                                 return OperationFlow.None;\r
41                         }\r
42                 }\r
43 \r
44                 public OperationInput Input {\r
45                         get { \r
46                                 foreach (object message in List)\r
47                                         if (message is OperationInput)\r
48                                                 return (OperationInput) message;\r
49                                 return null;\r
50                         }\r
51                 }\r
52         \r
53                 public OperationMessage this [int index] {\r
54                         get { return (OperationMessage) List[index]; }\r
55                         set { List[index] = value; }\r
56                 }\r
57 \r
58                 public OperationOutput Output {\r
59                         get { \r
60                                 foreach (object message in List)\r
61                                         if (message is OperationOutput)\r
62                                                 return (OperationOutput) message;\r
63                                 return null;\r
64                         }\r
65                 }\r
66 \r
67                 #endregion // Properties\r
68 \r
69                 #region Methods\r
70 \r
71                 public int Add (OperationMessage operationMessage) \r
72                 {\r
73                         Insert (Count, operationMessage);\r
74                         return (Count - 1);\r
75                 }\r
76 \r
77                 public bool Contains (OperationMessage operationMessage)\r
78                 {\r
79                         return List.Contains (operationMessage);\r
80                 }\r
81 \r
82                 public void CopyTo (OperationMessage[] array, int index) \r
83                 {\r
84                         List.CopyTo (array, index);\r
85                 }\r
86 \r
87                 public int IndexOf (OperationMessage operationMessage)\r
88                 {\r
89                         return List.IndexOf (operationMessage);\r
90                 }\r
91 \r
92                 public void Insert (int index, OperationMessage operationMessage)\r
93                 {\r
94                         List.Insert (index, operationMessage);\r
95                 }\r
96 \r
97                 protected override void OnInsert (int index, object value)\r
98                 {\r
99                         if (Count > 2 || value.GetType () == this [0].GetType ())\r
100                                 throw new InvalidOperationException ("The operation object can only contain one input and one output message.");\r
101                 }\r
102 \r
103                 protected override void OnSet (int index, object oldValue, object newValue)\r
104                 {\r
105                         if (oldValue.GetType () != newValue.GetType ())\r
106                                 throw new InvalidOperationException ("The message types of the old and new value are not the same.");\r
107                         base.OnSet (index, oldValue, newValue);\r
108                 }\r
109 \r
110                 protected override void OnValidate (object value)\r
111                 {\r
112                         if (value == null)\r
113                                 throw new NullReferenceException ("The message object is a null reference.");\r
114                         if (!(value is OperationInput || value is OperationOutput))\r
115                                 throw new ArgumentException ("The message object is not an input or an output message.");\r
116                 }\r
117         \r
118                 public void Remove (OperationMessage operationMessage)\r
119                 {\r
120                         List.Remove (operationMessage);\r
121                 }\r
122 \r
123                 protected override void SetParent (object value, object parent)\r
124                 {\r
125                         ((OperationMessage) value).SetParent ((Operation) parent);\r
126                 }\r
127                         \r
128                 #endregion // Methods\r
129         }\r
130 }\r