myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r809815 - in /myfaces/core/trunk/api/src/main/java/javax/faces/component: UIComponent.java UIComponentBase.java
Date Tue, 01 Sep 2009 05:13:35 GMT
Author: lu4242
Date: Tue Sep  1 05:13:35 2009
New Revision: 809815

URL: http://svn.apache.org/viewvc?rev=809815&view=rev
Log:
MYFACES-2342  New objects added for new api in UIViewRoot, UIComponent and UIComponentBase
could be saved and restored (add _systemEventListenerClassMap)

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponent.java
    myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponent.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponent.java?rev=809815&r1=809814&r2=809815&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponent.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponent.java Tue Sep  1
05:13:35 2009
@@ -19,18 +19,31 @@
 package javax.faces.component;
 
 import java.io.IOException;
-import java.util.*;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Deque;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
+import java.util.Set;
 
-import javax.el.ELContext;
 import javax.el.ELException;
 import javax.el.ValueExpression;
 import javax.faces.FacesException;
-import javax.faces.application.Application;
 import javax.faces.application.Resource;
 import javax.faces.component.visit.VisitCallback;
 import javax.faces.component.visit.VisitContext;
-import javax.faces.component.visit.VisitResult;
 import javax.faces.component.visit.VisitHint;
+import javax.faces.component.visit.VisitResult;
 import javax.faces.context.FacesContext;
 import javax.faces.el.ValueBinding;
 import javax.faces.event.AbortProcessingException;
@@ -69,7 +82,7 @@
     public static final String FACETS_KEY = "javax.faces.component.FACETS_KEY";
     public static final String VIEW_LOCATION_KEY = "javax.faces.component.VIEW_LOCATION_KEY";
     private static final String _COMPONENT_STACK = "componentStack:" + UIComponent.class.getName();
-    private Map<Class<? extends SystemEvent>, List<SystemEventListener>>
_systemEventListenerClassMap;
+    Map<Class<? extends SystemEvent>, List<SystemEventListener>> _systemEventListenerClassMap;
     
     @Deprecated
     protected Map<String, ValueExpression> bindings;
@@ -591,7 +604,7 @@
         List<SystemEventListener> listeners = _systemEventListenerClassMap.get(eventClass);
         // Make sure the list for class exists
         if (listeners == null) {
-            listeners = new ArrayList<SystemEventListener>(2);
+            listeners = new _DeltaList<SystemEventListener>(new ArrayList<SystemEventListener>(2));
             _systemEventListenerClassMap.put(eventClass, listeners);
         }
 

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java?rev=809815&r1=809814&r2=809815&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java Tue Sep
 1 05:13:35 2009
@@ -28,7 +28,6 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
 import javax.el.ValueExpression;
 import javax.faces.FacesException;
@@ -43,6 +42,8 @@
 import javax.faces.event.PostAddToViewEvent;
 import javax.faces.event.PreRemoveFromViewEvent;
 import javax.faces.event.PreRenderComponentEvent;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
 import javax.faces.render.RenderKit;
 import javax.faces.render.RenderKitFactory;
 import javax.faces.render.Renderer;
@@ -407,6 +408,14 @@
                 ((PartialStateHolder) entry.getValue()).clearInitialState();
             }
         }
