* Mono.Posix.dll.sources: Rename Mono.Posix to Mono.Unix.
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / OperationMessageCollection.cs
index 3e13e51f0f0e4db9f0d5a24ed032942d78e10ca5..cac974c12b25b8cf64a567c883b442db6d128d97 100644 (file)
@@ -6,23 +6,38 @@
 //\r
 // Copyright (C) Tim Coleman, 2002\r
 //\r
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 \r
 using System.Web.Services;\r
 \r
 namespace System.Web.Services.Description {\r
        public sealed class OperationMessageCollection : ServiceDescriptionBaseCollection {\r
 \r
-               #region Fields\r
-\r
-               Operation operation;\r
-\r
-               #endregion // Fields\r
-\r
                #region Constructors\r
 \r
                internal OperationMessageCollection (Operation operation)\r
+                       : base (operation)\r
                {\r
-                       this.operation = operation; \r
                }\r
 \r
                #endregion // Constructors\r
@@ -30,13 +45,30 @@ namespace System.Web.Services.Description {
                #region Properties\r
 \r
                public OperationFlow Flow {\r
-                       [MonoTODO]\r
-                       get { throw new NotImplementedException (); }\r
+                       get { \r
+                               switch (Count) {\r
+                               case 1: \r
+                                       if (this[0] is OperationInput)\r
+                                               return OperationFlow.OneWay;\r
+                                       else\r
+                                               return OperationFlow.Notification;\r
+                               case 2:\r
+                                       if (this[0] is OperationInput)\r
+                                               return OperationFlow.RequestResponse;\r
+                                       else\r
+                                               return OperationFlow.SolicitResponse;\r
+                               }\r
+                               return OperationFlow.None;\r
+                       }\r
                }\r
 \r
                public OperationInput Input {\r
-                       [MonoTODO]\r
-                       get { throw new NotImplementedException (); }\r
+                       get { \r
+                               foreach (object message in List)\r
+                                       if (message is OperationInput)\r
+                                               return (OperationInput) message;\r
+                               return null;\r
+                       }\r
                }\r
        \r
                public OperationMessage this [int index] {\r
@@ -45,14 +77,34 @@ namespace System.Web.Services.Description {
                }\r
 \r
                public OperationOutput Output {\r
-                       [MonoTODO]\r
-                       set { throw new NotImplementedException (); }\r
+                       get { \r
+                               foreach (object message in List)\r
+                                       if (message is OperationOutput)\r
+                                               return (OperationOutput) message;\r
+                               return null;\r
+                       }\r
+               }\r
+\r
+               internal OperationFault Fault {\r
+                       get { \r
+                               foreach (object message in List)\r
+                                       if (message is OperationFault)\r
+                                               return (OperationFault) message;\r
+                               return null;\r
+                       }\r
                }\r
 \r
                #endregion // Properties\r
 \r
                #region Methods\r
 \r
+               protected override string GetKey (object value) \r
+               {\r
+                       if (!(value is OperationMessage))\r
+                               throw new InvalidCastException ();\r
+                       return ((OperationMessage) value).Name;\r
+               }\r
+\r
                public int Add (OperationMessage operationMessage) \r
                {\r
                        Insert (Count, operationMessage);\r
@@ -76,29 +128,36 @@ namespace System.Web.Services.Description {
 \r
                public void Insert (int index, OperationMessage operationMessage)\r
                {\r
-                       SetParent (operationMessage, operation);\r
                        List.Insert (index, operationMessage);\r
                }\r
 \r
-               [MonoTODO]\r
                protected override void OnInsert (int index, object value)\r
                {\r
-                       throw new NotImplementedException ();\r
+                       if (Count == 0)\r
+                               return;\r
+                       \r
+                       if (Count == 1 && value.GetType() != this[0].GetType())\r
+                               return;\r
+\r
+                               throw new InvalidOperationException ("The operation object can only contain one input and one output message.");\r
                }\r
 \r
-               [MonoTODO]\r
                protected override void OnSet (int index, object oldValue, object newValue)\r
                {\r
-                       throw new NotImplementedException ();\r
+                       if (oldValue.GetType () != newValue.GetType ())\r
+                               throw new InvalidOperationException ("The message types of the old and new value are not the same.");\r
+                       base.OnSet (index, oldValue, newValue);\r
                }\r
 \r
-               [MonoTODO]\r
                protected override void OnValidate (object value)\r
                {\r
-                       throw new NotImplementedException ();\r
+                       if (value == null)\r
+                               throw new ArgumentException("The message object is a null reference.");\r
+                       if (!(value is OperationInput || value is OperationOutput))\r
+                               throw new ArgumentException ("The message object is not an input or an output message.");\r
                }\r
        \r
-               public void Remove (Operation operationMessage)\r
+               public void Remove (OperationMessage operationMessage)\r
                {\r
                        List.Remove (operationMessage);\r
                }\r