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.Iterator;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.RandomAccess;
28
29
30
31
32
33 class _ComponentChildrenList extends AbstractList<UIComponent> implements Serializable, RandomAccess
34 {
35 private static final long serialVersionUID = -6775078929331154224L;
36 private UIComponent _component;
37 private List<UIComponent> _list = new ArrayList<UIComponent>(4);
38
39 _ComponentChildrenList(UIComponent component)
40 {
41 _component = component;
42 }
43
44 @Override
45 public UIComponent get(int index)
46 {
47 return _list.get(index);
48 }
49
50 @Override
51 public int size()
52 {
53 return _list.size();
54 }
55
56 @Override
57 public UIComponent set(int index, UIComponent value)
58 {
59 checkValue(value);
60 removeChildrenFromParent(value);
61 UIComponent child = _list.set(index, value);
62 if (child != value)
63 {
64 updateParent(value);
65 if (child != null)
66 {
67 childRemoved(child);
68 }
69 }
70
71 return child;
72 }
73
74 @Override
75 public boolean add(UIComponent value)
76 {
77 checkValue(value);
78
79 removeChildrenFromParent(value);
80 boolean res = _list.add(value);
81
82 updateParent(value);
83
84 return res;
85 }
86
87 @Override
88 public void add(int index, UIComponent value)
89 {
90 checkValue(value);
91
92 removeChildrenFromParent(value);
93
94 _list.add(index, value);
95
96 updateParent(value);
97 }
98
99 @Override
100 public UIComponent remove(int index)
101 {
102 UIComponent child = _list.remove(index);
103 if (child != null)
104 {
105 childRemoved(child);
106 }
107
108 return child;
109 }
110
111 private void checkValue(Object value)
112 {
113 if (value == null)
114 {
115 throw new NullPointerException("value");
116 }
117
118
119
120
121
122
123 }
124
125 private void childRemoved(UIComponent child)
126 {
127 child.setParent(null);
128 }
129
130 private void updateParent(UIComponent child)
131 {
132 child.setParent(_component);
133 }
134
135 private void removeChildrenFromParent(UIComponent child)
136 {
137 UIComponent oldParent = child.getParent();
138 if (oldParent != null)
139 {
140 if (!oldParent.getChildren().remove(child))
141 {
142
143 if (oldParent.getFacetCount() > 0)
144 {
145 for (Iterator< Map.Entry<String, UIComponent > > it =
146 oldParent.getFacets().entrySet().iterator() ; it.hasNext() ; )
147 {
148 Map.Entry<String, UIComponent > entry = it.next();
149
150 if (entry.getValue().equals(child))
151 {
152 it.remove();
153 break;
154 }
155 }
156 }
157 }
158 }
159 }
160
161 @Override
162 public boolean remove(Object value)
163 {
164 if (!(value instanceof UIComponent))
165 {
166 throw new ClassCastException("value is not a UIComponent");
167 }
168
169 checkValue(value);
170
171 if (_list.remove(value))
172 {
173 childRemoved((UIComponent)value);
174 return true;
175 }
176 return false;
177 }
178 }