2 // (C) 2007 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.Generic;
\r
31 using System.Configuration;
\r
33 using Mainsoft.Web.Hosting;
\r
34 using javax.faces.lifecycle;
\r
36 namespace Mainsoft.Web
\r
39 /// BaseHttpContext contains all of the per-request state information related to the processing of a single request,
\r
40 /// and the rendering of the corresponding response.
\r
42 public abstract class BaseHttpContext
\r
44 protected readonly HttpContext _context;
\r
45 static readonly object _contextKey = new object ();
\r
47 protected BaseHttpContext (HttpContext context) {
\r
49 context.Items [_contextKey] = this;
\r
53 /// Gets the Mainsoft.Web.BaseHttpContext object for the current request.
\r
55 /// <param name="context"></param>
\r
56 /// <returns></returns>
\r
57 public static BaseHttpContext GetCurrent(HttpContext context) {
\r
58 if (context == null)
\r
59 throw new ArgumentNullException ("context");
\r
61 BaseHttpContext baseContext = (BaseHttpContext) context.Items [_contextKey];
\r
62 return baseContext ?? GetWorker (context).CreateContext (context);
\r
66 /// Returns the javax.faces.lifecycle.Lifecycle instance.
\r
68 public Lifecycle Lifecycle {
\r
69 get { return BaseHttpServlet.Lifecycle; }
\r
73 /// Returns the Mainsoft.Web.Hosting.BaseWorkerRequest object for the current request.
\r
75 protected BaseWorkerRequest Worker {
\r
76 get { return GetWorker (_context); }
\r
79 static BaseWorkerRequest GetWorker (HttpContext context) {
\r
80 return (BaseWorkerRequest) ((IServiceProvider) context).GetService (typeof (HttpWorkerRequest));
\r