[seam-commits] Seam SVN: r12574 - in modules/servlet/trunk: impl/src/main/java/org/jboss/seam/servlet and 4 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Apr 22 15:15:04 EDT 2010


Author: nickarls
Date: 2010-04-22 15:15:01 -0400 (Thu, 22 Apr 2010)
New Revision: 12574

Added:
   modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/DefaultValue.java
   modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/HttpParam.java
   modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/beanManager/
   modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/beanManager/ServletContextBeanManagerProvider.java
   modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpParamProducer.java
   modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpServletEnvironmentProducer.java
   modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpSessionStatus.java
   modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/ServletContextHelper.java
   modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/ServletContextProducer.java
   modules/servlet/trunk/impl/src/main/resources/META-INF/services/
   modules/servlet/trunk/impl/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider
Removed:
   modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/RequestParameter.java
   modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpArtifacts.java
   modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpUserArtifacts.java
Log:
BeanManagerAware infrastructure

Added: modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/DefaultValue.java
===================================================================
--- modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/DefaultValue.java	                        (rev 0)
+++ modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/DefaultValue.java	2010-04-22 19:15:01 UTC (rev 12574)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.servlet.http;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.util.Nonbinding;
+import javax.inject.Qualifier;
+
+/**
+ * Sets the default value for a {@link HttpParam}
+ * 
+ * @author Nicklas Karlsson
+ *
+ */
+ at Qualifier
+ at Retention(RUNTIME)
+ at Target( { FIELD, PARAMETER, METHOD })
+public @interface DefaultValue
+{
+   @Nonbinding
+   public String value();
+}
\ No newline at end of file

Copied: modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/HttpParam.java (from rev 12541, modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/RequestParameter.java)
===================================================================
--- modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/HttpParam.java	                        (rev 0)
+++ modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/HttpParam.java	2010-04-22 19:15:01 UTC (rev 12574)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.servlet.http;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.util.Nonbinding;
+import javax.inject.Qualifier;
+
+/**
+ * Qualifies injection points that should have their values fetched from a HTTP request attribute
+ * 
+ * @author Nicklas Karlsson
+ *
+ */
+ at Qualifier
+ at Retention(RUNTIME)
+ at Target( { FIELD, PARAMETER, METHOD })
+public @interface HttpParam
+{
+   @Nonbinding
+   public String value();
+}
\ No newline at end of file

Deleted: modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/RequestParameter.java
===================================================================
--- modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/RequestParameter.java	2010-04-22 18:12:04 UTC (rev 12573)
+++ modules/servlet/trunk/api/src/main/java/org/jboss/seam/servlet/http/RequestParameter.java	2010-04-22 19:15:01 UTC (rev 12574)
@@ -1,48 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.seam.servlet.http;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.enterprise.util.Nonbinding;
-import javax.inject.Qualifier;
-
-/**
- * Qualifies injection points that should have their values fetched from a HTTP request attribute
- * 
- * @author Nicklas Karlsson
- *
- */
- at Qualifier
- at Retention(RUNTIME)
- at Target( { FIELD, PARAMETER, METHOD })
-public @interface RequestParameter
-{
-   @Nonbinding
-   public String value();
-}
\ No newline at end of file

Added: modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/beanManager/ServletContextBeanManagerProvider.java
===================================================================
--- modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/beanManager/ServletContextBeanManagerProvider.java	                        (rev 0)
+++ modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/beanManager/ServletContextBeanManagerProvider.java	2010-04-22 19:15:01 UTC (rev 12574)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.servlet.beanManager;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.seam.servlet.http.ServletContextHelper;
+import org.jboss.weld.extensions.beanManager.BeanManagerProvider;
+
+/**
+ * A BeanManager provider for the Servlet Context attribute
+ * "javax.enterprise.inject.spi.BeanManager"
+ * 
+ * @author Nicklas Karlsson
+ * 
+ */
+public class ServletContextBeanManagerProvider implements BeanManagerProvider
+{
+   public BeanManager getBeanManager()
+   {
+      return (BeanManager) ServletContextHelper.getCurrentInstance().getAttribute(BeanManager.class.getName());
+   }
+
+   public int getPrecedence()
+   {
+      return 0;
+   }
+
+}

