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