2008-03-12 Jb Evain <jbevain@novell.com>
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / Operation.cs
1 // 
2 // System.Web.Services.Description.Operation.cs
3 //
4 // Author:
5 //   Tim Coleman (tim@timcoleman.com)
6 //
7 // Copyright (C) Tim Coleman, 2002
8 //
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
31 using System.Collections;
32 using System.ComponentModel;
33 using System.Xml;
34 using System.Xml.Serialization;
35 using System.Web.Services.Configuration;
36
37 namespace System.Web.Services.Description 
38 {
39 #if NET_2_0
40         [XmlFormatExtensionPoint ("Extensions")]
41 #endif
42         public sealed class Operation :
43 #if NET_2_0
44                 NamedItem
45 #else
46                 DocumentableItem 
47 #endif
48         {
49                 #region Fields
50
51                 OperationFaultCollection faults;
52                 OperationMessageCollection messages;
53 #if !NET_2_0
54                 string name;
55 #endif
56                 string[] parameterOrder;
57                 PortType portType;
58 #if NET_2_0
59                 ServiceDescriptionFormatExtensionCollection extensions;
60 #endif
61
62                 #endregion // Fields
63
64                 #region Constructors
65                 
66                 public Operation ()
67                 {
68                         faults = new OperationFaultCollection (this);
69                         messages = new OperationMessageCollection (this);
70 #if !NET_2_0
71                         name = String.Empty;
72 #endif
73                         parameterOrder = null;
74                         portType = null;
75 #if NET_2_0
76                         extensions = new ServiceDescriptionFormatExtensionCollection (this);
77 #endif
78                 }
79                 
80                 #endregion // Constructors
81
82                 #region Properties
83
84                 [XmlElement ("fault")]
85                 public OperationFaultCollection Faults {
86                         get { return faults; }
87                 }
88
89                 [XmlElement ("output", typeof (OperationOutput))]
90                 [XmlElement ("input", typeof (OperationInput))]
91                 public OperationMessageCollection Messages {
92                         get { return messages; }
93                 }
94
95 #if !NET_2_0
96                 [XmlAttribute ("name", DataType = "NCName")]
97                 public string Name {
98                         get { return name; }
99                         set { name = value; }
100                 }
101 #endif
102
103                 [XmlIgnore]
104                 public string[] ParameterOrder {
105                         get { return parameterOrder; }
106                         set { parameterOrder = value; }
107                 }
108
109                 static readonly char [] wsChars = new char [] {' ', '\r', '\n', '\t'};
110
111                 [DefaultValue ("")]
112                 // LAMESPEC: it could simply use xs:NMTOKENS
113                 [XmlAttribute ("parameterOrder")]
114                 public string ParameterOrderString {
115                         get { 
116                                 if (parameterOrder == null)
117                                         return String.Empty;
118                                 return String.Join (" ", parameterOrder); 
119                         }
120                         set {
121                                 ArrayList al = new ArrayList ();
122                                 foreach (string s in value.Split (' ')) {
123                                         value = s.Trim (wsChars);
124                                         if (value.Length > 0)
125                                                 al.Add (value);
126                                 }
127                                 ParameterOrder = (string []) al.ToArray (typeof (string));
128                         }
129                 }
130
131 //              [XmlIgnore]
132                 public PortType PortType {
133                         get { return portType; }
134                 }
135
136 #if NET_2_0
137                 [XmlIgnore]
138                 public override ServiceDescriptionFormatExtensionCollection Extensions {
139                         get { return extensions; }
140                 }
141 #endif
142
143                 #endregion // Properties
144
145                 #region Methods
146
147                 public bool IsBoundBy (OperationBinding operationBinding)
148                 {
149                         return (operationBinding.Name == Name);
150                 }
151
152                 internal void SetParent (PortType portType)
153                 {
154                         this.portType = portType;
155                 }
156
157                 #endregion
158         }
159 }