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