Async reads no longer return -1 read byte count
[mono.git] / mcs / class / Mainsoft.Web / Mainsoft.Web.SessionState / ServletSessionStateItemCollection.cs
1 //\r
2 // (C) 2006 Mainsoft Corporation (http://www.mainsoft.com)\r
3 // Author: Konstantin Triger <kostat@mainsoft.com>\r
4 //\r
5 \r
6 //\r
7 // Permission is hereby granted, free of charge, to any person obtaining\r
8 // a copy of this software and associated documentation files (the\r
9 // "Software"), to deal in the Software without restriction, including\r
10 // without limitation the rights to use, copy, modify, merge, publish,\r
11 // distribute, sublicense, and/or sell copies of the Software, and to\r
12 // permit persons to whom the Software is furnished to do so, subject to\r
13 // the following conditions:\r
14 //\r
15 // The above copyright notice and this permission notice shall be\r
16 // included in all copies or substantial portions of the Software.\r
17 //\r
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
25 //\r
26 \r
27 using System;\r
28 using System.Collections;\r
29 using System.Collections.Generic;\r
30 using System.Text;\r
31 using System.Web.SessionState;\r
32 using System.Web;\r
33 using System.Threading;\r
34 \r
35 using javax.servlet;\r
36 using javax.servlet.http;\r
37 using System.Diagnostics;\r
38 using Mainsoft.Web.Hosting;\r
39 \r
40 namespace Mainsoft.Web.SessionState\r
41 {\r
42         /// <summary>\r
43         /// <para>This class supports the Framework infrastructure and is not intended to be used directly from your code.</para>\r
44         /// </summary>\r
45         public sealed partial class ServletSessionStateStoreProvider\r
46         {\r
47                 sealed class ServletSessionStateItemCollection : ISessionStateItemCollection, java.io.Externalizable\r
48                 {\r
49                         SessionStateItemCollection _items;\r
50                         HttpStaticObjectsCollection _staticObjects;\r
51                         bool _needSessionPersistence;\r
52 \r
53                         public ServletSessionStateItemCollection () {} // For Java deserialization\r
54 \r
55                         public ServletSessionStateItemCollection (HttpContext context)\r
56                                 : this () {\r
57 \r
58                                 _items = new SessionStateItemCollection ();\r
59                                 _staticObjects = new HttpStaticObjectsCollection ();\r
60 \r
61                                 if (context != null) {\r
62                                         ServletContext servletContext = J2EEUtils.GetWorkerRequest (context).GetContext ();\r
63                                         string sessionPersistance = servletContext.getInitParameter (J2EEConsts.Enable_Session_Persistency);\r
64                                         if (sessionPersistance != null) {\r
65                                                 try {\r
66                                                         _needSessionPersistence = Boolean.Parse (sessionPersistance);\r
67                                                 }\r
68                                                 catch (Exception) {\r
69                                                         _needSessionPersistence = false;\r
70                                                         Debug.WriteLine ("EnableSessionPersistency init param's value is invalid. the value is " + sessionPersistance);\r
71                                                 }\r
72                                         }\r
73                                 }\r
74                         }\r
75 \r
76                         public HttpStaticObjectsCollection StaticObjects {\r
77                                 get { return _staticObjects; }\r
78                         }\r
79                         #region ISessionStateItemCollection Members\r
80 \r
81                         public void Clear () {\r
82                                 _items.Clear ();\r
83                         }\r
84 \r
85                         public bool Dirty {\r
86                                 get {\r
87                                         return _items.Dirty;\r
88                                 }\r
89                                 set {\r
90                                         _items.Dirty = value;\r
91                                 }\r
92                         }\r
93 \r
94                         public System.Collections.Specialized.NameObjectCollectionBase.KeysCollection Keys {\r
95                                 get { return _items.Keys; }\r
96                         }\r
97 \r
98                         public void Remove (string name) {\r
99                                 _items.Remove (name);\r
100                         }\r
101 \r
102                         public void RemoveAt (int index) {\r
103                                 _items.RemoveAt (index);\r
104                         }\r
105 \r
106                         public object this [int index] {\r
107                                 get {\r
108                                         return _items [index];\r
109                                 }\r
110                                 set {\r
111                                         _items [index] = value;\r
112                                 }\r
113                         }\r
114 \r
115                         public object this [string name] {\r
116                                 get {\r
117                                         return _items [name];\r
118                                 }\r
119                                 set {\r
120                                         _items [name] = value;\r
121                                 }\r
122                         }\r
123 \r
124                         #endregion\r
125 \r
126                         #region ICollection Members\r
127 \r
128                         public void CopyTo (Array array, int index) {\r
129                                 ((ICollection) _items).CopyTo (array, index);\r
130                         }\r
131 \r
132                         public int Count {\r
133                                 get { return ((ICollection) _items).Count; }\r
134                         }\r
135 \r
136                         public bool IsSynchronized {\r
137                                 get { return ((ICollection) _items).IsSynchronized; }\r
138                         }\r
139 \r
140                         public object SyncRoot {\r
141                                 get { return ((ICollection) _items).SyncRoot; }\r
142                         }\r
143 \r
144                         #endregion\r
145 \r
146                         #region IEnumerable Members\r
147 \r
148                         public System.Collections.IEnumerator GetEnumerator () {\r
149                                 return ((IEnumerable) _items).GetEnumerator ();\r
150                         }\r
151 \r
152                         #endregion\r
153 \r
154                         #region Externalizable Members\r
155 \r
156                         public void readExternal (java.io.ObjectInput input) {\r
157                                 lock (this) {\r
158                                         _needSessionPersistence = input.readBoolean ();\r
159                                         if (!_needSessionPersistence) { //nothing has been written \r
160                                                 if (_items == null)\r
161                                                         _items = new SessionStateItemCollection ();\r
162                                                 if (_staticObjects == null)\r
163                                                         _staticObjects = new HttpStaticObjectsCollection ();\r
164                                                 return;\r
165                                         }\r
166 \r
167                                         ObjectInputStream ms = new ObjectInputStream (input);\r
168                                         System.IO.BinaryReader br = new System.IO.BinaryReader (ms);\r
169                                         _items = SessionStateItemCollection.Deserialize (br);\r
170                                         _staticObjects = HttpStaticObjectsCollection.Deserialize (br);\r
171                                 }\r
172                         }\r
173 \r
174                         public void writeExternal (java.io.ObjectOutput output) {\r
175                                 lock (this) {\r
176                                         output.writeBoolean (_needSessionPersistence);\r
177                                         if (!_needSessionPersistence)\r
178                                                 //indicates that there is nothing to serialize for this object\r
179                                                 return;\r
180 \r
181                                         ObjectOutputStream ms = new ObjectOutputStream (output);\r
182                                         System.IO.BinaryWriter bw = new System.IO.BinaryWriter (ms);\r
183                                         _items.Serialize (bw);\r
184                                         _staticObjects.Serialize (bw);\r
185                                 }\r
186                         }\r
187 \r
188                         #endregion\r
189                 }\r
190         }\r
191 }\r