| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package javax.faces.internal; |
| 17 | |
|
| 18 | |
import java.io.Serializable; |
| 19 | |
import java.util.Collection; |
| 20 | |
import java.util.HashMap; |
| 21 | |
import java.util.Iterator; |
| 22 | |
import java.util.Map; |
| 23 | |
import java.util.Set; |
| 24 | |
|
| 25 | |
import javax.faces.component.UIComponent; |
| 26 | |
|
| 27 | |
import org.seasar.framework.util.AssertionUtil; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
public class ComponentFacetMapWrapper implements Map, Serializable { |
| 36 | |
|
| 37 | |
private static final long serialVersionUID = 3977016266726585651L; |
| 38 | |
|
| 39 | 423 | private UIComponent parent = null; |
| 40 | |
|
| 41 | 423 | private Map facetMap = new HashMap(); |
| 42 | |
|
| 43 | 423 | public ComponentFacetMapWrapper(UIComponent parent) { |
| 44 | 423 | this.parent = parent; |
| 45 | 423 | } |
| 46 | |
|
| 47 | |
public int size() { |
| 48 | 172 | return facetMap.size(); |
| 49 | |
} |
| 50 | |
|
| 51 | |
public void clear() { |
| 52 | 0 | facetMap.clear(); |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
public boolean isEmpty() { |
| 56 | 5 | return facetMap.isEmpty(); |
| 57 | |
} |
| 58 | |
|
| 59 | |
public boolean containsKey(Object key) { |
| 60 | 0 | return facetMap.containsKey(key); |
| 61 | |
} |
| 62 | |
|
| 63 | |
public boolean containsValue(Object value) { |
| 64 | 0 | return facetMap.containsValue(value); |
| 65 | |
} |
| 66 | |
|
| 67 | |
public Collection values() { |
| 68 | 175 | return facetMap.values(); |
| 69 | |
} |
| 70 | |
|
| 71 | |
public Set entrySet() { |
| 72 | 53 | return facetMap.entrySet(); |
| 73 | |
} |
| 74 | |
|
| 75 | |
public Set keySet() { |
| 76 | 18 | return facetMap.keySet(); |
| 77 | |
} |
| 78 | |
|
| 79 | |
public Object get(Object key) { |
| 80 | 331 | return facetMap.get(key); |
| 81 | |
} |
| 82 | |
|
| 83 | |
public Object remove(Object key) { |
| 84 | 0 | UIComponent facet = (UIComponent) facetMap.remove(key); |
| 85 | 0 | if (facet != null) { |
| 86 | 0 | facet.setParent(null); |
| 87 | |
} |
| 88 | 0 | return facet; |
| 89 | |
} |
| 90 | |
|
| 91 | |
public Object put(Object key, Object facet) { |
| 92 | 381 | AssertionUtil.assertNotNull("key", key); |
| 93 | 381 | AssertionUtil.assertNotNull("facet", facet); |
| 94 | 381 | checkKeyClass(key); |
| 95 | 381 | checkValueClass(facet); |
| 96 | 381 | setNewParent((String) key, (UIComponent) facet); |
| 97 | 381 | return facetMap.put(key, facet); |
| 98 | |
} |
| 99 | |
|
| 100 | |
public void putAll(Map map) { |
| 101 | 0 | for (Iterator itr = map.entrySet().iterator(); itr.hasNext();) { |
| 102 | 0 | Map.Entry entry = (Map.Entry) itr.next(); |
| 103 | 0 | put(entry.getKey(), entry.getValue()); |
| 104 | |
} |
| 105 | 0 | } |
| 106 | |
|
| 107 | |
private void setNewParent(String facetName, UIComponent facet) { |
| 108 | 381 | UIComponent oldParent = facet.getParent(); |
| 109 | 381 | if (oldParent != null) { |
| 110 | 0 | oldParent.getFacets().remove(facetName); |
| 111 | |
} |
| 112 | 381 | facet.setParent(parent); |
| 113 | 381 | } |
| 114 | |
|
| 115 | |
private static void checkKeyClass(Object key) { |
| 116 | 381 | if (!(key instanceof String)) { |
| 117 | 0 | throw new ClassCastException("key"); |
| 118 | |
} |
| 119 | 381 | } |
| 120 | |
|
| 121 | |
private static void checkValueClass(Object value) { |
| 122 | 381 | if (!(value instanceof UIComponent)) { |
| 123 | 0 | throw new ClassCastException("value"); |
| 124 | |
} |
| 125 | 381 | } |
| 126 | |
|
| 127 | |
} |