2003-10-04 Sebastien Pouliot <spouliot@videotron.ca>
[mono.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services / SoapContext.cs
1 //
2 // SoapContext.cs: SOAP Context
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
9
10 using Microsoft.Web.Services.Dime;
11 using Microsoft.Web.Services.Referral;
12 using Microsoft.Web.Services.Routing;
13 using Microsoft.Web.Services.Security;
14 using Microsoft.Web.Services.Timestamp;
15 #if !WSE1
16 using Microsoft.Web.Services.Addressing;
17 #endif
18
19 using System;
20 using System.Collections;
21
22 namespace Microsoft.Web.Services {
23
24         public sealed class SoapContext {
25
26                 private SoapEnvelope envelope;
27                 private Uri actor;
28                 private Microsoft.Web.Services.Timestamp.Timestamp timestamp;
29                 private Microsoft.Web.Services.Security.Security security;
30                 private Hashtable table;
31                 private DimeAttachmentCollection attachments;
32                 private string contentType;
33                 private SecurityCollection extendedSecurity;
34                 private ReferralCollection referrals;
35 #if !WSE1
36                 private AddressingHeaders addressingHeaders;
37 #endif
38                 internal SoapContext () 
39                 {
40                         timestamp = new Microsoft.Web.Services.Timestamp.Timestamp ();
41                         table = new Hashtable ();
42                 }
43
44                 internal SoapContext (SoapEnvelope env) 
45                 {
46                         envelope = env;
47                         timestamp = new Microsoft.Web.Services.Timestamp.Timestamp ();
48                         table = new Hashtable ();
49                 }
50 #if !WSE1
51                 public Action Action {
52                         get { return addressingHeaders.Action; }
53                         set { addressingHeaders.Action = value; }
54                 }
55
56                 public ReplyTo ReplyTo {
57                         get { return addressingHeaders.ReplyTo; }
58                         set { addressingHeaders.ReplyTo = value; }
59                 }
60          
61                 public To To {
62                         get { return addressingHeaders.To; }
63                 }
64 #endif
65                 public Uri Actor { 
66                         get { return actor; }
67                 }
68
69                 public DimeAttachmentCollection Attachments { 
70                         get { 
71                                 if (attachments == null)
72                                         attachments = new DimeAttachmentCollection ();
73                                 return attachments; 
74                         }
75                 }
76
77                 public string ContentType { 
78                         get { return contentType; }
79                 }
80
81                 public SoapEnvelope Envelope { 
82                         get { return envelope; }
83                 }
84
85                 public SecurityCollection ExtendedSecurity {
86                         get { return extendedSecurity; }
87                 }
88
89                 public object this [string key] { 
90                         get { return table [key]; }
91                         set { 
92                                 if (key == null)
93                                         throw new ArgumentNullException ("key");
94                                 table [key] = value;
95                         } 
96                 }
97
98                 public Path Path { 
99                         get { return null; }
100                         set {;} 
101                 }
102
103                 public ReferralCollection Referrals { 
104                         get { return referrals; }
105                 }
106
107                 public Microsoft.Web.Services.Security.Security Security { 
108                         get { 
109                                 if (security == null) {
110                                         if (actor != null)
111                                                 security = new Microsoft.Web.Services.Security.Security (actor.ToString ());
112                                         else
113                                                 security = new Microsoft.Web.Services.Security.Security ();
114                                 }
115                                 return security; 
116                         }
117                 }
118
119                 public Microsoft.Web.Services.Timestamp.Timestamp Timestamp { 
120                         get { return timestamp; }
121                 }
122
123                 internal bool IsReserved (string key) 
124                 {
125                         switch (key) {
126                                 case "Actor":
127                                 case "Attachments":
128                                 case "ContentType":
129                                 case "Envelope":
130                                 case "ExtendedSecurity":
131                                 case "IsInbound":
132                                 case "IsIntermediary":
133                                 case "Referrals":
134                                 case "Path":
135                                 case "Security":
136                                 case "Timestamp":
137                                 case "WebRequest":
138                                 case "WebResponse":
139                                         return true;
140                                 default:
141                                         return false;
142                         }
143                 }
144
145                 public void Add (string key, object value) 
146                 {
147                         if (key == null)
148                                 throw new ArgumentNullException ("key");
149                         if (IsReserved (key))
150                                 throw new ArgumentException ("reserved key");
151                         table.Add (key, value);
152                 }
153
154                 public void Clear () 
155                 {
156                         foreach (DictionaryEntry entry in table) {
157                                 string key = (string) entry.Key;
158                                 // remove all except reserved names
159                                 if (!IsReserved (key))
160                                         table.Remove (key);
161                         }
162                 }
163
164                 public bool Contains (string key) 
165                 {
166                         if (key == null)
167                                 throw new ArgumentNullException ("key");
168                         return table.Contains (key);
169                 }
170
171                 public void CopyTo (SoapContext context) 
172                 {
173                         if (context == null)
174                                 throw new ArgumentNullException ("context");
175                         context.actor = this.actor;
176                         foreach (DimeAttachment da in Attachments) {
177                                 context.Attachments.Add (da);
178                         }
179                         context.contentType = contentType;
180                         context.envelope = envelope;
181                         context.extendedSecurity = ExtendedSecurity;
182                         context.Path = Path;
183                         context.referrals = Referrals;
184                         context.security = security;
185                         context.timestamp = timestamp;
186                         foreach (DictionaryEntry de in table) {
187                                 context.table.Add (de.Key, de.Value);
188                         }
189                 }
190
191                 public IDictionaryEnumerator GetEnumerator () 
192                 {
193                         return table.GetEnumerator ();
194                 }
195
196                 public void Remove (string key) 
197                 {
198                         if (key == null)
199                                 throw new ArgumentNullException ("key");
200                         if (IsReserved (key))
201                                 throw new ArgumentException ("reserved key");
202                         table.Remove (key);
203                 }
204         }
205 }