001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *   http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    
020    package org.apache.myfaces.tobago.util;
021    
022    import org.apache.myfaces.tobago.context.ResourceManagerUtil;
023    
024    import javax.faces.context.FacesContext;
025    import java.util.Map;
026    import java.util.Set;
027    import java.util.Collection;
028    
029    /*
030     * Date: 20.04.2006
031     * Time: 19:31:21
032     */
033    public class BundleMapWrapper implements Map {
034    
035      private String basename;
036    
037      public BundleMapWrapper(String basename) {
038        this.basename = basename;
039      }
040    
041      public void clear() {
042        throw new UnsupportedOperationException();
043      }
044    
045      public boolean containsKey(Object key) {
046        if (null == key) {
047          return false;
048        }
049        String value = ResourceManagerUtil.getPropertyNotNull(
050            FacesContext.getCurrentInstance(), basename, key.toString());
051        return value != null;
052      }
053    
054      public boolean containsValue(Object value) {
055        throw new UnsupportedOperationException();
056      }
057    
058      public Set entrySet() {
059        throw new UnsupportedOperationException();
060      }
061    
062      public Object get(Object key) {
063        if (null == key) {
064          return null;
065        }
066        return ResourceManagerUtil.getPropertyNotNull(
067            FacesContext.getCurrentInstance(), basename, key.toString());
068      }
069    
070      public int hashCode() {
071        return basename.hashCode();
072      }
073    
074      public boolean equals(Object o) {
075        if (this == o) {
076          return true;
077        }
078        if (o == null || getClass() != o.getClass()) {
079          return false;
080        }
081        BundleMapWrapper that = (BundleMapWrapper) o;
082        return basename.equals(that.basename);
083      }
084    
085      public boolean isEmpty() {
086        throw new UnsupportedOperationException();
087      }
088    
089      public Set keySet() {
090        throw new UnsupportedOperationException();
091      }
092    
093      public Object put(Object k, Object v) {
094        throw new UnsupportedOperationException();
095      }
096    
097      public void putAll(Map t) {
098        throw new UnsupportedOperationException();
099      }
100    
101      public Object remove(Object k) {
102        throw new UnsupportedOperationException();
103      }
104    
105      public int size() {
106        throw new UnsupportedOperationException();
107      }
108    
109      public Collection values() {
110        throw new UnsupportedOperationException();
111      }
112    }