View Javadoc

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.Collection;
23  import java.util.Map;
24  import java.util.Map.Entry;
25  import java.util.Set;
26  
27  /**
28   *
29   * @author Leonardo Uribe
30   */
31  class _ViewAttributeMap implements Map<String, Object>, Serializable
32  {
33      private static final long serialVersionUID = -9106832109394257866L;
34  
35      //private static final String RESET_SAVE_STATE_MODE_KEY = 
36      //        "oam.view.resetSaveStateMode";
37  
38      /**
39       * Key under UIViewRoot to generated unique ids for components added 
40       * by @ResourceDependency effect.
41       */
42      private static final String RESOURCE_DEPENDENCY_UNIQUE_ID_KEY =
43                "oam.view.resourceDependencyUniqueId";
44      private static final String UNIQUE_ID_COUNTER_KEY =
45                "oam.view.uniqueIdCounter";
46      
47      private Map<String, Object> _delegate;
48      private UIViewRoot _root;
49  
50      public _ViewAttributeMap(UIViewRoot root, Map<String, Object> delegate)
51      {
52          this._delegate = delegate;
53          this._root = root;
54      }
55  
56      public int size()
57      {
58          return _delegate.size();
59      }
60  
61      public boolean isEmpty()
62      {
63          return _delegate.isEmpty();
64      }
65  
66      public boolean containsKey(Object key)
67      {
68          return _delegate.containsKey(key);
69      }
70  
71      public boolean containsValue(Object value)
72      {
73          return _delegate.containsValue(value);
74      }
75  
76      public Object get(Object key)
77      {
78          checkKey(key);
79          int keyLength = ((String)key).length();
80          /*
81          if (RESET_SAVE_STATE_MODE_KEY.length() == keyLength
82              && RESET_SAVE_STATE_MODE_KEY.equals(key))
83          {
84              return _root.getResetSaveStateMode();
85          }*/
86          if (RESOURCE_DEPENDENCY_UNIQUE_ID_KEY.length() == keyLength
87              && RESOURCE_DEPENDENCY_UNIQUE_ID_KEY.equals(key))
88          {
89              return _root.isResourceDependencyUniqueId();
90          }
91          if (UNIQUE_ID_COUNTER_KEY.length() == keyLength
92              && UNIQUE_ID_COUNTER_KEY.equals(key))
93          {
94              return _root.getStateHelper().get(UIViewRoot.PropertyKeys.uniqueIdCounter);
95          }
96          return _delegate.get(key);
97      }
98  
99      public Object put(String key, Object value)
100     {
101         int keyLength = ((String)key).length();
102 
103         /*
104         if (RESET_SAVE_STATE_MODE_KEY.length() == keyLength
105             && RESET_SAVE_STATE_MODE_KEY.equals(key))
106         {
107             Integer b = _root.getResetSaveStateMode();
108             _root.setResetSaveStateMode(value == null ? 0 : (Integer) value);
109             return b;
110         }*/
111         if (RESOURCE_DEPENDENCY_UNIQUE_ID_KEY.length() == keyLength
112             && RESOURCE_DEPENDENCY_UNIQUE_ID_KEY.equals(key))
113         {
114             boolean b = _root.isResourceDependencyUniqueId();
115             _root.setResourceDependencyUniqueId(value == null ? false : (Boolean) value);
116             return b;
117         }
118         if (UNIQUE_ID_COUNTER_KEY.length() == keyLength
119             && UNIQUE_ID_COUNTER_KEY.equals(key))
120         {
121             Long v = (Long) _root.getStateHelper().get(UIViewRoot.PropertyKeys.uniqueIdCounter);
122             _root.getStateHelper().put(UIViewRoot.PropertyKeys.uniqueIdCounter, value);
123             return v;
124         }
125         return _delegate.put(key, value);
126     }
127 
128     public Object remove(Object key)
129     {
130         return _delegate.remove(key);
131     }
132 
133     public void putAll(Map<? extends String, ? extends Object> m)
134     {
135         _delegate.putAll(m);
136     }
137 
138     public void clear()
139     {
140         _delegate.clear();
141     }
142 
143     public Set<String> keySet()
144     {
145         return _delegate.keySet();
146     }
147 
148     public Collection<Object> values()
149     {
150         return _delegate.values();
151     }
152 
153     public Set<Entry<String, Object>> entrySet()
154     {
155         return _delegate.entrySet();
156     }
157 
158     public boolean equals(Object o)
159     {
160         return _delegate.equals(o);
161     }
162 
163     public int hashCode()
164     {
165         return _delegate.hashCode();
166     }
167 
168     public String toString()
169     {
170         return _delegate.toString();
171     }
172     
173     private void checkKey(Object key)
174     {
175         if (key == null)
176         {
177             throw new NullPointerException("key");
178         }
179         if (!(key instanceof String))
180         {
181             throw new ClassCastException("key is not a String");
182         }
183     }
184 }