KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
20
21 /**
22  * @author Manfred Geiler (latest modification by $Author: mwessendorf $)
23  * @version $Revision: 1.3 $ $Date: 2004/07/01 22:00:50 $
24  */

25 class _ComponentFacetMap
26         implements Map, Serializable JavaDoc
27 {
28     private UIComponent _component;
29     private Map _map = new HashMap();
30
31     _ComponentFacetMap(UIComponent component)
32     {
33         _component = component;
34     }
35
36     public int size()
37     {
38         return _map.size();
39     }
40
41     public void clear()
42     {
43         _map.clear();
44     }
45
46     public boolean isEmpty()
47     {
48         return _map.isEmpty();
49     }
50
51     public boolean containsKey(Object JavaDoc key)
52     {
53         checkKey(key);
54         return _map.containsKey(key);
55     }
56
57     public boolean containsValue(Object JavaDoc value)
58     {
59         checkValue(value);
60         return false;
61     }
62
63     public Collection values()
64     {
65         return _map.values();
66     }
67
68     public void putAll(Map t)
69     {
70         for (Iterator it = t.entrySet().iterator(); it.hasNext(); )
71         {
72             Map.Entry entry = (Entry)it.next();
73             put(entry.getKey(), entry.getValue());
74         }
75     }
76
77     public Set entrySet()
78     {
79         return _map.entrySet();
80     }
81
82     public Set keySet()
83     {
84         return _map.keySet();
85     }
86
87     public Object JavaDoc get(Object JavaDoc key)
88     {
89         checkKey(key);
90         return _map.get(key);
91     }
92
93     public Object JavaDoc remove(Object JavaDoc key)
94     {
95         checkKey(key);
96         UIComponent facet = (UIComponent)_map.remove(key);
97         if (facet != null) facet.setParent(null);
98         return facet;
99     }
100
101     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value)
102     {
103         checkKey(key);
104         checkValue(value);
105         setNewParent((String JavaDoc)key, (UIComponent)value);
106         return _map.put(key, value);
107     }
108
109
110     private void setNewParent(String JavaDoc facetName, UIComponent facet)
111     {
112         UIComponent oldParent = facet.getParent();
113         if (oldParent != null)
114         {
115             oldParent.getFacets().remove(facetName);
116         }
117         facet.setParent(_component);
118     }
119
120     private void checkKey(Object JavaDoc key)
121     {
122         if (key == null) throw new NullPointerException JavaDoc("key");
123         if (!(key instanceof String JavaDoc)) throw new ClassCastException JavaDoc("key is not a String");
124     }
125
126     private void checkValue(Object JavaDoc value)
127     {
128         if (value == null) throw new NullPointerException JavaDoc("value");
129         if (!(value instanceof UIComponent)) throw new ClassCastException JavaDoc("value is not a UIComponent");
130     }
131
132 }
133
Popular Tags