[sgen] Make sure we don't sweep a block if we're not supposed to
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Channels / MessageVersion.cs
1 //
2 // System.ServiceModel.MessageVersion.cs
3 //
4 // Author: Duncan Mak (duncan@novell.com)
5 //
6 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining
9 // a copy of this software and associated documentation files (the
10 // "Software"), to deal in the Software without restriction, including
11 // without limitation the rights to use, copy, modify, merge, publish,
12 // distribute, sublicense, and/or sell copies of the Software, and to
13 // permit persons to whom the Software is furnished to do so, subject to
14 // the following conditions:
15 // 
16 // The above copyright notice and this permission notice shall be
17 // included in all copies or substantial portions of the Software.
18 // 
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 //
27
28 using System;
29 using System.ServiceModel;
30
31 namespace System.ServiceModel.Channels {
32
33         public sealed class MessageVersion
34         {
35                 EnvelopeVersion envelope;
36                 AddressingVersion addressing;
37
38                 static MessageVersion ()
39                 {
40                         None = new MessageVersion (EnvelopeVersion.None, AddressingVersion.None);
41                         Soap11 = new MessageVersion (EnvelopeVersion.Soap11, AddressingVersion.None);
42                         Soap12WSAddressing10 = new MessageVersion  (EnvelopeVersion.Soap12, AddressingVersion.WSAddressing10);
43
44                         Soap12 = new MessageVersion (EnvelopeVersion.Soap12, AddressingVersion.None);
45                         Soap11WSAddressing10 = new MessageVersion (EnvelopeVersion.Soap11, AddressingVersion.WSAddressing10);
46                         Soap11WSAddressingAugust2004 = new MessageVersion (EnvelopeVersion.Soap11, AddressingVersion.WSAddressingAugust2004);
47                         Soap12WSAddressingAugust2004 = new MessageVersion (EnvelopeVersion.Soap12, AddressingVersion.WSAddressingAugust2004);
48                 }
49
50                 MessageVersion (EnvelopeVersion envelope, AddressingVersion addressing)
51                 {
52                         this.envelope = envelope;
53                         this.addressing = addressing;
54                 }
55                 
56                 public static MessageVersion CreateVersion (EnvelopeVersion envelope_version)
57                 {
58                         return CreateVersion (envelope_version,
59                                 AddressingVersion.WSAddressing10);
60                 }
61
62                 public static MessageVersion CreateVersion (EnvelopeVersion envelope_version,
63                                                             AddressingVersion addressing_version)
64                 {
65                         if (envelope_version == EnvelopeVersion.None && addressing_version == AddressingVersion.None)
66                                 return None;
67                         if (envelope_version == EnvelopeVersion.Soap11 && addressing_version == AddressingVersion.None)
68                                 return Soap11;
69                         if (envelope_version == EnvelopeVersion.Soap12 && addressing_version == AddressingVersion.WSAddressing10)
70                                 return Soap12WSAddressing10;
71
72                         if (envelope_version == EnvelopeVersion.Soap12 && addressing_version == AddressingVersion.None)
73                                 return Soap12;
74                         if (envelope_version == EnvelopeVersion.Soap11 && addressing_version == AddressingVersion.WSAddressing10)
75                                 return Soap11WSAddressing10;
76                         if (envelope_version == EnvelopeVersion.Soap11 && addressing_version == AddressingVersion.WSAddressingAugust2004)
77                                 return Soap11WSAddressingAugust2004;
78                         if (envelope_version == EnvelopeVersion.Soap12 && addressing_version == AddressingVersion.WSAddressingAugust2004)
79                                 return Soap12WSAddressingAugust2004;
80                         throw new ArgumentException (string.Format ("EnvelopeVersion {0} cannot be used with AddressingVersion {1}", envelope_version, addressing_version));
81                 }
82
83                 public override bool Equals (object value)
84                 {
85                         MessageVersion other = value as MessageVersion;
86
87                         if (other == null)
88                                 return false;
89
90                         return (other.Addressing == this.Addressing) && (other.Envelope == this.Envelope);
91                 }
92
93                 public override int GetHashCode ()
94                 {
95                         return addressing.GetHashCode () + envelope.GetHashCode ();
96                 }
97
98                 public override string ToString ()
99                 {
100                         return envelope.ToString () + " " +  addressing.ToString ();
101                 }
102
103                 public AddressingVersion Addressing { 
104                         get { return addressing; }
105                 }
106
107                 public static MessageVersion Default { 
108                         get { return CreateVersion (EnvelopeVersion.Soap12); }
109                 }
110
111                 public EnvelopeVersion Envelope {
112                         get { return envelope; }
113                 }
114
115                 public static MessageVersion None { 
116                         get; private set;
117                 }
118
119                 public static MessageVersion Soap11 {
120                         get; private set;
121                 }
122
123                 public static MessageVersion Soap12WSAddressing10 {
124                         get; private set;
125                 }
126
127                 public static MessageVersion Soap12 {
128                         get; private set;
129                 }
130
131                 public static MessageVersion Soap11WSAddressing10 {
132                         get; private set;
133                 }
134
135                 public static MessageVersion Soap11WSAddressingAugust2004 {
136                         get; private set;
137                 }
138
139                 public static MessageVersion Soap12WSAddressingAugust2004 {
140                         get; private set;
141                 }
142         }
143 }