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