myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1154801 - in /myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request: CodiFacesContextWrapper.java DefaultErrorViewExceptionHandler.java
Date Sun, 07 Aug 2011 23:36:47 GMT
Author: gpetracek
Date: Sun Aug  7 23:36:46 2011
New Revision: 1154801

URL: http://svn.apache.org/viewvc?rev=1154801&view=rev
Log:
EXTCDI-208 lazy injection in ExceptionHandler

Modified:
    myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/CodiFacesContextWrapper.java
    myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/DefaultErrorViewExceptionHandler.java

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/CodiFacesContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/CodiFacesContextWrapper.java?rev=1154801&r1=1154800&r2=1154801&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/CodiFacesContextWrapper.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/CodiFacesContextWrapper.java
Sun Aug  7 23:36:46 2011
@@ -31,7 +31,6 @@ import org.apache.myfaces.extensions.cdi
 import javax.faces.application.FacesMessage;
 import javax.faces.application.Application;
 import javax.faces.context.ExceptionHandler;
-import javax.faces.context.ExceptionHandlerWrapper;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.context.FacesContextWrapper;
@@ -78,9 +77,9 @@ class CodiFacesContextWrapper extends Fa
 
         if(this.defaultErrorViewExceptionHandlerActivated)
         {
-            exceptionHandler = new DefaultErrorViewExceptionHandler(exceptionHandler);
+            exceptionHandler = new DefaultErrorViewExceptionHandler(
+                    exceptionHandler, this.advancedQualifierRequiredForDependencyInjection);
         }
-        tryToInjectFields(exceptionHandler);
         return exceptionHandler;
     }
 
@@ -154,16 +153,6 @@ class CodiFacesContextWrapper extends Fa
         }
     }
 
-    private void tryToInjectFields(ExceptionHandler exceptionHandler)
-    {
-        CodiUtils.injectFields(exceptionHandler, this.advancedQualifierRequiredForDependencyInjection);
-
-        if(exceptionHandler instanceof ExceptionHandlerWrapper)
-        {
-            tryToInjectFields(((ExceptionHandlerWrapper) exceptionHandler).getWrapped());
-        }
-    }
-
     /**
      * {@inheritDoc}
      */

Modified: myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/DefaultErrorViewExceptionHandler.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/DefaultErrorViewExceptionHandler.java?rev=1154801&r1=1154800&r2=1154801&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/DefaultErrorViewExceptionHandler.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/jsf20-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/jsf2/impl/listener/request/DefaultErrorViewExceptionHandler.java
Sun Aug  7 23:36:46 2011
@@ -18,10 +18,10 @@
  */
 package org.apache.myfaces.extensions.cdi.jsf2.impl.listener.request;
 
-import org.apache.myfaces.extensions.cdi.core.api.Advanced;
 import org.apache.myfaces.extensions.cdi.core.api.config.view.DefaultErrorView;
 import org.apache.myfaces.extensions.cdi.core.api.navigation.ViewNavigationHandler;
 import org.apache.myfaces.extensions.cdi.core.impl.projectstage.ProjectStageProducer;
+import org.apache.myfaces.extensions.cdi.core.impl.util.CodiUtils;
 
 import javax.enterprise.context.ContextNotActiveException;
 import javax.faces.FacesException;
@@ -34,18 +34,16 @@ import javax.faces.context.FacesContext;
 import javax.faces.context.Flash;
 import javax.faces.event.ExceptionQueuedEvent;
 import javax.faces.event.ExceptionQueuedEventContext;
-import javax.inject.Inject;
 import java.util.Iterator;
 
 /**
  * @author Gerhard Petracek
  */
-@Advanced
 class DefaultErrorViewExceptionHandler extends ExceptionHandlerWrapper
 {
     private ExceptionHandler wrapped;
+    private boolean advancedQualifierRequiredForDependencyInjection;
 
-    @Inject
     private ViewNavigationHandler viewNavigationHandler;
 
     /**
@@ -55,9 +53,10 @@ class DefaultErrorViewExceptionHandler e
     {
     }
 
-    DefaultErrorViewExceptionHandler(ExceptionHandler wrapped)
+    DefaultErrorViewExceptionHandler(ExceptionHandler wrapped, boolean advancedQualifierRequiredForDependencyInjection)
     {
         this.wrapped = wrapped;
+        this.advancedQualifierRequiredForDependencyInjection = advancedQualifierRequiredForDependencyInjection;
     }
 
     /**
@@ -66,6 +65,7 @@ class DefaultErrorViewExceptionHandler e
     @Override
     public void handle() throws FacesException
     {
+        lazyInit();
         Iterator<ExceptionQueuedEvent> exceptionQueuedEventIterator = getUnhandledExceptionQueuedEvents().iterator();
 
         while (exceptionQueuedEventIterator.hasNext())
@@ -132,11 +132,31 @@ class DefaultErrorViewExceptionHandler e
         this.wrapped.handle();
     }
 
+    private void lazyInit()
+    {
+        if(this.viewNavigationHandler == null)
+        {
+            tryToInjectFields(this.wrapped);
+            this.viewNavigationHandler = CodiUtils.getContextualReferenceByClass(ViewNavigationHandler.class);
+        }
+    }
+
+    private void tryToInjectFields(ExceptionHandler exceptionHandler)
+    {
+        CodiUtils.injectFields(exceptionHandler, this.advancedQualifierRequiredForDependencyInjection);
+
+        if(exceptionHandler instanceof ExceptionHandlerWrapper)
+        {
+            tryToInjectFields(((ExceptionHandlerWrapper) exceptionHandler).getWrapped());
+        }
+    }
+
     /**
      * {@inheritDoc}
      */
     public ExceptionHandler getWrapped()
     {
+        lazyInit();
         return wrapped;
     }
 }



Mime
View raw message