KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > faces > component > _ComponentChildrenList


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package javax.faces.component;
17
18 import java.io.Serializable JavaDoc;
19 import java.util.AbstractList JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 /**
24  * @author Manfred Geiler (latest modification by $Author: mwessendorf $)
25  * @version $Revision: 1.3 $ $Date: 2004/07/01 22:00:50 $
26  * $Log: _ComponentChildrenList.java,v $
27  * Revision 1.3 2004/07/01 22:00:50 mwessendorf
28  * ASF switch
29  *
30  * Revision 1.2 2004/03/31 12:45:01 manolito
31  * add(int index, Object value) was missing
32  *
33  */

34 class _ComponentChildrenList
35         extends AbstractList JavaDoc
36         implements Serializable JavaDoc
37 {
38     private UIComponent _component;
39     private List JavaDoc _list = new ArrayList JavaDoc();
40
41     _ComponentChildrenList(UIComponent component)
42     {
43         _component = component;
44     }
45
46     public Object JavaDoc 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 JavaDoc set(int index, Object JavaDoc 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 JavaDoc value)
66     {
67         checkValue(value);
68         setNewParent((UIComponent)value);
69         return _list.add(value);
70     }
71
72     public void add(int index, Object JavaDoc value)
73     {
74         checkValue(value);
75         setNewParent((UIComponent)value);
76         _list.add(index, value);
77     }
78
79     public Object JavaDoc 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 JavaDoc value)
98     {
99         if (value == null) throw new NullPointerException JavaDoc("value");
100         if (!(value instanceof UIComponent)) throw new ClassCastException JavaDoc("value is not a UIComponent");
101     }
102
103 }
104
Popular Tags