You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2008/04/15 05:08:34 UTC

svn commit: r648106 - in /myfaces/core/trunk/api/src/main/java/javax/faces/component: UIComponentBase.java _EmptyIterator.java _FacetsAndChildrenIterator.java

Author: lu4242
Date: Mon Apr 14 20:08:27 2008
New Revision: 648106

URL: http://svn.apache.org/viewvc?rev=648106&view=rev
Log:
fix MYFACES-1864 Enhance UIComponentBase.getFacetsAndChildren(), creating _FacetsAndChildrenIterator only when it is necessary

Added:
    myfaces/core/trunk/api/src/main/java/javax/faces/component/_EmptyIterator.java   (with props)
Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/component/UIComponentBase.java
    myfaces/core/trunk/api/src/main/java/javax/faces/component/_FacetsAndChildrenIterator.java

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=648106&r1=648105&r2=648106&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 Mon Apr 14 20:08:27 2008
@@ -63,6 +63,9 @@
     private static Log log = LogFactory.getLog(UIComponentBase.class);
     
     private static final ThreadLocal _STRING_BUILDER = new ThreadLocal();
+    
+    private static final Iterator _EMPTY_UICOMPONENT_ITERATOR = 
+        new _EmptyIterator();    
 
     private _ComponentAttributesMap _attributesMap = null;
     private Map _valueBindingMap = null;
@@ -602,7 +605,39 @@
 
     public Iterator getFacetsAndChildren()
     {
-        return new _FacetsAndChildrenIterator(_facetMap, _childrenList);
+        if (_facetMap == null)
+        {
+            if (_childrenList == null)
+                return _EMPTY_UICOMPONENT_ITERATOR;
+
+            if (_childrenList.size() == 0)
+                return _EMPTY_UICOMPONENT_ITERATOR;
+            
+            return _childrenList.iterator();
+        }
+        else
+        {
+            if (_facetMap.size() == 0)
+            {
+                if (_childrenList == null)
+                    return _EMPTY_UICOMPONENT_ITERATOR;
+              
+                if (_childrenList.size() == 0)
+                    return _EMPTY_UICOMPONENT_ITERATOR;
+            
+                return _childrenList.iterator();  
+            }
+            else
+            {
+                if (_childrenList == null)
+                    return _facetMap.values().iterator();
+              
+                if (_childrenList.size() == 0)
+                    return _facetMap.values().iterator();
+              
+                return new _FacetsAndChildrenIterator(_facetMap, _childrenList);                            
+            }
+        }
     }
 
     /**

Added: myfaces/core/trunk/api/src/main/java/javax/faces/component/_EmptyIterator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_EmptyIterator.java?rev=648106&view=auto
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_EmptyIterator.java (added)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_EmptyIterator.java Mon Apr 14 20:08:27 2008
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package javax.faces.component;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+class _EmptyIterator implements Iterator
+{
+    public boolean hasNext()
+    {
+        return false;
+    }
+
+    public Object next()
+    {
+        throw new NoSuchElementException();
+    }
+
+    public void remove()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+}

Propchange: myfaces/core/trunk/api/src/main/java/javax/faces/component/_EmptyIterator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk/api/src/main/java/javax/faces/component/_EmptyIterator.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/_FacetsAndChildrenIterator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_FacetsAndChildrenIterator.java?rev=648106&r1=648105&r2=648106&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_FacetsAndChildrenIterator.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_FacetsAndChildrenIterator.java Mon Apr 14 20:08:27 2008
@@ -41,8 +41,14 @@
 
     public boolean hasNext()
     {
-        return (_facetsIterator != null && _facetsIterator.hasNext()) ||
-               (_childrenIterator != null && _childrenIterator.hasNext());
+        boolean hasNext = (_facetsIterator != null && _facetsIterator.hasNext()) ||
+        (_childrenIterator != null && _childrenIterator.hasNext());
+        if (!hasNext)
+        {
+            _facetsIterator = null;
+            _childrenIterator = null;
+        }
+        return hasNext;
     }
 
     public Object next()