Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/Support
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv26957/Support
Modified Files:
PageHandlerFactory.cs
Log Message:
fixed SPRNET-704
fixed SPRNET-705
Index: PageHandlerFactory.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/Support/PageHandlerFactory.cs,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** PageHandlerFactory.cs 3 Aug 2007 08:31:24 -0000 1.32
--- PageHandlerFactory.cs 23 Aug 2007 08:27:08 -0000 1.33
***************
*** 193,203 ****
internal class PageHandler : System.Web.UI.Page, IHttpHandler
{
! private IApplicationContext appContext;
! private string pageId;
! private string url;
! private string path;
! private IHttpHandler cachedHandler; // cache handler if IsReusable == true
! private IDictionary handlerState = new SynchronizedHashtable();
/// <summary>
--- 193,210 ----
internal class PageHandler : System.Web.UI.Page, IHttpHandler
{
! private readonly IApplicationContext appContext;
! private readonly string pageId;
! private readonly string url;
! private readonly string path;
! // cache handler if IsReusable == true
! // since we don't use sync, make it volatile
! private volatile IHttpHandler cachedHandler;
!
! // holds shared state for handlerType
! private Type handlerType;
! private IDictionary handlerState;
!
! private readonly object syncRoot = new object();
/// <summary>
***************
*** 226,229 ****
--- 233,244 ----
}
+ /// <summary>
+ /// Use for sync access to this PageHandler instance.
+ /// </summary>
+ public object SyncRoot
+ {
+ get { return syncRoot; }
+ }
+
#region IHttpHandler Members
***************
*** 235,274 ****
{
IHttpHandler handler = cachedHandler;
if (handler == null)
{
if (path != null)
{
! handler = WebObjectUtils.CreatePageInstance(url);
! if (handler is IApplicationContextAware)
! {
! ((IApplicationContextAware) handler).ApplicationContext = appContext;
! }
}
else
{
! string processId = context.Request[AbstractProcessHandler.ProcessIdParamName];
! if (processId != null)
! {
! handler = (IHttpHandler) ProcessManager.GetProcess(processId);
! }
!
! if (handler == null)
! {
! handler = (IHttpHandler) this.appContext.GetObject(this.pageId);
! if (handler is IProcess)
! {
! ((IProcess) handler).Start(url);
! }
! }
}
if (handler.IsReusable) cachedHandler = handler;
}
! if (handler is ISharedStateAware)
{
! ((ISharedStateAware) handler).SharedState = this.handlerState;
}
if (handler is Control)
{
--- 250,319 ----
{
IHttpHandler handler = cachedHandler;
+
if (handler == null)
{
if (path != null)
{
! handler = CreatePageInstance();
}
else
{
! handler = GetOrCreateProcessHandler(context);
}
+ // note, that we don't care about sync here. The last call wins (it's the most current handler instance anyway)
if (handler.IsReusable) cachedHandler = handler;
}
! ApplySharedState(handler);
! ApplyDependencyInjection(handler);
!
! context.Handler = handler;
! handler.ProcessRequest(context);
! }
!
! /// <summary>
! /// Creates a page instance corresponding to this handler's url.
! /// </summary>
! private IHttpHandler CreatePageInstance()
! {
! IHttpHandler handler;
! handler = WebObjectUtils.CreatePageInstance(url);
! if (handler is IApplicationContextAware)
{
! ((IApplicationContextAware)handler).ApplicationContext = appContext;
}
+ return handler;
+ }
+ /// <summary>
+ /// Gets or - if not found - creates a process handler instance.
+ /// </summary>
+ private IHttpHandler GetOrCreateProcessHandler(HttpContext context)
+ {
+ IHttpHandler handler = null;
+ string processId = context.Request[AbstractProcessHandler.ProcessIdParamName];
+ if (processId != null)
+ {
+ handler = (IHttpHandler) ProcessManager.GetProcess(processId);
+ }
+
+ if (handler == null)
+ {
+ handler = (IHttpHandler) this.appContext.GetObject(this.pageId);
+ if (handler is IProcess)
+ {
+ ((IProcess) handler).Start(url);
+ }
+ }
+ return handler;
+ }
+
+ /// <summary>
+ /// Apply dependency injection stuff on the handler.
+ /// </summary>
+ /// <param name="handler"></param>
+ private void ApplyDependencyInjection(IHttpHandler handler)
+ {
if (handler is Control)
{
***************
*** 282,288 ****
}
}
! context.Handler = handler;
! handler.ProcessRequest(context);
}
--- 327,362 ----
}
}
+ }
! /// <summary>
! /// Applies <see cref="HandlerState"/> to the given handler if applicable.
! /// </summary>
! private void ApplySharedState(IHttpHandler handler)
! {
! if (handler is ISharedStateAware)
! {
! CheckIfPageWasRecompiled(handler);
! ((ISharedStateAware)handler).SharedState = this.handlerState;
! }
! }
!
! /// <summary>
! /// Checks, if page has been recompiled. Creates/discards handlerState if necessary.
! /// </summary>
! /// <param name="handler"></param>
! private void CheckIfPageWasRecompiled(IHttpHandler handler)
! {
! if (handlerType != handler.GetType())
! {
! lock (SyncRoot)
! {
! if (handlerType != handler.GetType())
! {
! // discard old handlerState and cache new pagetype
! handlerState = new SynchronizedHashtable();
! handlerType = handler.GetType();
! }
! }
! }
}
|