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    public void clear() {
39      throw new UnsupportedOperationException();
40    }
41  
42    public boolean containsKey(final Object key) {
43      if (null == key) {
44        return false;
45      }
46      final String value = ResourceManagerUtils.getPropertyNotNull(
47          FacesContext.getCurrentInstance(), basename, key.toString());
48      return value != null;
49    }
50  
51    public boolean containsValue(final Object value) {
52      throw new UnsupportedOperationException();
53    }
54  
55    public Set entrySet() {
56      throw new UnsupportedOperationException();
57    }
58  
59    public Object get(final Object key) {
60      if (null == key) {
61        return null;
62      }
63      return ResourceManagerUtils.getPropertyNotNull(
64          FacesContext.getCurrentInstance(), basename, key.toString());
65    }
66  
67    public int hashCode() {
68      return basename.hashCode();
69    }
70  
71    public boolean equals(final Object o) {
72      if (this == o) {
73        return true;
74      }
75      if (o == null || getClass() != o.getClass()) {
76        return false;
77      }
78      final BundleMapWrapper that = (BundleMapWrapper) o;
79      return basename.equals(that.basename);
80    }
81  
82    public boolean isEmpty() {
83      throw new UnsupportedOperationException();
84    }
85  
86    public Set keySet() {
87      throw new UnsupportedOperationException();
88    }
89  
90    public Object put(final Object k, final Object v) {
91      throw new UnsupportedOperationException();
92    }
93  
94    public void putAll(final Map t) {
95      throw new UnsupportedOperationException();
96    }
97  
98    public Object remove(final Object k) {
99      throw new UnsupportedOperationException();
100   }
101 
102   public int size() {
103     throw new UnsupportedOperationException();
104   }
105 
106   public Collection values() {
107     throw new UnsupportedOperationException();
108   }
109 }