[weld-commits] Weld SVN: r4039 - in extensions/trunk/servlet/int/src/main: java/org/jboss/weld/environment/servlet/jsf and 1 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Wed Oct 14 10:23:08 EDT 2009


Author: pete.muir at jboss.org
Date: 2009-10-14 10:23:08 -0400 (Wed, 14 Oct 2009)
New Revision: 4039

Removed:
   extensions/trunk/servlet/int/src/main/java/org/jboss/webbeans/environment/servlet/
Modified:
   extensions/trunk/servlet/int/src/main/java/org/jboss/weld/environment/servlet/jsf/WeldApplication.java
   extensions/trunk/servlet/int/src/main/resources/META-INF/faces-config.xml
Log:
cleanup, refactor

Modified: extensions/trunk/servlet/int/src/main/java/org/jboss/weld/environment/servlet/jsf/WeldApplication.java
===================================================================
--- extensions/trunk/servlet/int/src/main/java/org/jboss/weld/environment/servlet/jsf/WeldApplication.java	2009-10-14 14:21:38 UTC (rev 4038)
+++ extensions/trunk/servlet/int/src/main/java/org/jboss/weld/environment/servlet/jsf/WeldApplication.java	2009-10-14 14:23:08 UTC (rev 4039)
@@ -23,7 +23,6 @@
 import javax.faces.context.FacesContext;
 import javax.servlet.ServletContext;
 
-import org.jboss.weld.manager.api.WeldManager;
 import org.jboss.weld.environment.servlet.util.Reflections;
 
 /**
@@ -37,61 +36,62 @@
    
    private final Application application;
    private ExpressionFactory expressionFactory;
+   private BeanManager beanManager;
    
    public WeldApplication(Application application)
    {
       this.application = application;
-      BeanManager beanManager = getBeanManager();
-      if (beanManager != null)
+   }
+   
+   private void init()
+   {
+      if (expressionFactory == null && application.getExpressionFactory() != null && beanManager() != null)
       {
          application.addELContextListener(Reflections.<ELContextListener>newInstance("org.jboss.weld.el.WeldELContextListener"));
-         application.addELResolver(beanManager.getELResolver());
+         application.addELResolver(beanManager().getELResolver());
+         this.expressionFactory = beanManager().wrapExpressionFactory(application.getExpressionFactory());
       }
    }
 
    @Override
    protected Application delegate()
    {
+      init();
       return application;
    }
    
    @Override
    public ExpressionFactory getExpressionFactory()
    {
-      // Application is multi-threaded, but no need to guard against races (re-
-      // creating the cached expression factory doesn't matter) or liveness
-      // (the value read by all threads will be the same)
-      // We have to do this lazily as Mojarra hasn't set the ExpressionFactory
-      // when the object is created
-      if (this.expressionFactory == null)
+      init();
+      if (expressionFactory == null)
       {
-         BeanManager beanManager = getBeanManager();
-         if (beanManager != null)
-         {
-            this.expressionFactory = beanManager.wrapExpressionFactory(delegate().getExpressionFactory());
-         }
-         else
-         {
-            // WB failed to initialize properly
-            this.expressionFactory = delegate().getExpressionFactory(); 
-         }
+         return application.getExpressionFactory();
       }
-      return expressionFactory;
+      else
+      {
+         return expressionFactory;
+      }
    }
    
-   private static WeldManager getBeanManager()
+   private BeanManager beanManager()
    {
-      FacesContext facesContext = FacesContext.getCurrentInstance();
-      if (!(facesContext.getExternalContext().getContext() instanceof ServletContext))
+      if (beanManager == null)
       {
-         throw new IllegalStateException("Not in a servlet environment!");
+         FacesContext facesContext = FacesContext.getCurrentInstance();
+         if (!(facesContext.getExternalContext().getContext() instanceof ServletContext))
+         {
+            throw new IllegalStateException("Not in a servlet environment!");
+         }
+         ServletContext ctx = (ServletContext) facesContext.getExternalContext().getContext();
+         if (ctx.getAttribute(BeanManager.class.getName()) == null)
+         {
+            return null;
+         }
+         this.beanManager = (BeanManager) ctx.getAttribute(BeanManager.class.getName());
       }
-      ServletContext ctx = (ServletContext) facesContext.getExternalContext().getContext();
-      if (ctx.getAttribute(BeanManager.class.getName()) == null)
-      {
-         throw new IllegalStateException("BeanManager has not been pushed into the ServletContext");
-      }
-      return (WeldManager) ctx.getAttribute(BeanManager.class.getName());
+      return beanManager;
+      
    }
 
 }

Modified: extensions/trunk/servlet/int/src/main/resources/META-INF/faces-config.xml
===================================================================
--- extensions/trunk/servlet/int/src/main/resources/META-INF/faces-config.xml	2009-10-14 14:21:38 UTC (rev 4038)
+++ extensions/trunk/servlet/int/src/main/resources/META-INF/faces-config.xml	2009-10-14 14:23:08 UTC (rev 4039)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<faces-config id="webbeans" version="1.2" 
+<faces-config id="weld" version="1.2" 
               xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">



More information about the weld-commits mailing list