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 | 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 | |
} |