openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1766409 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/component/ webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/
Date Mon, 24 Oct 2016 14:10:16 GMT
Author: rmannibucau
Date: Mon Oct 24 14:10:16 2016
New Revision: 1766409

URL: http://svn.apache.org/viewvc?rev=1766409&view=rev
Log:
OWB-1158 ServletContext bean

Added:
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/ServletContextBean.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java?rev=1766409&r1=1766408&r2=1766409&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/WebBeansType.java
Mon Oct 24 14:10:16 2016
@@ -70,5 +70,6 @@ public enum WebBeansType
     PRINCIPAL,
     VALIDATIONFACT,
     VALIDATION,
-    METADATA
+    METADATA,
+    SERVLET_CONTEXT
 }
\ No newline at end of file

Added: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/ServletContextBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/ServletContextBean.java?rev=1766409&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/ServletContextBean.java
(added)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/ServletContextBean.java
Mon Oct 24 14:10:16 2016
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.web.lifecycle;
+
+import org.apache.webbeans.component.BuiltInOwbBean;
+import org.apache.webbeans.component.SimpleProducerFactory;
+import org.apache.webbeans.component.WebBeansType;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.portable.ProviderBasedProducer;
+
+import javax.inject.Provider;
+import javax.servlet.ServletContext;
+
+class ServletContextBean extends BuiltInOwbBean<ServletContext>
+{
+    ServletContextBean(final WebBeansContext ctx, final ServletContext context)
+    {
+        super(ctx, WebBeansType.SERVLET_CONTEXT, ServletContext.class, new SimpleProducerFactory<ServletContext>(
+                new ProviderBasedProducer<>(ctx, ServletContext.class, new Provider<ServletContext>()
+                {
+                    @Override
+                    public ServletContext get()
+                    {
+                        return context;
+                    }
+                }, true)));
+    }
+
+    @Override
+    public Class<?> proxyableType()
+    {
+        return ServletContext.class;
+    }
+}

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java?rev=1766409&r1=1766408&r2=1766409&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
Mon Oct 24 14:10:16 2016
@@ -43,12 +43,12 @@ import java.util.logging.Level;
 
 /**
  * Manages container lifecycle.
- * 
+ *
  * <p>
  * Behaves according to the request, session, and application
- * contexts of the web application. 
+ * contexts of the web application.
  * </p>
- * 
+ *
  * @version $Rev: 911764 $ $Date: 2010-02-19 11:52:54 +0200 (Fri, 19 Feb 2010) $
  * @see org.apache.webbeans.servlet.WebBeansConfigurationListener
  */
@@ -82,6 +82,11 @@ public final class WebContainerLifecycle
     public void startApplication(Object startupObject)
     {
         ServletContext servletContext = getServletContext(startupObject);
+        // this flag is just there in case some integration does it already so we should
be able to switch it off
+        if ("true".equalsIgnoreCase(getWebBeansContext().getOpenWebBeansConfiguration().getProperty("org.apache.webbeans.web.add-beans",
"true")))
+        {
+            webBeansContext.getBeanManagerImpl().addInternalBean(new ServletContextBean(webBeansContext,
servletContext));
+        }
         super.startApplication(servletContext);
     }
 
@@ -190,7 +195,7 @@ public final class WebContainerLifecycle
         //ContextFactory.cleanUpContextFactory();
 
         this.cleanupShutdownThreadLocals();
-        
+
         if (logger.isLoggable(Level.INFO))
         {
           logger.log(Level.INFO, OWBLogConst.INFO_0002, ServletCompatibilityUtil.getServletInfo(servletContext));
@@ -205,7 +210,7 @@ public final class WebContainerLifecycle
     {
         contextsService.removeThreadLocals();
     }
-    
+
     /**
      * Returns servelt context otherwise throws exception.
      * @param object object
@@ -224,8 +229,8 @@ public final class WebContainerLifecycle
             {
                 throw new WebBeansException(WebBeansLoggerFacade.getTokenString(OWBLogConst.EXCEPT_0018));
             }
-        }                
-        
+        }
+
         throw new IllegalArgumentException("ServletContextEvent object but found null");
     }
 



Mime
View raw message