gt:     for (UIComponent child : getFacetsAndChildrenArray()) {
context: /*
   * Copyright (c) 1998-2010 Caucho Technology -- all rights reserved
   *
   * This file is part of Resin(R) Open Source
   *
   * Each copy or derived work must preserve the copyright notice and this
   * notice unmodified.
   *
   * Resin Open Source is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2
   * as published by the Free Software Foundation.
   *
   * Resin Open Source is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
   * of NON-INFRINGEMENT.  See the GNU General Public License for more
   * details.
   *
   * You should have received a copy of the GNU General Public License
   * along with Resin Open Source; if not, write to the
   *
   *   Free Software Foundation, Inc.
   *   59 Temple Place, Suite 330
   *   Boston, MA 02111-1307  USA
   *
   * @author Scott Ferguson
   */
  
  package javax.faces.component;
  
  import java.beans.*;
  import java.lang.reflect.*;
  import java.lang.annotation.Annotation;
  
  import java.io.*;
  import java.util.*;
  import java.util.logging.*;
  
  import javax.el.*;
  
  import javax.faces.*;
  import javax.faces.application.*;
  import javax.faces.component.html.*;
  import javax.faces.context.*;
  import javax.faces.el.*;
  import javax.faces.event.*;
  import javax.faces.render.*;
  
  public abstract class UIComponentBase extends UIComponent
  {
    private static final UIComponent []NULL_FACETS_AND_CHILDREN
      = new UIComponent[0];
    
    private static final FacesListener []NULL_FACES_LISTENERS
      = new FacesListener[0];
  
    private static final HashMap<String,Integer> _rendererToCodeMap
      = new HashMap<String,Integer>();
  
    private static final HashMap<Integer,String> _codeToRendererMap
      = new HashMap<Integer,String>();
    
    private static final WeakHashMap<Class,HashMap<String,Property>> _compMap
      = new WeakHashMap<Class,HashMap<String,Property>>();
  
    private String _id;
    private String _clientId;
  
    private UIComponent _parent;
    
    private String _rendererType;
    private ValueExpression _rendererTypeExpr;
    
    private boolean _isTransient;
    
    private Boolean _isRendered;
    private ValueExpression _isRenderedExpr;
    
    private ValueExpression _bindingExpr;
  
    private ComponentList _children;
    private ComponentMap _facets;
  
    private UIComponent []_facetsAndChildren;
  
    private AttributeMap _attributeMap;
    
  
    
    private FacesListener []_facesListeners
      = NULL_FACES_LISTENERS;
    
    public Map<String,Object> getAttributes()
    {
      if (_attributeMap == null)
        _attributeMap = new AttributeMap(this);
  
      return _attributeMap;
    }
    
    /**
     * @deprecated
     */
    public ValueBinding getValueBinding(String name)
    {
      ValueExpression expr = getValueExpression(name);
  
      if (expr == null)
        return null;
      else if (expr instanceof ValueExpressionAdapter)
        return ((ValueExpressionAdapter) expr).getBinding();
      else
        return new ValueBindingAdapter(expr);
    }
  
    /**
     * @deprecated
     */
    public void setValueBinding(String name, ValueBinding binding)
    {
      setValueExpression(name, new ValueExpressionAdapter(binding));
    }
  
    /**
     * Returns the value expression for an attribute
     *
     * @param name the name of the attribute to get
     */
    @Override
    public ValueExpression getValueExpression(String name)
    {
      if (name == null)
        throw new NullPointerException();
  
      if ("rendered".equals(name))
        return _isRenderedExpr;
      else if ("rendererType".equals(name))
        return _rendererTypeExpr;
      else if ("binding".equals(name))
        return _bindingExpr;
      
      if (bindings != null)
        return bindings.get(name);
      else
        return null;
    }
  
    /**
     * Sets the value expression for an attribute
     *
     * @param name the name of the attribute to set
     * @param expr the value expression
     */
    @Override
    public void setValueExpression(String name, ValueExpression expr)
    {
      if (name.equals("id"))
        throw new IllegalArgumentException("'id' is not a valid ValueExpression name.");
      else if (name.equals("parent"))
        throw new IllegalArgumentException("'parent' is not a valid ValueExpression name.");
      
      if ("rendered".equals(name)) {
        if (expr.isLiteralText()) {
  	_isRendered = Util.booleanValueOf(expr.getValue(null));
  	return;
        }
        else
  	_isRenderedExpr = expr;
      }
      else if ("rendererType".equals(name)) {
        if (expr.isLiteralText()) {
  	_rendererType = String.valueOf(expr.getValue(null));
  	return;
        }
        else
  	_rendererTypeExpr = expr;
      }
      else if ("binding".equals(name)) {
        _bindingExpr = expr;
      }
  
      try {
        if (expr != null) {
  	if (expr.isLiteralText()) {
  	  getAttributes().put(name, expr.getValue(null));
  	}
  	else {
  	  if (bindings == null)
  	    bindings = new HashMap<String,ValueExpression>();
  	  
  	  bindings.put(name, expr);
  	}
        }
        else if (bindings != null)
  	bindings.remove(name);
      } catch (ELException e) {
        throw new FacesException(e);
      }
    }
  
    /**
     * Returns the client-specific id for the component.
     */
    @Override
    public String getClientId(FacesContext context)
    {
      if (context == null)
        throw new NullPointerException();
  
      if (_clientId != null)
        return _clientId;
  
      String parentId = null;
  
      for (UIComponent ptr = getParent(); ptr != null; ptr = ptr.getParent()) {
        if (ptr instanceof NamingContainer) {
  	parentId = ptr.getContainerClientId(context);
  	break;
        }
      }
  
      String myId = _id;
  
      if (myId == null) {
        myId = context.getViewRoot().createUniqueId();
      }
  
      if (parentId != null)
        myId = parentId + NamingContainer.SEPARATOR_CHAR + myId;
      
      Renderer renderer = getRenderer(context);
      
      if (renderer != null)
        _clientId = renderer.convertClientId(context, myId);
      else
        _clientId = myId;
  
      return _clientId;
    }
  
    public String getId()
    {
      return _id;
    }
  
    public void setId(String id)
    {
      if (id == null) {
        _id = null;
        _clientId = null;
        return;
      }
      
      int len = id.length();
  
      if (len == 0)
        throw new IllegalArgumentException();
  
      char ch = id.charAt(0);
  
      if (! ('a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_'))
        throw new IllegalArgumentException();
  
      for (int i = 1; i < len; i++) {
        ch = id.charAt(i);
        
        if (! ('a' <= ch && ch <= 'z'
  	     || 'A' <= ch && ch <= 'Z'
  	     || '0' <= ch && ch <= '9'
  	     || ch == '_'
  	     || ch == '-'))
  	throw new IllegalArgumentException();
      }
  
      _id = id;
      _clientId = null;
    }
  
    public UIComponent getParent()
    {
      return _parent;
    }
  
    public void setParent(UIComponent parent)
    {
      _parent = parent;
    }
  
    public boolean isRendered()
    {
      if (_isRendered != null)
        return _isRendered;
      else if (_isRenderedExpr != null)
        return Util.evalBoolean(_isRenderedExpr, getFacesContext());
      else
        return true;
    }
  
    public void setRendered(boolean isRendered)
    {
      _isRendered = isRendered;
    }
  
    public String getRendererType()
    {
      if (_rendererType != null)
        return _rendererType;
      else if (_rendererTypeExpr != null)
        return Util.evalString(_rendererTypeExpr, getFacesContext());
      else
        return null;
    }
  
    public void setRendererType(String rendererType)
    {
      _rendererType = rendererType;
    }
  
    public boolean getRendersChildren()
    {
      Renderer renderer = getRenderer(getFacesContext());
  
      if (renderer != null)
        return renderer.getRendersChildren();
      else
        return false;
    }
  
    public List<UIComponent> getChildren()
    {
      if (_children == null)
        _children = new ComponentList(this);
  
      return _children;
    }
  
    public int getChildCount()
    {
      if (_children != null)
        return _children.size();
      else
        return 0;
    }
  
    public UIComponent findComponent(String expr)
    {
      UIComponent base = null;
  
      String []values = expr.split(":");
      
      if (values[0].equals("")) {
        for (base = this; base.getParent() != null; base = base.getParent()) {
        }
      }
      else {
        for (base = this;
  	   base.getParent() != null && ! (base instanceof NamingContainer);
  	   base = base.getParent()) {
        }
      }
  
      for (int i = 0; i < values.length; i++) {
        String v = values[i];
  
        if ("".equals(v))
  	continue;
  
        base = findComponent(base, v);
  
        if (i + 1 == values.length)
  	return base;
  
        if (base == null)
          return base;
  
        if (! (base instanceof NamingContainer)) {
  	throw new IllegalArgumentException("'" + v + "' in expression '" + expr + "' does not match an intermediate NamingContainer.");
        }
      }
      
      return base;
    }
  
    private static UIComponent findComponent(UIComponent comp, String id)
    {
      if (id.equals(comp.getId()))
        return comp;
  
      Iterator iter = comp.getFacetsAndChildren();
      while (iter.hasNext()) {
        UIComponent child = (UIComponent) iter.next();
  
        if (id.equals(child.getId()))
  	return child;
        
        if (! (child instanceof NamingContainer)) {
  	UIComponent desc = findComponent(child, id);
  
  	if (desc != null)
  	  return desc;
        }
      }
  
      return null;
    }
  
    public Map<String,UIComponent> getFacets()
    {
      if (_facets == null)
        _facets = new ComponentMap(this);
  
      return _facets;
    }
  
    public UIComponent getFacet(String name)
    {
      if (_facets != null)
        return _facets.get(name);
      else
        return null;
    }
  
    public Iterator<UIComponent> getFacetsAndChildren()
    {
      return new FacetAndChildIterator(getFacetsAndChildrenArray());
    }
  
    UIComponent []getFacetsAndChildrenArray()
    {
      if (_facetsAndChildren == null) {
        if (_children == null && _facets == null)
  	_facetsAndChildren = NULL_FACETS_AND_CHILDREN;
        else {
  	int facetCount = getFacetCount();
  	int childCount = getChildCount();
  	
  	_facetsAndChildren = new UIComponent[facetCount + childCount];
  
  	int i = 0;
  	if (_facets != null) {
  	  for (UIComponent facet : _facets.values()) {
  	    _facetsAndChildren[i++] = facet;
  	  }
  	}
  	
  	for (int j = 0; j < childCount; j++) {
  	  _facetsAndChildren[i++] = _children.get(j);
  	}
        }
      }
  
      return _facetsAndChildren;
    }
  
    //
    // Listeners, broadcast and event handling
    //
  
    protected void addFacesListener(FacesListener listener)
    {
      if (listener == null)
        throw new NullPointerException();
      
      int length = _facesListeners.length;
      
      FacesListener[] newListeners = new FacesListener[length + 1];
  
      System.arraycopy(_facesListeners, 0, newListeners, 0, length);
  
      newListeners[length] = listener;
  
      _facesListeners = newListeners;
    }
  
    protected FacesListener []getFacesListeners(Class cl)
    {
      if (FacesListener.class.equals(cl))
        return _facesListeners;
  
      int count = 0;
      for (int i = _facesListeners.length - 1; i >= 0; i--) {
        if (cl.isAssignableFrom(_facesListeners[i].getClass()))
  	count++;
      }
  
      FacesListener []array = (FacesListener []) Array.newInstance(cl, count);
      count = 0;
      for (int i = _facesListeners.length - 1; i >= 0; i--) {
        if (cl.isAssignableFrom(_facesListeners[i].getClass())) {
  	array[count++] = _facesListeners[i];
        }
      }
  
      return array;
    }
  
    protected void removeFacesListener(FacesListener listener)
    {
      if (listener == null)
        throw new NullPointerException();
  
      int length = _facesListeners.length;
      for (int i = 0; i < length; i++) {
        if (listener.equals(_facesListeners[i])) {
  	FacesListener []newListeners = new FacesListener[length - 1];
  	System.arraycopy(_facesListeners, 0, newListeners, 0, i);
  	System.arraycopy(_facesListeners, i + 1, newListeners, i,
  			 length - i - 1);
  
  	_facesListeners = newListeners;
  
  	return;
        }
      }
    }
  
    public void queueEvent(FacesEvent event)
    {
      UIComponent parent = getParent();
  
      if (parent != null)
        parent.queueEvent(event);
      else
        throw new IllegalStateException();
    }
  
    public void broadcast(FacesEvent event)
      throws AbortProcessingException
    {
      for (int i = 0; i < _facesListeners.length; i++) {
        if (event.isAppropriateListener(_facesListeners[i])) {
  	event.processListener(_facesListeners[i]);
        }
      }
    }
  
    //
    // decoding
    //
  
    /**
     * Recursively calls the decodes for any children, then calls
     * decode().
     */
    public void processDecodes(FacesContext context)
    {
      if (context == null)
        throw new NullPointerException();
  
      if (! isRendered())
        return;
  
      for (UIComponent child : getFacetsAndChildrenArray()) {
        child.processDecodes(context);
      }
  
      try {
        decode(context);
      } catch (RuntimeException e) {
        context.renderResponse();
  
        throw e;
      }
    }
  
    /**
     * Decodes the value of the component.
     */
    @Override
    public void decode(FacesContext context)
    {
      Renderer renderer = getRenderer(context);
  
      if (renderer != null)
        renderer.decode(context, this);
    }
  
    //
    // Validation
    //
  
    @Override
    public void processValidators(FacesContext context)
    {
      if (context == null)
        throw new NullPointerException();
  
      if (! isRendered())
        return;
  
      for (UIComponent child : getFacetsAndChildrenArray()) {
        child.processValidators(context);
      }
    }
  
    //
    // Model updates
    //
  
    public void processUpdates(FacesContext context)
    {
      if (context == null)
        throw new NullPointerException();
  
      if (! isRendered())
        return;
  
  