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.*;
23
24
25
26
27
28 class _ComponentChildrenList
29 extends AbstractList
30 implements Serializable
31 {
32 private static final long serialVersionUID = -6775078929331154224L;
33 private UIComponent _component;
34 private List _list = new ArrayList();
35 private Map _idIndexedMap = new HashMap();
36
37 _ComponentChildrenList(UIComponent component)
38 {
39 _component = component;
40 }
41
42 public UIComponent get(String id) {
43 return (UIComponent) _idIndexedMap.get(id);
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 resetParent(child);
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 resetParent(child);
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 _idIndexedMap.put(child.getId(),child);
96 }
97
98 private void resetParent(UIComponent child) {
99 if (child != null)
100 child.setParent(null);
101 _idIndexedMap.remove(child.getId());
102 }
103
104 private void checkValue(Object value)
105 {
106 if (value == null) throw new NullPointerException("value");
107 if (!(value instanceof UIComponent)) throw new ClassCastException("value is not a UIComponent");
108 }
109
110 public void updateId(String oldId, UIComponent component) {
111 _idIndexedMap.remove(oldId);
112 _idIndexedMap.put(component.getId(), component);
113 }
114 }