Deleted: modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpArtifacts.java
===================================================================
--- modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpArtifacts.java	2010-04-22 18:12:04 UTC (rev 12573)
+++ modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpArtifacts.java	2010-04-22 19:15:01 UTC (rev 12574)
@@ -1,74 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.seam.servlet.http;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-
-import org.jboss.seam.servlet.event.qualifier.Destroyed;
-import org.jboss.seam.servlet.event.qualifier.Initialized;
-import org.slf4j.Logger;
-
-/**
- * 
- * @author Nicklas Karlsson
- * 
- *         A source for HTTP artifacts. It observes for and stores the
- *         ServletContext and provides the HttpSession and ServletRequest
- *         objects
- */
- at ApplicationScoped
-public class HttpArtifacts
-{
-   private ServletContext servletContext;
-
-   @Inject
-   BeanManager beanManager;
-   
-   @Inject Logger log;
-
-   protected void contextInitialized(@Observes @Initialized ServletContextEvent e)
-   {
-      log.debug("Servlet context initialized with event #0", e);
-      servletContext = e.getServletContext();
-      servletContext.setAttribute(BeanManager.class.getName(), beanManager);
-   }
-
-   protected void contextDestroyed(@Observes @Destroyed ServletContextEvent e)
-   {
-      log.debug("Servlet context destroyed with event #0", e);
-      servletContext = null;
-   }
-   
-   @Produces
-   @ApplicationScoped
-   public ServletContext getServletContext()
-   {
-      return servletContext;
-   }
-
-}
\ No newline at end of file

Added: modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpParamProducer.java
===================================================================
--- modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpParamProducer.java	                        (rev 0)
+++ modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpParamProducer.java	2010-04-22 19:15:01 UTC (rev 12574)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.servlet.http;
+
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * A producer for {@link HttpParam}
+ * 
+ * @author Nicklas Karlsson
+ * 
+ */
+public class HttpParamProducer
+{
+   @Inject
+   private HttpServletRequest request;
+
+   @Produces
+   @HttpParam("")
+   protected String getParamValue(InjectionPoint ip)
+   {
+      String parameterName = getParameterName(ip);
+      return getParameterValue(parameterName, ip);
+   }
+
+   private String getParameterName(InjectionPoint ip)
+   {
+      String parameterName = ip.getAnnotated().getAnnotation(HttpParam.class).value();
+      if ("".equals(parameterName))
+      {
+         parameterName = ip.getMember().getName();
+      }
+      return parameterName;
+   }
+
+   private String getParameterValue(String parameterName, InjectionPoint ip)
+   {
+      return isParameterInRequest(parameterName) ? request.getParameter(parameterName) : getDefaultValue(ip);
+   }
+
+   private boolean isParameterInRequest(String parameterName)
+   {
+      return request.getParameterMap().containsKey(parameterName);
+   }
+
+   private String getDefaultValue(InjectionPoint ip)
+   {
+      DefaultValue defaultValueAnnotation = ip.getAnnotated().getAnnotation(DefaultValue.class);
+      return defaultValueAnnotation == null ? null : defaultValueAnnotation.value();
+   }
+}

