Coverage Report - javax.faces.component._ComponentFacetMap
 
Classes in this File Line Coverage Branch Coverage Complexity
_ComponentFacetMap
0%
0/42
0%
0/14
0
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package javax.faces.component;
 20  
 
 21  
 import java.io.Serializable;
 22  
 import java.util.*;
 23  
 
 24  
 /**
 25  
  * @author Manfred Geiler (latest modification by $Author: skitching $)
 26  
  * @version $Revision: 676298 $ $Date: 2008-07-13 05:31:48 -0500 (Sun, 13 Jul 2008) $
 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  
 }