001    package org.apache.myfaces.tobago.util;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import org.apache.myfaces.tobago.context.ResourceManagerUtil;
021    
022    import javax.faces.context.FacesContext;
023    import java.util.Map;
024    import java.util.Set;
025    import java.util.Collection;
026    
027    /*
028     * Created by IntelliJ IDEA.
029     * User: bommel
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    }