Copied: modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpServletEnvironmentProducer.java (from rev 12541, modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpUserArtifacts.java)
===================================================================
--- modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpServletEnvironmentProducer.java	                        (rev 0)
+++ modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpServletEnvironmentProducer.java	2010-04-22 19:15:01 UTC (rev 12574)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.servlet.http;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+
+import org.jboss.seam.servlet.event.qualifier.Created;
+import org.jboss.seam.servlet.event.qualifier.Destroyed;
+import org.jboss.seam.servlet.event.qualifier.Initialized;
+import org.slf4j.Logger;
+
+/**
+ * A manager for acquiring HTTP artifacts
+ * 
+ * @author Nicklas Karlsson
+ * 
+ */
+ at RequestScoped
+public class HttpServletEnvironmentProducer implements Serializable
+{
+   private static final long serialVersionUID = 1L;
+
+   private HttpSession session;
+   private HttpServletRequest request;
+
+   @Inject
+   private Logger log;
+
+   protected void requestInitialized(@Observes @Initialized ServletRequestEvent e)
+   {
+      log.trace("Servlet request initialized with event #0", e);
+      request = (HttpServletRequest) e.getServletRequest();
+      session = request.getSession();
+   }
+
+   protected void requestDestroyed(@Observes @Destroyed ServletRequestEvent e)
+   {
+      log.trace("Servlet request destroyed with event #0", e);
+      request = null;
+   }
+
+   @Produces
+   @RequestScoped
+   protected HttpSession getSession()
+   {
+      return session;
+   }
+
+   @Produces
+   @RequestScoped
+   protected HttpServletRequest getRequest()
+   {
+      return request;
+   }
+
+}

Added: modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpSessionStatus.java
===================================================================
--- modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpSessionStatus.java	                        (rev 0)
+++ modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpSessionStatus.java	2010-04-22 19:15:01 UTC (rev 12574)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.servlet.http;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+/**
+ * A helper bean that can be injected to check the status of the HttpSession and acquiring it
+ * 
+ * @author Nicklas Karlsson
+ *
+ */
+ at RequestScoped
+public class HttpSessionStatus
+{
+   @Inject
+   private HttpServletRequest request;
+
+   public boolean isActive()
+   {
+      HttpSession session = request.getSession(false);
+      try
+      {
+         return session != null && (session.getMaxInactiveInterval() > 0);
+      }
+      catch (IllegalStateException e)
+      {
+         return false;
+      }
+   }
+
+   public HttpSession getOrCreate()
+   {
+      return request.getSession();
+   }
+
+}

Deleted: modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpUserArtifacts.java
===================================================================
--- modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpUserArtifacts.java	2010-04-22 18:12:04 UTC (rev 12573)
+++ modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpUserArtifacts.java	2010-04-22 19:15:01 UTC (rev 12574)
@@ -1,103 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.seam.servlet.http;
-
-import java.io.Serializable;
-
-import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.InjectionPoint;
-import javax.inject.Inject;
-import javax.servlet.ServletRequestEvent;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionEvent;
-
-import org.jboss.seam.servlet.event.qualifier.Created;
-import org.jboss.seam.servlet.event.qualifier.Destroyed;
-import org.jboss.seam.servlet.event.qualifier.Initialized;
-import org.slf4j.Logger;
-
-/**
- * A manager for acquiring HTTP artifacts
- * 
- * @author Nicklas Karlsson
- * 
- */
- at RequestScoped
-public class HttpUserArtifacts implements Serializable
-{
-   private static final long serialVersionUID = 1L;
-
-   private HttpSession session;
-   private HttpServletRequest request;
-
-   @Inject
-   private Logger log;
-
-   protected void requestInitialized(@Observes @Initialized ServletRequestEvent e)
-   {
-      log.trace("Servlet request initialized with event #0", e);
-      request = (HttpServletRequest) e.getServletRequest();
-   }
-
-   protected void requestDestroyed(@Observes @Destroyed ServletRequestEvent e)
-   {
-      log.trace("Servlet request destroyed with event #0", e);
-      request = null;
-   }
-
-   protected void sessionInitialized(@Observes @Created HttpSessionEvent e)
-   {
-      log.trace("HTTP session initalized with event #0", e);
-      session = e.getSession();
-   }
-
-   protected void sessionDestroyed(@Observes @Destroyed HttpSessionEvent e)
-   {
-      log.trace("HTTP session destroyed with event #0", e);
-      session = null;
-   }
-
-   @Produces
-   @RequestScoped
-   protected HttpSession getSession()
-   {
-      return session;
-   }
-
-   @Produces
-   @RequestScoped
-   protected HttpServletRequest getRequest()
-   {
-      return request;
-   }
-
-   @Produces
-   @RequestParameter("")
-   protected String getParamValue(InjectionPoint ip)
-   {
-      return getRequest().getParameter(ip.getAnnotated().getAnnotation(RequestParameter.class).value());
-   }
-
-}

