2 // (C) 2006 Mainsoft Corporation (http://www.mainsoft.com)
\r
3 // Author: Konstantin Triger <kostat@mainsoft.com>
\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
15 // The above copyright notice and this permission notice shall be
\r
16 // included in all copies or substantial portions of the Software.
\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
28 using System.Collections;
\r
29 using System.Collections.Generic;
\r
31 using System.Web.SessionState;
\r
33 using System.Threading;
\r
35 using javax.servlet;
\r
36 using javax.servlet.http;
\r
37 using System.Diagnostics;
\r
38 using Mainsoft.Web.Hosting;
\r
40 namespace Mainsoft.Web.SessionState
\r
43 /// <para>This class supports the Framework infrastructure and is not intended to be used directly from your code.</para>
\r
45 public sealed partial class ServletSessionStateStoreProvider
\r
47 sealed class ServletSessionStateItemCollection : ISessionStateItemCollection, java.io.Externalizable
\r
49 SessionStateItemCollection _items;
\r
50 HttpStaticObjectsCollection _staticObjects;
\r
51 bool _needSessionPersistence;
\r
53 public ServletSessionStateItemCollection () {} // For Java deserialization
\r
55 public ServletSessionStateItemCollection (HttpContext context)
\r
58 _items = new SessionStateItemCollection ();
\r
59 _staticObjects = new HttpStaticObjectsCollection ();
\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
66 _needSessionPersistence = Boolean.Parse (sessionPersistance);
\r
69 _needSessionPersistence = false;
\r
70 Debug.WriteLine ("EnableSessionPersistency init param's value is invalid. the value is " + sessionPersistance);
\r
76 public HttpStaticObjectsCollection StaticObjects {
\r
77 get { return _staticObjects; }
\r
79 #region ISessionStateItemCollection Members
\r
81 public void Clear () {
\r
87 return _items.Dirty;
\r
90 _items.Dirty = value;
\r
94 public System.Collections.Specialized.NameObjectCollectionBase.KeysCollection Keys {
\r
95 get { return _items.Keys; }
\r
98 public void Remove (string name) {
\r
99 _items.Remove (name);
\r
102 public void RemoveAt (int index) {
\r
103 _items.RemoveAt (index);
\r
106 public object this [int index] {
\r
108 return _items [index];
\r
111 _items [index] = value;
\r
115 public object this [string name] {
\r
117 return _items [name];
\r
120 _items [name] = value;
\r
126 #region ICollection Members
\r
128 public void CopyTo (Array array, int index) {
\r
129 ((ICollection) _items).CopyTo (array, index);
\r
133 get { return ((ICollection) _items).Count; }
\r
136 public bool IsSynchronized {
\r
137 get { return ((ICollection) _items).IsSynchronized; }
\r
140 public object SyncRoot {
\r
141 get { return ((ICollection) _items).SyncRoot; }
\r
146 #region IEnumerable Members
\r
148 public System.Collections.IEnumerator GetEnumerator () {
\r
149 return ((IEnumerable) _items).GetEnumerator ();
\r
154 #region Externalizable Members
\r
156 public void readExternal (java.io.ObjectInput input) {
\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
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
174 public void writeExternal (java.io.ObjectOutput output) {
\r
176 output.writeBoolean (_needSessionPersistence);
\r
177 if (!_needSessionPersistence)
\r
178 //indicates that there is nothing to serialize for this object
\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