Coverage Report - javax.faces.component._ComponentFacetMap
 
Classes in this File Line Coverage Branch Coverage Complexity
_ComponentFacetMap
0%
0/45
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: slessard $)
 26  
  * @version $Revision: 701829 $ $Date: 2008-10-05 12:06:02 -0500 (Sun, 05 Oct 2008) $
 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  
 }