Added: modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/ServletContextHelper.java
===================================================================
--- modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/ServletContextHelper.java	                        (rev 0)
+++ modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/ServletContextHelper.java	2010-04-22 19:15:01 UTC (rev 12574)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.servlet.http;
+
+import javax.servlet.ServletContext;
+
+/**
+ * A ThreadLocal storage for the ServletContext. The current instance is set in
+ * ServletContextProducer and used in the ServletContextBeanManagerProvider.
+ * 
+ * @author Nicklas Karlsson
+ * 
+ */
+public class ServletContextHelper
+{
+   private static ThreadLocal<ServletContext> servletContext = new ThreadLocal<ServletContext>()
+   {
+      protected ServletContext initialValue()
+      {
+         return null;
+      }
+   };
+
+   /**
+    * Returns the current instance of the ServletContext, if any
+    * 
+    * @return The servet context or null if none is currently set
+    */
+   public static ServletContext getCurrentInstance()
+   {
+      return (servletContext.get());
+   }
+
+   
+   /**
+    * Sets the current instance of the ServletContext
+    * 
+    * @param sc The Servlet Context
+    */
+   public static void setCurrentInstance(ServletContext sc)
+   {
+      servletContext.set(sc);
+   }
+}

Copied: modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/ServletContextProducer.java (from rev 12541, modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/HttpArtifacts.java)
===================================================================
--- modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/ServletContextProducer.java	                        (rev 0)
+++ modules/servlet/trunk/impl/src/main/java/org/jboss/seam/servlet/http/ServletContextProducer.java	2010-04-22 19:15:01 UTC (rev 12574)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.servlet.http;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+
+import org.jboss.seam.servlet.event.qualifier.Destroyed;
+import org.jboss.seam.servlet.event.qualifier.Initialized;
+import org.slf4j.Logger;
+
+/**
+ * 
+ * @author Nicklas Karlsson
+ * 
+ *         A source for HTTP artifacts. It observes for and stores the
+ *         ServletContext and provides the HttpSession and ServletRequest
+ *         objects
+ */
+ at ApplicationScoped
+public class ServletContextProducer
+{
+   private ServletContext servletContext;
+
+   @Inject
+   private BeanManager beanManager;
+
+   @Inject
+   private Logger log;
+
+   protected void contextInitialized(@Observes @Initialized ServletContextEvent e)
+   {
+      log.debug("Servlet context initialized with event #0", e);
+      servletContext = e.getServletContext();
+      servletContext.setAttribute(BeanManager.class.getName(), beanManager);
+      ServletContextHelper.setCurrentInstance(servletContext);
+   }
+
+   protected void contextDestroyed(@Observes @Destroyed ServletContextEvent e)
+   {
+      log.debug("Servlet context destroyed with event #0", e);
+      servletContext = null;
+   }
+
+   @Produces
+   @ApplicationScoped
+   public ServletContext getServletContext()
+   {
+      return servletContext;
+   }
+
+}
\ No newline at end of file

Added: modules/servlet/trunk/impl/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider
===================================================================
--- modules/servlet/trunk/impl/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider	                        (rev 0)
+++ modules/servlet/trunk/impl/src/main/resources/META-INF/services/org.jboss.weld.extensions.beanManager.BeanManagerProvider	2010-04-22 19:15:01 UTC (rev 12574)
@@ -0,0 +1 @@
+org.jboss.seam.servlet.beanManager.ServletContextBeanManagerProvider



More information about the seam-commits mailing list