Author: nbelaevski
Date: 2009-03-24 20:09:34 -0400 (Tue, 24 Mar 2009)
New Revision: 13165
Added:
trunk/framework/impl/src/main/java/org/richfaces/context/
trunk/framework/impl/src/main/java/org/richfaces/context/RequestContext.java
Log:
https://jira.jboss.org/jira/browse/RF-6547
Added: trunk/framework/impl/src/main/java/org/richfaces/context/RequestContext.java
===================================================================
--- trunk/framework/impl/src/main/java/org/richfaces/context/RequestContext.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/richfaces/context/RequestContext.java 2009-03-25
00:09:34 UTC (rev 13165)
@@ -0,0 +1,81 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.context;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.1
+ */
+
+public final class RequestContext {
+
+ private static final String REQUEST_ATTRIBUTE_NAME = RequestContext.class.getName();
+
+ private Map<String, Object> attributesMap = null;
+
+ private RequestContext() {
+ super();
+ }
+
+ public static RequestContext getInstance() {
+ return getInstance(FacesContext.getCurrentInstance());
+ }
+
+ public static RequestContext getInstance(FacesContext context) {
+ ExternalContext externalContext = context.getExternalContext();
+ Map<String, Object> requestMap = externalContext.getRequestMap();
+
+ RequestContext requestContext = (RequestContext)
requestMap.get(REQUEST_ATTRIBUTE_NAME);
+ if (requestContext == null) {
+ requestContext = new RequestContext();
+
+ requestMap.put(REQUEST_ATTRIBUTE_NAME, requestContext);
+ }
+
+ return requestContext;
+ }
+
+ public Object getAttribute(String name) {
+ Object result = null;
+
+ if (attributesMap != null) {
+ result = attributesMap.get(name);
+ }
+
+ return result;
+ }
+
+ public void setAttribute(String name, Object value) {
+ if (attributesMap == null) {
+ attributesMap = new HashMap<String, Object>();
+ }
+
+ attributesMap.put(name, value);
+ }
+
+}