+        if (_systemEventListenerClassMap != null)
+        {
+            for (Map.Entry<Class<? extends SystemEvent>, List<SystemEventListener>>
entry : 
+                _systemEventListenerClassMap.entrySet())
+            {
+                ((PartialStateHolder) entry.getValue()).clearInitialState();
+            }
+        }
     }
 
     /**
@@ -980,6 +989,14 @@
                 ((PartialStateHolder) entry.getValue()).markInitialState();
             }
         }
+        if (_systemEventListenerClassMap != null)
+        {
+            for (Map.Entry<Class<? extends SystemEvent>, List<SystemEventListener>>
entry : 
+                _systemEventListenerClassMap.entrySet())
+            {
+                ((PartialStateHolder) entry.getValue()).markInitialState();
+            }
+        }
     }
 
     @Override
@@ -1515,6 +1532,7 @@
             //and never changes during component life.
             Object facesListenersSaved = saveFacesListenersList(context);
             Object behaviorsMapSaved = saveBehaviorsMap(context);
+            Object systemEventListenerClassMapSaved = saveSystemEventListenerClassMap(context);
             Object stateHelperSaved = null;
             StateHelper stateHelper = getStateHelper(false);
             if (stateHelper != null)
@@ -1522,17 +1540,18 @@
                 stateHelperSaved = stateHelper.saveState(context);
             }
             
-            if (facesListenersSaved == null && stateHelperSaved == null &&
behaviorsMapSaved == null)
+            if (facesListenersSaved == null && stateHelperSaved == null &&

+                behaviorsMapSaved == null && systemEventListenerClassMapSaved ==
null)
             {
                 return null;
             }
             
-            return new Object[] {facesListenersSaved, stateHelperSaved, behaviorsMapSaved};
+            return new Object[] {facesListenersSaved, stateHelperSaved, behaviorsMapSaved,
systemEventListenerClassMapSaved};
         }
         else
         {
             //Full
-            Object values[] = new Object[5];
+            Object values[] = new Object[6];
             values[0] = saveFacesListenersList(context);
             StateHelper stateHelper = getStateHelper(false);
             if (stateHelper != null)
@@ -1540,8 +1559,9 @@
                 values[1] = stateHelper.saveState(context);
             }
             values[2] = saveBehaviorsMap(context);
-            values[3] = _id;
-            values[4] = _clientId;
+            values[3] = saveSystemEventListenerClassMap(context);
+            values[4] = _id;
+            values[5] = _clientId;
 
             return values;
         }
@@ -1566,7 +1586,7 @@
         
         Object values[] = (Object[]) state;
         
-        if ( values.length == 5 && initialStateMarked())
+        if ( values.length == 6 && initialStateMarked())
         {
             //Delta mode is active, but we are restoring a full state.
             //we need to clear the initial state, to restore state without
@@ -1584,7 +1604,7 @@
                         ((_AttachedDeltaWrapper) values[0]).getWrappedStateObject());
             //}
         }
-        else if (values[0] != null || (values.length == 5))
+        else if (values[0] != null || (values.length == 6))
         {
             //Full
             _facesListeners = (_DeltaList<FacesListener>)
@@ -1597,21 +1617,23 @@
         
         getStateHelper().restoreState(context, values[1]);
         
-        if (values.length == 5)
+        if (values.length == 6)
         {
             //Full restore
             restoreFullBehaviorsMap(context, values[2]);
+            restoreFullSystemEventListenerClassMap(context, values[3]);
         }
         else
         {
             //Delta restore
             restoreDeltaBehaviorsMap(context, values[2]);
+            restoreDeltaSystemEventListenerClassMap(context, values[3]);
         }
         
-        if (values.length == 5)
+        if (values.length == 6)
         {
-            _id = (String) values[3];
-            _clientId = (String) values[4];
+            _id = (String) values[4];
+            _clientId = (String) values[5];
         }
     }
     
@@ -1726,8 +1748,101 @@
         {
             return null;
         }
-    } 
-
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void restoreFullSystemEventListenerClassMap(FacesContext facesContext, Object
stateObj)
+    {
+        if (stateObj != null)
+        {
+            Map<Class<? extends SystemEvent>, Object> stateMap = (Map<Class<?
extends SystemEvent>, Object>) stateObj;
+            int initCapacity = (stateMap.size() * 4 + 3) / 3;
+            _systemEventListenerClassMap = new HashMap<Class<? extends SystemEvent>,
List<SystemEventListener>>(initCapacity);
+            for (Map.Entry<Class<? extends SystemEvent>, Object> entry : stateMap.entrySet())
+            {
+                _systemEventListenerClassMap.put(entry.getKey(), (List<SystemEventListener>)
restoreAttachedState(facesContext, entry.getValue()));
+            }
+        }
+        else
+        {
+            _systemEventListenerClassMap = null;
+        }        
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void restoreDeltaSystemEventListenerClassMap(FacesContext facesContext, Object
stateObj)
+    {
+        if (stateObj != null)
+        {
+            Map<Class<? extends SystemEvent>, Object> stateMap = (Map<Class<?
extends SystemEvent>, Object>) stateObj;
+            int initCapacity = (stateMap.size() * 4 + 3) / 3;
+            if (_systemEventListenerClassMap == null)
+            {
+                _systemEventListenerClassMap = new HashMap<Class<? extends SystemEvent>,
List<SystemEventListener>>(initCapacity);
+            }
+            for (Map.Entry<Class<? extends SystemEvent>, Object> entry : stateMap.entrySet())
+            {
+                Object savedObject = entry.getValue(); 
+                if (savedObject instanceof _AttachedDeltaWrapper)
+                {
+                    StateHolder holderList = (StateHolder) _systemEventListenerClassMap.get(entry.getKey());
+                    holderList.restoreState(facesContext, ((_AttachedDeltaWrapper) savedObject).getWrappedStateObject());
+                }
+                else
+                {
+                    _systemEventListenerClassMap.put(entry.getKey(), (List<SystemEventListener>)
restoreAttachedState(facesContext, savedObject));
+                }
+            }
+        }
+    }
+    
+    private Object saveSystemEventListenerClassMap(FacesContext facesContext)
+    {
+        if (_systemEventListenerClassMap != null)
+        {
+            if (initialStateMarked())
+            {
+                HashMap<Class<? extends SystemEvent>, Object> stateMap = new
HashMap<Class<? extends SystemEvent>, Object>(_systemEventListenerClassMap.size(),
1);
+                
+                for (Map.Entry<Class<? extends SystemEvent>, List<SystemEventListener>
> entry : _systemEventListenerClassMap.entrySet())
+                {
+                    // The list is always an instance of _DeltaList so we can cast to
+                    // PartialStateHolder 
+                    PartialStateHolder holder = (PartialStateHolder) entry.getValue();
+                    if (holder.initialStateMarked())
+                    {
+                        Object attachedState = holder.saveState(facesContext);
+                        if (attachedState != null)
+                        {
+                            stateMap.put(entry.getKey(), new _AttachedDeltaWrapper(_facesListeners.getClass(),
+                                    attachedState));
+                        }
+                    }
+                    else
+                    {
+                        stateMap.put(entry.getKey(), saveAttachedState(facesContext, holder));
+                    }
+                }
+                return stateMap;
+            }
+            else
+            {
+                //Save it in the traditional way
+                HashMap<Class<? extends SystemEvent>, Object> stateMap = 
+                    new HashMap<Class<? extends SystemEvent>, Object>(_systemEventListenerClassMap.size(),
1);
+                for (Map.Entry<Class<? extends SystemEvent>, List<SystemEventListener>
> entry : _systemEventListenerClassMap.entrySet())
+                {
+                    stateMap.put(entry.getKey(), saveAttachedState(facesContext, entry.getValue()));
+                }
+                return stateMap;
+            }
+        }
+        else
+        {
+            return null;
+        }
+    }
+    
     /*
     private Object saveBindings(FacesContext context)
     {



Mime
View raw message