* System.Web20.csproj: added ObjectInputStream.cs and ObjectOutputStream.cs
[mono.git] / mcs / class / System.Web / System.Web.UI / Page.jvm.cs
index 3f620d957ba21003b82247a3d210b310b658f4d7..dd342bc11fa20b8ec95d8a93774cde4c12682239 100644 (file)
-//
-// System.Web.UI.Page.jvm.cs
-//
-// Authors:
-//   Eyal Alaluf (eyala@mainsoft.com)
-//
-// (C) 2006 Mainsoft Co. (http://www.mainsoft.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-// 
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-// 
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-using vmw.@internal.j2ee;
-using javax.servlet.http;
-using System.Collections.Specialized;
-using System.Globalization;
-using System.Web.Hosting;
-using System.Web.J2EE;
-using System.ComponentModel;
-
-namespace System.Web.UI
-{
-       public partial class Page
-       {
-               const string PageNamespaceKey = "__PAGENAMESPACE";
-               const string RenderPageMark = "vmw.render.page=";
-               const string ActionPageMark = "vmw.action.page=";
-               static readonly string NextActionPageKey = PortletInternalUtils.NextActionPage;
-               static readonly string NextRenderPageKey = PortletInternalUtils.NextRenderPage;
-
-               bool _emptyPortletNamespace = false;
-               string _PortletNamespace = null;
-               bool _renderResponseInit = false;
-               IPortletRenderResponse _renderResponse = null;
-
-               internal string PortletNamespace
-               {
-                       get {
-                               if (_emptyPortletNamespace)
-                                       return null;
-
-                               if (_PortletNamespace == null) {
-                                       IPortletResponse portletResponse = null;
-                                       if (Context != null) {
-                                               string usePortletNamespace = J2EEUtils.GetInitParameterByHierarchy (Context.Servlet.getServletConfig (), "mainsoft.use.portlet.namespace");
-                                               if (usePortletNamespace == null || Boolean.Parse(usePortletNamespace))
-                                                       portletResponse = Context.ServletResponse as IPortletResponse;
-                                       }
-                                       if (portletResponse != null)
-                                               _PortletNamespace = portletResponse.getNamespace ();
-                                       else if (_requestValueCollection != null && _requestValueCollection [PageNamespaceKey] != null)
-                                               _PortletNamespace = _requestValueCollection [PageNamespaceKey];
-                                               
-                                       _emptyPortletNamespace = _PortletNamespace == null;
-                               }
-                               return _PortletNamespace;
-                       }
-               }
-
-               internal string theForm {
-                       get {
-                               return "theForm" + PortletNamespace;
-                       }
-               }
-               
-               internal bool IsMultiForm {
-                       get { return IsPortletRender; }
-               }
-
-               internal bool IsPortletRender
-               {
-                       get {
-                               return RenderResponse != null;
-                       }
-               }
-
-               internal bool IsGetBack {
-                       get {
-                               return IsPostBack && IsPortletRender &&
-                                       (0 == String.Compare (Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase));
-                       }
-               }
-
-               internal IPortletRenderResponse RenderResponse
-               {
-                       get {
-                               if (!_renderResponseInit)
-                                       if (Context != null) {
-                                               _renderResponse = Context.ServletResponse as IPortletRenderResponse;
-                                               _renderResponseInit = true;
-                                       }
-                               return _renderResponse;
-                       }
-               }
-
-               public string CreateRenderUrl (string url)
-               {
-                       if (RenderResponse != null)
-                               return RenderResponse.createRenderURL (url);
-                       if (PortletNamespace == null)
-                               return url;
-
-                       string internalUrl = RemoveAppPathIfInternal (url);
-                       if (internalUrl == null)
-                               return url;
-
-                       PostBackOptions options = new PostBackOptions (this);
-                       options.ActionUrl = RenderPageMark + internalUrl;
-                       options.RequiresJavaScriptProtocol = true;
-                       return ClientScript.GetPostBackEventReference (options);
-               }
-
-               public string CreateActionUrl (string url)
-               {
-                       if (url.StartsWith (RenderPageMark, StringComparison.Ordinal) || url.StartsWith (ActionPageMark, StringComparison.Ordinal))
-                               return url;
-
-                       if (RenderResponse != null)
-                               return RenderResponse.createActionURL (url);
-                       if (PortletNamespace == null)
-                               return url;
-
-                       Uri requestUrl = Request.Url;
-                       string internalUrl = RemoveAppPathIfInternal (url);
-                       if (internalUrl == null)
-                               return url;
-
-                       return ActionPageMark + internalUrl;
-               }
-
-               private string RemoveAppPathIfInternal (string url)
-               {
-                       Uri reqUrl = Request.Url;
-                       string appPath = Request.ApplicationPath;
-                       string currPage = Request.CurrentExecutionFilePath;
-                       if (currPage.StartsWith (appPath, StringComparison.InvariantCultureIgnoreCase))
-                               currPage = currPage.Substring (appPath.Length);
-                       return PortletInternalUtils.mapPathIfInternal (url, reqUrl.Host, reqUrl.Port, reqUrl.Scheme, appPath, currPage);
-               }
-
-               internal bool OnSaveStateCompleteForPortlet ()
-               {
-                       if (PortletNamespace != null) {
-                               ClientScript.RegisterHiddenField (PageNamespaceKey, PortletNamespace);
-                               ClientScript.RegisterHiddenField (NextActionPageKey, "");
-                               ClientScript.RegisterHiddenField (NextRenderPageKey, "");
-                       }
-
-                       IPortletActionResponse resp = Context.ServletResponse as IPortletActionResponse;
-                       IPortletActionRequest req = Context.ServletRequest as IPortletActionRequest;
-                       if (req == null)
-                               return false;
-
-                       // When redirecting don't save the page viewstate and hidden fields
-                       if (resp.isRedirected ())
-                               return true;
-
-                       if (IsPostBack && 0 == String.Compare (Request.HttpMethod, "POST", true, CultureInfo.InvariantCulture)) {
-                               resp.setRenderParameter ("__VIEWSTATE", GetSavedViewState ());
-                               if (ClientScript.hiddenFields != null)
-                                       foreach (string key in ClientScript.hiddenFields.Keys)
-                                               resp.setRenderParameter (key, (string) ClientScript.hiddenFields [key]);
-                       }
-
-                       // Stop processing only if we are handling processAction. If we
-                       // are handling a postback from render then fall through.
-                       return req.processActionOnly ();
-               }
-       }
-}
+//\r
+// System.Web.UI.Page.jvm.cs\r
+//\r
+// Authors:\r
+//   Eyal Alaluf (eyala@mainsoft.com)\r
+//\r
+// (C) 2006 Mainsoft Co. (http://www.mainsoft.com)\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+\r
+using javax.servlet.http;\r
+using System.Collections.Specialized;\r
+using System.Globalization;\r
+using System.Web.Hosting;\r
+using System.Web.J2EE;\r
+using System.ComponentModel;\r
+using System.IO;\r
+using javax.faces.context;\r
+using javax.faces.render;\r
+using javax.servlet;\r
+using javax.faces;\r
+using javax.faces.application;\r
+using javax.faces.@event;\r
+using javax.faces.el;\r
+using javax.faces.component;\r
+using System.Threading;\r
+using System.Web.Configuration;\r
+using Mainsoft.Web.Hosting;\r
+\r
+namespace System.Web.UI\r
+{\r
+       public partial class Page\r
+       {\r
+               string _namespace = null;\r
+               StateManager.SerializedView _facesSerializedView;\r
+               MethodBinding _action;\r
+               MethodBinding _actionListener;\r
+               bool _immediate;\r
+               Pair _state;\r
+               bool [] _validatorsState;\r
+               ICallbackEventHandler _callbackTarget;\r
+               string _callbackEventError = String.Empty;\r
+               static readonly object CrossPagePostBack = new object ();\r
+               FacesContext _facesContext;\r
+               const string RenderBodyContentOnlyKey = "mainsoft.render.body.content.only";\r
+\r
+               static readonly java.util.List emptyList = java.util.Collections.unmodifiableList (new java.util.ArrayList ());\r
+\r
+               bool _isMultiForm = false;\r
+               bool _isMultiFormInited = false;\r
+\r
+               internal string Namespace\r
+               {\r
+                       get {\r
+                               if (_namespace == null) {\r
+\r
+                                       if (getFacesContext () != null) {\r
+                                               _namespace = getFacesContext ().getExternalContext ().encodeNamespace (String.Empty);\r
+                                       }\r
+\r
+                                       _namespace = _namespace ?? String.Empty;\r
+                               }\r
+                               return _namespace;\r
+                       }\r
+               }\r
+\r
+               internal string theForm {\r
+                       get {\r
+                               return "theForm" + Namespace;\r
+                       }\r
+               }\r
+\r
+               internal bool IsMultiForm {\r
+                       get {\r
+                               if (!_isMultiFormInited) {\r
+                                       string isMultiForm = WebConfigurationManager.AppSettings ["mainsoft.use.portlet.namespace"];\r
+                                       _isMultiForm = isMultiForm != null ? Boolean.Parse(isMultiForm) : false;\r
+\r
+                                       _isMultiFormInited = true;\r
+                               }\r
+                               return _isMultiForm;\r
+                       }\r
+               }\r
+\r
+               IHttpHandler EnterThread () {\r
+\r
+                       IHttpHandler jsfHandler = _context.CurrentHandler;\r
+                       _context.PopHandler ();\r
+                       _context.PushHandler (this);\r
+                       if (jsfHandler == _context.Handler)\r
+                               _context.Handler = this;\r
+                       \r
+                       _context.CurrentHandlerInternal = this;\r
+\r
+                       return jsfHandler;\r
+               }\r
+\r
+               void ExitThread (IHttpHandler jsfHandler) {\r
+                       // TODO\r
+                       //if (context.getResponseComplete ())\r
+                       //    Response.End ();\r
+\r
+                       _context.PopHandler ();\r
+                       _context.PushHandler (jsfHandler);\r
+                       if (this == _context.Handler)\r
+                               _context.Handler = jsfHandler;\r
+\r
+               }\r
+\r
+               public override void encodeBegin (FacesContext context) {\r
+                       // do nothing\r
+               }\r
+\r
+               public override void encodeChildren (FacesContext context) {\r
+                       System.Diagnostics.Trace.WriteLine ("encodeChildren");\r
+\r
+                       // reset _facesContext if changed between action and render phases (such portal).\r
+                       _facesContext = null;\r
+\r
+                       IHttpHandler jsfHandler = EnterThread ();\r
+                       bool wasException = false;\r
+                       try {\r
+                               if (!context.getResponseComplete ()) {\r
+\r
+                                       if (IsCallback) {\r
+                                               string result = ProcessGetCallbackResult (_callbackTarget, _callbackEventError);\r
+                                               HtmlTextWriter callbackOutput = new HtmlTextWriter (Response.Output);\r
+                                               callbackOutput.Write (result);\r
+                                               callbackOutput.Flush ();\r
+                                               return;\r
+                                       }\r
+\r
+                                       // ensure lifecycle complete.\r
+                                       if (!IsLoaded) {\r
+                                               ProcessLoad ();\r
+                                               RestoreValidatorsState (_validatorsState);\r
+                                       }\r
+                                       if (!IsPrerendered)\r
+                                               ProcessLoadComplete ();\r
+\r
+                                       RenderPage ();\r
+                               }\r
+                       }\r
+                       catch (Exception ex) {\r
+                               wasException = true;\r
+                               HandleException (ex);\r
+                       }\r
+                       finally {\r
+                               try {\r
+                                       if (!wasException)\r
+                                               ProcessUnload ();\r
+                               }\r
+                               finally {\r
+                                       ExitThread (jsfHandler);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               public override void encodeEnd (FacesContext context) {\r
+                       // do nothing\r
+               }\r
+\r
+               // BUGBUG: must return correct value. Currently returns 0 as performance optimization.\r
+               public override int getChildCount ()\r
+               {\r
+                       return 0;\r
+               }\r
+\r
+               // BUGBUG: must return correct value. Currently returns empty list as performance optimization.\r
+               public override java.util.List getChildren ()\r
+               {\r
+                       return emptyList;\r
+               }\r
+\r
+               public override UIComponent getParent () {\r
+                       return null;\r
+               }\r
+\r
+               public override void setParent (UIComponent parent) {\r
+                       //ignore: parent is root\r
+               }\r
+\r
+               // TODO: consider validators state\r
+               public override object processSaveState (FacesContext context) {\r
+                       System.Diagnostics.Trace.WriteLine ("processSaveState");\r
+\r
+                       object state = new Pair (_state, GetValidatorsState ());\r
+                       return new StateSerializer (state);\r
+               }\r
+\r
+               public override void processRestoreState (FacesContext context, object state) {\r
+                       System.Diagnostics.Trace.WriteLine ("processRestoreState");\r
+\r
+                       if (state == null)\r
+                               throw new ArgumentNullException ("state");\r
+                       IHttpHandler jsfHandler = EnterThread ();\r
+                       try {\r
+                               state = ((StateSerializer) state).State;\r
+                               _state = (Pair) ((Pair) state).First;\r
+                               _validatorsState = (bool []) ((Pair) state).Second;\r
+                               RestorePageState ();\r
+                       }\r
+                       catch (Exception ex) {\r
+                               HandleException (ex);\r
+                       }\r
+                       finally {\r
+                               ExitThread (jsfHandler);\r
+                       }\r
+               }\r
+\r
+               public override void processDecodes (FacesContext context) {\r
+                       System.Diagnostics.Trace.WriteLine ("processDecodes");\r
+\r
+                       IHttpHandler jsfHandler = EnterThread ();\r
+                       try {\r
+                               ProcessPostData ();\r
+\r
+                               EventRaiserFacesEvent facesEvent = new EventRaiserFacesEvent (this);\r
+                               facesEvent.setPhaseId (PhaseId.INVOKE_APPLICATION);\r
+                               context.getViewRoot ().queueEvent (facesEvent);\r
+\r
+                               base.processDecodes (context);\r
+                       }\r
+                       catch (Exception ex) {\r
+                               HandleException (ex);\r
+                       }\r
+                       finally {\r
+                               ExitThread (jsfHandler);\r
+                       }\r
+               }\r
+\r
+               public override void processValidators (FacesContext context) {\r
+                       System.Diagnostics.Trace.WriteLine ("processValidators");\r
+\r
+                       IHttpHandler jsfHandler = EnterThread ();\r
+                       try {\r
+                               base.processValidators (context);\r
+                       }\r
+                       catch (Exception ex) {\r
+                               HandleException (ex);\r
+                       }\r
+                       finally {\r
+                               ExitThread (jsfHandler);\r
+                       }\r
+               }\r
+\r
+               public override void processUpdates (FacesContext context) {\r
+                       System.Diagnostics.Trace.WriteLine ("processUpdates");\r
+\r
+                       IHttpHandler jsfHandler = EnterThread ();\r
+                       try {\r
+                               base.processUpdates (context);\r
+                       }\r
+                       catch (Exception ex) {\r
+                               HandleException (ex);\r
+                       }\r
+                       finally {\r
+                               ExitThread (jsfHandler);\r
+                       }\r
+               }\r
+\r
+               public override void broadcast (FacesEvent e) {\r
+                       System.Diagnostics.Trace.WriteLine ("broadcast");\r
+\r
+                       if (!(e is EventRaiserFacesEvent))\r
+                               throw new NotSupportedException ("FacesEvent of class " + e.GetType ().Name + " not supported by Page");\r
+\r
+                       IHttpHandler jsfHandler = EnterThread ();\r
+                       bool doUnload = false;\r
+                       try {\r
+                               ProcessRaiseEvents ();\r
+                               doUnload = (ProcessLoadComplete () && IsCrossPagePostBack);\r
+                       }\r
+                       catch (Exception ex) {\r
+                               doUnload = false;\r
+                               HandleException (ex);\r
+                       }\r
+                       finally {\r
+                               try {\r
+                                       if (doUnload) {\r
+                                               getFacesContext ().responseComplete ();\r
+                                               ProcessUnload ();\r
+                                       }\r
+                               }\r
+                               finally {\r
+                                       ExitThread (jsfHandler);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               void HandleException (Exception ex) {\r
+                       try {\r
+                               if (ex is ThreadAbortException) {\r
+                                       if (FlagEnd.Value == ((ThreadAbortException) ex).ExceptionState) {\r
+                                               Thread.ResetAbort ();\r
+                                               return;\r
+                                       }\r
+                                       vmw.common.TypeUtils.Throw (ex);\r
+                               }\r
+                               else\r
+                                       ProcessException (ex);\r
+                       }\r
+                       finally {\r
+                               if (getFacesContext () != null)\r
+                                       getFacesContext ().responseComplete ();\r
+                               ProcessUnload ();\r
+                       }\r
+               }\r
+\r
+               bool [] GetValidatorsState () {\r
+                       if (is_validated && Validators.Count > 0) {\r
+                               bool [] validatorsState = new bool [Validators.Count];\r
+                               bool isValid = true;\r
+                               for (int i = 0; i < Validators.Count; i++) {\r
+                                       IValidator val = Validators [i];\r
+                                       if (!val.IsValid)\r
+                                               isValid = false;\r
+                                       else\r
+                                               validatorsState [i] = true;\r
+                               }\r
+                               return validatorsState;\r
+                       }\r
+                       return null;\r
+               }\r
+\r
+               void RestoreValidatorsState (bool [] validatorsState) {\r
+                       if (validatorsState == null)\r
+                               return;\r
+\r
+                       is_validated = true;\r
+                       for (int i = 0; i < Math.Min (validatorsState.Length, Validators.Count); i++) {\r
+                               IValidator val = Validators [i];\r
+                               val.IsValid = validatorsState [i];\r
+                       }\r
+               }\r
+\r
+               ResponseWriter SetupResponseWriter (TextWriter httpWriter) { //TODO\r
+                       FacesContext facesContext = getFacesContext ();\r
+\r
+                       ResponseWriter oldWriter = facesContext.getResponseWriter ();\r
+                       if (oldWriter == null)\r
+                               throw new InvalidOperationException ();\r
+\r
+                       ResponseWriter writer = oldWriter.cloneWithWriter (new AspNetResponseWriter (httpWriter));\r
+                       \r
+                       facesContext.setResponseWriter (writer);\r
+                       return oldWriter;\r
+               }\r
+\r
+               string DecodeNamespace (string id) {\r
+                       if (Namespace.Length > 0 && id.Length > Namespace.Length && id.StartsWith (Namespace, StringComparison.Ordinal))\r
+                               id = id.Substring (Namespace.Length);\r
+                       return id;\r
+               }\r
+\r
+               protected override FacesContext getFacesContext () {\r
+                       return _facesContext ?? (_facesContext = FacesContext.getCurrentInstance ());\r
+               }\r
+\r
+               #region FacesPageStatePersister\r
+               sealed class FacesPageStatePersister : PageStatePersister\r
+               {\r
+                       public FacesPageStatePersister (Page page)\r
+                               : base (page) {\r
+                       }\r
+\r
+                       public override void Load () {\r
+                               if (Page._state != null) {\r
+                                       ViewState = Page._state.First;\r
+                                       ControlState = Page._state.Second;\r
+                               }\r
+                       }\r
+\r
+                       public override void Save () {\r
+                               if (ViewState != null || ControlState != null)\r
+                                       Page._state = new Pair (ViewState, ControlState);\r
+                       }\r
+               }\r
+               #endregion\r
+\r
+               #region EventRaiserFacesEvent\r
+               sealed class EventRaiserFacesEvent : FacesEvent\r
+               {\r
+                       public EventRaiserFacesEvent (Page page)\r
+                               : base (page) {\r
+                       }\r
+\r
+                       public override bool isAppropriateListener (FacesListener __p1) {\r
+                               throw new NotSupportedException ();\r
+                       }\r
+\r
+                       public override void processListener (FacesListener __p1) {\r
+                               throw new NotSupportedException ();\r
+                       }\r
+               }\r
+               #endregion\r
+\r
+               #region AspNetResponseWriter\r
+               private sealed class AspNetResponseWriter : java.io.Writer\r
+               {\r
+                       readonly TextWriter _writer;\r
+                       public AspNetResponseWriter (TextWriter writer) {\r
+                               _writer = writer;\r
+                       }\r
+                       public override void close () {\r
+                               _writer.Close ();\r
+                       }\r
+\r
+                       public override void flush () {\r
+                               _writer.Flush ();\r
+                       }\r
+\r
+                       public override void write (char [] __p1, int __p2, int __p3) {\r
+                               _writer.Write (__p1, __p2, __p3);\r
+                       }\r
+\r
+                       public override void write (int __p1) {\r
+                               _writer.Write ((char) __p1);\r
+                       }\r
+\r
+                       public override void write (char [] __p1) {\r
+                               _writer.Write (__p1);\r
+                       }\r
+\r
+                       public override void write (string __p1) {\r
+                               _writer.Write (__p1);\r
+                       }\r
+\r
+                       public override void write (string __p1, int __p2, int __p3) {\r
+                               _writer.Write (__p1, __p2, __p3);\r
+                       }\r
+               }\r
+               #endregion\r
+\r
+               #region StateSerializer\r
+               public sealed class StateSerializer : java.io.Externalizable\r
+               {\r
+                       object _state;\r
+\r
+                       public StateSerializer ()\r
+                       {\r
+                       }\r
+\r
+                       public StateSerializer (object state)\r
+                       {\r
+                               _state = state;\r
+                       }\r
+\r
+                       public object State\r
+                       {\r
+                               get { return _state; }\r
+                       }\r
+\r
+                       public void readExternal (java.io.ObjectInput __p1)\r
+                       {\r
+                               Console.WriteLine ("readExternal: " + CurrentPage);\r
+                               ObjectStateFormatter osf = new ObjectStateFormatter (CurrentPage);\r
+                               _state = osf.Deserialize (new ObjectInputStream (__p1));\r
+                       }\r
+\r
+                       public void writeExternal (java.io.ObjectOutput __p1)\r
+                       {\r
+                               Console.WriteLine ("writeExternal: " + CurrentPage);\r
+                               ObjectStateFormatter osf = new ObjectStateFormatter (CurrentPage);\r
+                               osf.Serialize (new ObjectOutputStream (__p1), _state);\r
+                       }\r
+\r
+                       private Page CurrentPage\r
+                       {\r
+                               get\r
+                               {\r
+                                       HttpContext context = HttpContext.Current;\r
+                                       if (context.CurrentHandler is Page)\r
+                                               return (Page) context.CurrentHandler;\r
+                                       \r
+                                       return context.CurrentHandlerInternal;\r
+                               }\r
+                       }\r
+               } \r
+               #endregion\r
+       }\r
+}\r