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  
20  package org.apache.myfaces.tobago.util;
21  
22  import org.apache.myfaces.tobago.context.ResourceManagerUtils;
23  
24  import javax.faces.context.FacesContext;
25  import java.io.Serializable;
26  import java.util.Collection;
27  import java.util.Map;
28  import java.util.Set;
29  
30  public class BundleMapWrapper implements Map, Serializable {
31  
32    private String basename;
33  
34    public BundleMapWrapper(final String basename) {
35      this.basename = basename;
36    }
37  
38    @Override
39    public void clear() {
40      throw new UnsupportedOperationException();
41    }
42  
43    @Override
44    public boolean containsKey(final Object key) {
45      if (null == key) {
46        return false;
47      }
48      final String value = ResourceManagerUtils.getPropertyNotNull(
49          FacesContext.getCurrentInstance(), basename, key.toString());
50      return value != null;
51    }
52  
53    @Override
54    public boolean containsValue(final Object value) {
55      throw new UnsupportedOperationException();
56    }
57  
58    @Override
59    public Set entrySet() {
60      throw new UnsupportedOperationException();
61    }
62  
63    @Override
64    public Object get(final Object key) {
65      if (null == key) {
66        return null;
67      }
68      return ResourceManagerUtils.getPropertyNotNull(
69          FacesContext.getCurrentInstance(), basename, key.toString());
70    }
71  
72    public int hashCode() {
73      return basename.hashCode();
74    }
75  
76    public boolean equals(final Object o) {
77      if (this == o) {
78        return true;
79      }
80      if (o == null || getClass() != o.getClass()) {
81        return false;
82      }
83      final BundleMapWrapper that = (BundleMapWrapper) o;
84      return basename.equals(that.basename);
85    }
86  
87    @Override
88    public boolean isEmpty() {
89      throw new UnsupportedOperationException();
90    }
91  
92    @Override
93    public Set keySet() {
94      throw new UnsupportedOperationException();
95    }
96  
97    @Override
98    public Object put(final Object k, final Object v) {
99      throw new UnsupportedOperationException();
100   }
101 
102   @Override
103   public void putAll(final Map t) {
104     throw new UnsupportedOperationException();
105   }
106 
107   @Override
108   public Object remove(final Object k) {
109     throw new UnsupportedOperationException();
110   }
111 
112   @Override
113   public int size() {
114     throw new UnsupportedOperationException();
115   }
116 
117   @Override
118   public Collection values() {
119     throw new UnsupportedOperationException();
120   }
121 }