1 16 package javax.faces.component; 17 18 import java.io.Serializable ; 19 import java.util.*; 20 21 25 class _ComponentFacetMap 26 implements Map, Serializable 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 key) 52 { 53 checkKey(key); 54 return _map.containsKey(key); 55 } 56 57 public boolean containsValue(Object 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 get(Object key) 88 { 89 checkKey(key); 90 return _map.get(key); 91 } 92 93 public Object remove(Object 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 put(Object key, Object value) 102 { 103 checkKey(key); 104 checkValue(value); 105 setNewParent((String )key, (UIComponent)value); 106 return _map.put(key, value); 107 } 108 109 110 private void setNewParent(String 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 key) 121 { 122 if (key == null) throw new NullPointerException ("key"); 123 if (!(key instanceof String )) throw new ClassCastException ("key is not a String"); 124 } 125 126 private void checkValue(Object value) 127 { 128 if (value == null) throw new NullPointerException ("value"); 129 if (!(value instanceof UIComponent)) throw new ClassCastException ("value is not a UIComponent"); 130 } 131 132 } 133 | Popular Tags |