1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
28
29
30 class _ComponentChildrenList
31 extends AbstractList
32 implements Serializable
33 {
34 private static final long serialVersionUID = -6775078929331154224L;
35 private UIComponent _component;
36 private List<Object> _list = new ArrayList<Object>();
37
38 _ComponentChildrenList(UIComponent component)
39 {
40 _component = component;
41 }
42
43 public Object get(int index)
44 {
45 return _list.get(index);
46 }
47
48 public int size()
49 {
50 return _list.size();
51 }
52
53 public Object set(int index, Object value)
54 {
55 checkValue(value);
56 setNewParent((UIComponent)value);
57 UIComponent child = (UIComponent) _list.set(index, value);
58 if (child != null) child.setParent(null);
59 return child;
60 }
61
62 public boolean add(Object value)
63 {
64 checkValue(value);
65 setNewParent((UIComponent)value);
66 return _list.add(value);
67 }
68
69 public void add(int index, Object value)
70 {
71 checkValue(value);
72 setNewParent((UIComponent)value);
73 _list.add(index, value);
74 }
75
76 public Object remove(int index)
77 {
78 UIComponent child = (UIComponent) _list.remove(index);
79 if (child != null) child.setParent(null);
80 return child;
81 }
82
83
84 private void setNewParent(UIComponent child)
85 {
86 UIComponent oldParent = child.getParent();
87 if (oldParent != null)
88 {
89 oldParent.getChildren().remove(child);
90 }
91 child.setParent(_component);
92 }
93
94 private void checkValue(Object value)
95 {
96 if (value == null) throw new NullPointerException("value");
97 if (!(value instanceof UIComponent)) throw new ClassCastException("value is not a UIComponent");
98 }
99
100 }