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