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
38 namespace Mainsoft.Web.SessionState
\r
40 public sealed partial class ServletSessionStateStoreProvider
\r
42 sealed class ServletSessionStateItemCollection : ISessionStateItemCollection, java.io.Externalizable
\r
44 SessionStateItemCollection _items;
\r
45 HttpStaticObjectsCollection _staticObjects;
\r
46 bool _needSessionPersistence;
\r
48 public ServletSessionStateItemCollection () {} // For Java deserialization
\r
50 public ServletSessionStateItemCollection (HttpContext context)
\r
53 _items = new SessionStateItemCollection ();
\r
54 _staticObjects = new HttpStaticObjectsCollection ();
\r
56 if (context != null) {
\r
57 ServletConfig config = ServletSessionStateStoreProvider.GetWorkerRequest (context).Servlet.getServletConfig ();
\r
58 string sessionPersistance = J2EEUtils.GetInitParameterByHierarchy(config, J2EEConsts.Enable_Session_Persistency);
\r
59 if (sessionPersistance == null)
\r
60 sessionPersistance = config.getServletContext().getInitParameter (J2EEConsts.Enable_Session_Persistency);
\r
61 if (sessionPersistance != null) {
\r
63 _needSessionPersistence = Boolean.Parse (sessionPersistance);
\r
66 _needSessionPersistence = false;
\r
68 Console.WriteLine ("EnableSessionPersistency init param's value is invalid. the value is " + sessionPersistance);
\r
75 public HttpStaticObjectsCollection StaticObjects {
\r
76 get { return _staticObjects; }
\r
78 #region ISessionStateItemCollection Members
\r
80 public void Clear () {
\r
86 return _items.Dirty;
\r
89 _items.Dirty = value;
\r
93 public System.Collections.Specialized.NameObjectCollectionBase.KeysCollection Keys {
\r
94 get { return _items.Keys; }
\r
97 public void Remove (string name) {
\r
98 _items.Remove (name);
\r
101 public void RemoveAt (int index) {
\r
102 _items.RemoveAt (index);
\r
105 public object this [int index] {
\r
107 return _items [index];
\r
110 _items [index] = value;
\r
114 public object this [string name] {
\r
116 return _items [name];
\r
119 _items [name] = value;
\r
125 #region ICollection Members
\r
127 public void CopyTo (Array array, int index) {
\r
128 ((ICollection) _items).CopyTo (array, index);
\r
132 get { return ((ICollection) _items).Count; }
\r
135 public bool IsSynchronized {
\r
136 get { return ((ICollection) _items).IsSynchronized; }
\r
139 public object SyncRoot {
\r
140 get { return ((ICollection) _items).SyncRoot; }
\r
145 #region IEnumerable Members
\r
147 public System.Collections.IEnumerator GetEnumerator () {
\r
148 return ((IEnumerable) _items).GetEnumerator ();
\r
153 #region Externalizable Members
\r
155 public void readExternal (java.io.ObjectInput input) {
\r
157 _needSessionPersistence = input.readBoolean ();
\r
158 if (!_needSessionPersistence) { //nothing has been written
\r
159 if (_items == null)
\r
160 _items = new SessionStateItemCollection ();
\r
161 if (_staticObjects == null)
\r
162 _staticObjects = new HttpStaticObjectsCollection ();
\r
166 ObjectInputStream ms = new ObjectInputStream (input);
\r
167 System.IO.BinaryReader br = new System.IO.BinaryReader (ms);
\r
168 _items = SessionStateItemCollection.Deserialize (br);
\r
169 _staticObjects = HttpStaticObjectsCollection.Deserialize (br);
\r
173 public void writeExternal (java.io.ObjectOutput output) {
\r
175 output.writeBoolean (_needSessionPersistence);
\r
176 if (!_needSessionPersistence)
\r
177 //indicates that there is nothing to serialize for this object
\r
180 ObjectOutputStream ms = new ObjectOutputStream (output);
\r
181 System.IO.BinaryWriter bw = new System.IO.BinaryWriter (ms);
\r
182 _items.Serialize (bw);
\r
183 _staticObjects.Serialize (bw);
\r