Coverage Report - javax.faces.component._ComponentChildrenList
 
Classes in this File Line Coverage Branch Coverage Complexity
_ComponentChildrenList
0%
0/29
0%
0/10
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package javax.faces.component;
 20  
 
 21  
 import java.io.Serializable;
 22  
 import java.util.AbstractList;
 23  
 import java.util.ArrayList;
 24  
 import java.util.List;
 25  
 
 26  
 /**
 27  
  * @author Manfred Geiler (latest modification by $Author: skitching $)
 28  
  * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Sun, 13 Jul 2008) $
 29  
  */
 30  
 class _ComponentChildrenList
 31  
         extends AbstractList
 32  
         implements Serializable
 33  
 {
 34  
     private static final long serialVersionUID = -6775078929331154224L;
 35  
     private UIComponent _component;
 36  0
     private List<Object> _list = new ArrayList<Object>();
 37  
 
 38  
     _ComponentChildrenList(UIComponent component)
 39  0
     {
 40  0
         _component = component;
 41  0
     }
 42  
 
 43  
     public Object get(int index)
 44  
     {
 45  0
         return _list.get(index);
 46  
     }
 47  
 
 48  
     public int size()
 49  
     {
 50  0
         return _list.size();
 51  
     }
 52  
 
 53  
     public Object set(int index, Object value)
 54  
     {
 55  0
         checkValue(value);
 56  0
         setNewParent((UIComponent)value);
 57  0
         UIComponent child = (UIComponent) _list.set(index, value);
 58  0
         if (child != null) child.setParent(null);
 59  0
         return child;
 60  
     }
 61  
 
 62  
     public boolean add(Object value)
 63  
     {
 64  0
         checkValue(value);
 65  0
         setNewParent((UIComponent)value);
 66  0
         return _list.add(value);
 67  
     }
 68  
 
 69  
     public void add(int index, Object value)
 70  
     {
 71  0
         checkValue(value);
 72  0
         setNewParent((UIComponent)value);
 73  0
         _list.add(index, value);
 74  0
     }
 75  
 
 76  
     public Object remove(int index)
 77  
     {
 78  0
         UIComponent child = (UIComponent) _list.remove(index);
 79  0
         if (child != null) child.setParent(null);
 80  0
         return child;
 81  
     }
 82  
 
 83  
 
 84  
     private void setNewParent(UIComponent child)
 85  
     {
 86  0
         UIComponent oldParent = child.getParent();
 87  0
         if (oldParent != null)
 88  
         {
 89  0
             oldParent.getChildren().remove(child);
 90  
         }
 91  0
         child.setParent(_component);
 92  0
     }
 93  
 
 94  
     private void checkValue(Object value)
 95  
     {
 96  0
         if (value == null) throw new NullPointerException("value");
 97  0
         if (!(value instanceof UIComponent)) throw new ClassCastException("value is not a UIComponent");
 98  0
     }
 99  
 
 100  
 }