You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by so...@apache.org on 2011/04/22 21:39:43 UTC

svn commit: r1096004 - /myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java

Author: sobryan
Date: Fri Apr 22 19:39:43 2011
New Revision: 1096004

URL: http://svn.apache.org/viewvc?rev=1096004&view=rev
Log:
TRINIDAD-2089 : Patch submitted by Venkata.  Thanks!

Modified:
    myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java

Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java?rev=1096004&r1=1096003&r2=1096004&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java Fri Apr 22 19:39:43 2011
@@ -865,92 +865,109 @@ public abstract class UIXCollection exte
     if (stamp.isTransient())
       return Transient.TRUE;
 
-    // The structure we will use is:
-    //   0: state of the stamp
-    //   1: state of the children (an array)
-    //   2: state of the facets (an array of name-key pairs)
-    // If there is no facet state, we have a two-element array
-    // If there is no facet state or child state, we have a one-elment array
-    // If there is no state at all, we return null
-
-    Object stampState = StampState.saveStampState(context, stamp);
-
-    // StampState can never EVER be an Object array, as if we do,
-    // we have no possible way of identifying the difference between
-    // just having stamp state, and having stamp state + child/facet state
-    assert(!(stampState instanceof Object[]));
-
-    int facetCount = stamp.getFacetCount();
+    boolean needsTearDownContext = false;
+    
+    if(stamp instanceof FlattenedComponent && stamp instanceof UIXComponent)
+    {
+      ((UIXComponent)stamp).setupVisitingContext(context);
+      needsTearDownContext = true;
+    }
 
     Object[] state = null;
-
-    if (facetCount > 0)
+    
+    try
     {
-      boolean facetStateIsEmpty = true;
-      Object[] facetState = null;
+      // The structure we will use is:
+      //   0: state of the stamp
+      //   1: state of the children (an array)
+      //   2: state of the facets (an array of name-key pairs)
+      // If there is no facet state, we have a two-element array
+      // If there is no facet state or child state, we have a one-elment array
+      // If there is no state at all, we return null
+
+      Object stampState = StampState.saveStampState(context, stamp);
+
+      // StampState can never EVER be an Object array, as if we do,
+      // we have no possible way of identifying the difference between
+      // just having stamp state, and having stamp state + child/facet state
+      assert(!(stampState instanceof Object[]));
+
+      int facetCount = _getFacetCount(stamp);
 
-      Map<String, UIComponent> facetMap = stamp.getFacets();
 
-      int i = 0;
-      for(Map.Entry<String, UIComponent> entry : facetMap.entrySet())
+      if (facetCount > 0)
       {
-        Object singleFacetState = saveStampState(context, entry.getValue());
-        if ((singleFacetState == null) ||
-            (singleFacetState == Transient.TRUE))
-          continue;
+        boolean facetStateIsEmpty = true;
+        Object[] facetState = null;
+
+        Map<String, UIComponent> facetMap = stamp.getFacets();
 
-        // Don't bother allocating anything until we have some non-null
-        // and non-transient facet state
-        if (facetStateIsEmpty)
+        int i = 0;
+        for(Map.Entry<String, UIComponent> entry : facetMap.entrySet())
         {
-          facetStateIsEmpty = false;
-          facetState = new Object[facetCount * 2];
-        }
+          Object singleFacetState = saveStampState(context, entry.getValue());
+          if ((singleFacetState == null) ||
+              (singleFacetState == Transient.TRUE))
+            continue;
+
+          // Don't bother allocating anything until we have some non-null
+          // and non-transient facet state
+          if (facetStateIsEmpty)
+          {
+            facetStateIsEmpty = false;
+            facetState = new Object[facetCount * 2];
+          }
 
-        int base = i * 2;
-        assert(facetState != null);
-        facetState[base] = entry.getKey();
-        facetState[base + 1] = singleFacetState;
-        i++;
-      }
+          int base = i * 2;
+          assert(facetState != null);
+          facetState[base] = entry.getKey();
+          facetState[base + 1] = singleFacetState;
+          i++;
+        }
 
-      // OK, we had something:  allocate the state array to three
-      // entries, and insert the facet state at position 2
-      if (!facetStateIsEmpty)
-      {
-        // trim the facetState array if necessary
-        if(i < facetCount)
+        // OK, we had something:  allocate the state array to three
+        // entries, and insert the facet state at position 2
+        if (!facetStateIsEmpty)
         {
-          Object[] trimmed = new Object[i*2];
-          System.arraycopy(facetState, 0, trimmed, 0, i*2);
-          facetState = trimmed;
+          // trim the facetState array if necessary
+          if(i < facetCount)
+          {
+            Object[] trimmed = new Object[i*2];
+            System.arraycopy(facetState, 0, trimmed, 0, i*2);
+            facetState = trimmed;
+          }
+          state = new Object[3];
+          state[2] = facetState;
         }
-        state = new Object[3];
-        state[2] = facetState;
       }
-    }
 
     // If we have any children, iterate through the array,
     // saving state
     Object childState = StampState.saveChildStampState(context,
                                                        stamp,
                                                        this);
-    if (childState != null)
-    {
-      // If the state hasn't been allocated yet, we only
-      // need a two-element array
-      if (state == null)
-        state = new Object[2];
-      state[1] = childState;
-    }
+      if (childState != null)
+      {
+        // If the state hasn't been allocated yet, we only
+        // need a two-element array
+        if (state == null)
+          state = new Object[2];
+        state[1] = childState;
+      }
 
-    // If we don't have an array, just return the stamp
-    // state
-    if (state == null)
-      return stampState;
+      // If we don't have an array, just return the stamp
+      // state
+      if (state == null)
+        return stampState;
 
-    // Otherwise, store the stamp state at index 0, and return
-    state[0] = stampState;
+      // Otherwise, store the stamp state at index 0, and return
+      state[0] = stampState;
+    }
+    finally
+    {
+      if(needsTearDownContext)
+        ((UIXComponent)stamp).tearDownVisitingContext(context);
+    }
     return state;
   }
 
@@ -1895,6 +1912,18 @@ public abstract class UIXCollection exte
     return b.equals(a);
   }
 
+  //
+  // Optimized path that avoids creating the Facet map
+  // unless necessary
+  //
+  private int _getFacetCount(UIComponent component)
+  {
+    if (component instanceof UIXComponent)
+      return ((UIXComponent) component).getFacetCount();
+
+    return component.getFacets().size();
+  }
+
   private static final class DefaultClientKeyManager extends ClientRowKeyManager
   {
     public void clear()