1 16 package javax.faces.component; 17 18 import java.io.Serializable ; 19 import java.util.AbstractList ; 20 import java.util.ArrayList ; 21 import java.util.List ; 22 23 34 class _ComponentChildrenList 35 extends AbstractList 36 implements Serializable 37 { 38 private UIComponent _component; 39 private List _list = new ArrayList (); 40 41 _ComponentChildrenList(UIComponent component) 42 { 43 _component = component; 44 } 45 46 public Object get(int index) 47 { 48 return _list.get(index); 49 } 50 51 public int size() 52 { 53 return _list.size(); 54 } 55 56 public Object set(int index, Object value) 57 { 58 checkValue(value); 59 setNewParent((UIComponent)value); 60 UIComponent child = (UIComponent) _list.set(index, value); 61 if (child != null) child.setParent(null); 62 return child; 63 } 64 65 public boolean add(Object value) 66 { 67 checkValue(value); 68 setNewParent((UIComponent)value); 69 return _list.add(value); 70 } 71 72 public void add(int index, Object value) 73 { 74 checkValue(value); 75 setNewParent((UIComponent)value); 76 _list.add(index, value); 77 } 78 79 public Object remove(int index) 80 { 81 UIComponent child = (UIComponent) _list.remove(index); 82 if (child != null) child.setParent(null); 83 return child; 84 } 85 86 87 private void setNewParent(UIComponent child) 88 { 89 UIComponent oldParent = child.getParent(); 90 if (oldParent != null) 91 { 92 oldParent.getChildren().remove(child); 93 } 94 child.setParent(_component); 95 } 96 97 private void checkValue(Object value) 98 { 99 if (value == null) throw new NullPointerException ("value"); 100 if (!(value instanceof UIComponent)) throw new ClassCastException ("value is not a UIComponent"); 101 } 102 103 } 104 | Popular Tags |