Home » Mojarra-2.0.1 » javax » faces » component » [javadoc | source]

    1   /*
    2    * Copyright 2004 The Apache Software Foundation.
    3    * 
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    * 
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    * 
   10    * Unless required by applicable law or agreed to in writing, software
   11    * distributed under the License is distributed on an "AS IS" BASIS,
   12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13    * See the License for the specific language governing permissions and
   14    * limitations under the License.
   15    */
   16   package javax.faces.component;
   17   
   18   import java.io.Serializable;
   19   import java.util;
   20   
   21   /**
   22    * @author Manfred Geiler (latest modification by $Author: mmarinschek $)
   23    * @version $Revision: 265006 $ $Date: 2005-08-31 06:33:56 -0400 (Wed, 31 Aug 2005) $
   24    */
   25   class _ComponentFacetMap
   26           implements Map, Serializable
   27   {
   28   	private static final long serialVersionUID = -3456937594422167629L;
   29   	private UIComponent _component;
   30       private Map _map = new HashMap();
   31   
   32       _ComponentFacetMap(UIComponent component)
   33       {
   34           _component = component;
   35       }
   36   
   37       public int size()
   38       {
   39           return _map.size();
   40       }
   41   
   42       public void clear()
   43       {
   44           _map.clear();
   45       }
   46   
   47       public boolean isEmpty()
   48       {
   49           return _map.isEmpty();
   50       }
   51   
   52       public boolean containsKey(Object key)
   53       {
   54           checkKey(key);
   55           return _map.containsKey(key);
   56       }
   57   
   58       public boolean containsValue(Object value)
   59       {
   60           checkValue(value);
   61           return _map.containsValue(value);
   62       }
   63   
   64       public Collection values()
   65       {
   66           return _map.values();
   67       }
   68   
   69       public void putAll(Map t)
   70       {
   71           for (Iterator it = t.entrySet().iterator(); it.hasNext(); )
   72           {
   73               Map.Entry entry = (Entry)it.next();
   74               put(entry.getKey(), entry.getValue());
   75           }
   76       }
   77   
   78       public Set entrySet()
   79       {
   80           return _map.entrySet();
   81       }
   82   
   83       public Set keySet()
   84       {
   85           return _map.keySet();
   86       }
   87   
   88       public Object get(Object key)
   89       {
   90           checkKey(key);
   91           return _map.get(key);
   92       }
   93   
   94       public Object remove(Object key)
   95       {
   96           checkKey(key);
   97           UIComponent facet = (UIComponent)_map.remove(key);
   98           if (facet != null) facet.setParent(null);
   99           return facet;
  100       }
  101   
  102       public Object put(Object key, Object value)
  103       {
  104           checkKey(key);
  105           checkValue(value);
  106           setNewParent((String)key, (UIComponent)value);
  107           return _map.put(key, value);
  108       }
  109   
  110   
  111       private void setNewParent(String facetName, UIComponent facet)
  112       {
  113           UIComponent oldParent = facet.getParent();
  114           if (oldParent != null)
  115           {
  116               oldParent.getFacets().remove(facetName);
  117           }
  118           facet.setParent(_component);
  119       }
  120   
  121       private void checkKey(Object key)
  122       {
  123           if (key == null) throw new NullPointerException("key");
  124           if (!(key instanceof String)) throw new ClassCastException("key is not a String");
  125       }
  126   
  127       private void checkValue(Object value)
  128       {
  129           if (value == null) throw new NullPointerException("value");
  130           if (!(value instanceof UIComponent)) throw new ClassCastException("value is not a UIComponent");
  131       }
  132   
  133   }

Home » Mojarra-2.0.1 » javax » faces » component » [javadoc | source]