You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2017/02/09 13:56:32 UTC

svn commit: r1782333 - in /myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application: ApplicationImpl.java _ApplicationUtils.java

Author: tandraschko
Date: Thu Feb  9 13:56:32 2017
New Revision: 1782333

URL: http://svn.apache.org/viewvc?rev=1782333&view=rev
Log:
MYFACES-4088 pass facescontext to new event constructor

Modified:
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/_ApplicationUtils.java

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java?rev=1782333&r1=1782332&r2=1782333&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java Thu Feb  9 13:56:32 2017
@@ -625,8 +625,8 @@ public class ApplicationImpl extends App
                 // systemEventClass
                 // argument. If the list is not empty, perform algorithm traverseListenerList on the list.
                 event = _ApplicationUtils._traverseListenerList(
-                        holder.getListenersForEventClass(systemEventClass), systemEventClass,
-                                              source, event);
+                        facesContext, holder.getListenersForEventClass(systemEventClass),
+                        systemEventClass, source, event);
             }
             
             UIViewRoot uiViewRoot = facesContext.getViewRoot();
@@ -634,14 +634,14 @@ public class ApplicationImpl extends App
             {
                 //Call listeners on view level
                 event = _ApplicationUtils._traverseListenerListWithCopy(
-                        uiViewRoot.getViewListenersForEventClass(systemEventClass), 
+                        facesContext, uiViewRoot.getViewListenersForEventClass(systemEventClass), 
                         systemEventClass, source, event);
             }
 
             SystemListenerEntry systemListenerEntry = _systemEventListenerClassMap.get(systemEventClass);
             if (systemListenerEntry != null)
             {
-                systemListenerEntry.publish(systemEventClass, sourceBaseType, source, event);
+                systemListenerEntry.publish(facesContext, systemEventClass, sourceBaseType, source, event);
             }
         }
         catch (AbortProcessingException e)
@@ -2717,16 +2717,17 @@ public class ApplicationImpl extends App
             }
         }
 
-        public void publish(Class<? extends SystemEvent> systemEventClass, Class<?> classSource, Object source,
-                            SystemEvent event)
+        public void publish(FacesContext facesContext, Class<? extends SystemEvent> systemEventClass,
+                Class<?> classSource, Object source, SystemEvent event)
         {
             if (source != null && _sourceClassMap != null)
             {
-                event = _ApplicationUtils._traverseListenerList(
-                        _sourceClassMap.get(classSource), systemEventClass, source, event);
+                event = _ApplicationUtils._traverseListenerList(facesContext, _sourceClassMap.get(classSource),
+                        systemEventClass, source, event);
             }
 
-            _ApplicationUtils._traverseListenerList(_lstSystemEventListener, systemEventClass, source, event);
+            _ApplicationUtils._traverseListenerList(facesContext, _lstSystemEventListener,
+                    systemEventClass, source, event);
         }
 
         private void addListenerNoDuplicate(List<SystemEventListener> listeners, SystemEventListener listener)

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/_ApplicationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/_ApplicationUtils.java?rev=1782333&r1=1782332&r2=1782333&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/_ApplicationUtils.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/_ApplicationUtils.java Thu Feb  9 13:56:32 2017
@@ -23,6 +23,7 @@ import java.lang.reflect.Constructor;
 import java.util.ArrayList;
 import java.util.List;
 import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
 import javax.faces.event.SystemEvent;
 import javax.faces.event.SystemEventListener;
 
@@ -33,8 +34,8 @@ import javax.faces.event.SystemEventList
 class _ApplicationUtils
 {
     
-    static SystemEvent _createEvent(Class<? extends SystemEvent> systemEventClass, Object source,
-                                            SystemEvent event)
+    static SystemEvent _createEvent(FacesContext facesContext, Class<? extends SystemEvent> systemEventClass,
+            Object source, SystemEvent event)
     {
         if (event == null)
         {
@@ -42,9 +43,11 @@ class _ApplicationUtils
             {
                 Constructor<?>[] constructors = systemEventClass.getConstructors();
                 Constructor<? extends SystemEvent> constructor = null;
+             
+                // try to lookup the new 2 parameter constructor
                 for (Constructor<?> c : constructors)
                 {
-                    if (c.getParameterTypes().length == 1)
+                    if (c.getParameterTypes().length == 2)
                     {
                         // Safe cast, since the constructor belongs
                         // to a class of type SystemEvent
@@ -54,9 +57,27 @@ class _ApplicationUtils
                 }
                 if (constructor != null)
                 {
-                    event = constructor.newInstance(source);
+                    event = constructor.newInstance(facesContext, source);
+                }
+                
+                // try to lookup the old 1 parameter constructor
+                if (constructor == null)
+                {
+                    for (Constructor<?> c : constructors)
+                    {
+                        if (c.getParameterTypes().length == 1)
+                        {
+                            // Safe cast, since the constructor belongs
+                            // to a class of type SystemEvent
+                            constructor = (Constructor<? extends SystemEvent>) c;
+                            break;
+                        }
+                    }
+                    if (constructor != null)
+                    {
+                        event = constructor.newInstance(source);
+                    }
                 }
-
             }
             catch (Exception e)
             {
@@ -68,7 +89,7 @@ class _ApplicationUtils
         return event;
     }
 
-    static SystemEvent _traverseListenerList(List<? extends SystemEventListener> listeners,
+    static SystemEvent _traverseListenerList(FacesContext facesContext, List<? extends SystemEventListener> listeners,
                                                      Class<? extends SystemEvent> systemEventClass, Object source,
                                                      SystemEvent event)
     {
@@ -89,7 +110,7 @@ class _ApplicationUtils
                     // Otherwise, if the event to be passed to the listener instances has not yet been constructed,
                     // construct the event, passing source as the argument to the one-argument constructor that takes
                     // an Object. This same event instance must be passed to all listener instances.
-                    event = _ApplicationUtils._createEvent(systemEventClass, source, event);
+                    event = _createEvent(facesContext, systemEventClass, source, event);
 
                     // Call SystemEvent.isAppropriateListener(javax.faces.event.FacesListener), passing the listener
                     // instance as the argument. If this returns false, take no action on the listener.
@@ -106,7 +127,8 @@ class _ApplicationUtils
         return event;
     }
     
-    static SystemEvent _traverseListenerListWithCopy(List<? extends SystemEventListener> listeners,
+    static SystemEvent _traverseListenerListWithCopy(FacesContext facesContext,
+            List<? extends SystemEventListener> listeners,
             Class<? extends SystemEvent> systemEventClass, Object source,
             SystemEvent event)
     {
@@ -135,7 +157,7 @@ class _ApplicationUtils
                         // construct the event, passing source as the argument
                         // to the one-argument constructor that takes
                         // an Object. This same event instance must be passed to all listener instances.
-                        event = _ApplicationUtils._createEvent(systemEventClass, source, event);
+                        event = _createEvent(facesContext, systemEventClass, source, event);
     
                         // Call SystemEvent.isAppropriateListener(javax.faces.event.FacesListener), passing the listener
                         // instance as the argument. If this returns false, take no action on the listener.