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