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 * Date: 20.04.2006
029 * Time: 19:31:21
030 */
031 public class BundleMapWrapper implements Map {
032
033 private String basename;
034
035 public BundleMapWrapper(String basename) {
036 this.basename = basename;
037 }
038
039 public void clear() {
040 throw new UnsupportedOperationException();
041 }
042
043 public boolean containsKey(Object key) {
044 if (null == key) {
045 return false;
046 }
047 String value = ResourceManagerUtil.getPropertyNotNull(
048 FacesContext.getCurrentInstance(), basename, key.toString());
049 return value != null;
050 }
051
052 public boolean containsValue(Object value) {
053 throw new UnsupportedOperationException();
054 }
055
056 public Set entrySet() {
057 throw new UnsupportedOperationException();
058 }
059
060 public Object get(Object key) {
061 if (null == key) {
062 return null;
063 }
064 return ResourceManagerUtil.getPropertyNotNull(
065 FacesContext.getCurrentInstance(), basename, key.toString());
066 }
067
068 public int hashCode() {
069 return basename.hashCode();
070 }
071
072 public boolean equals(Object o) {
073 if (this == o) {
074 return true;
075 }
076 if (o == null || getClass() != o.getClass()) {
077 return false;
078 }
079 BundleMapWrapper that = (BundleMapWrapper) o;
080 return basename.equals(that.basename);
081 }
082
083 public boolean isEmpty() {
084 throw new UnsupportedOperationException();
085 }
086
087 public Set keySet() {
088 throw new UnsupportedOperationException();
089 }
090
091 public Object put(Object k, Object v) {
092 throw new UnsupportedOperationException();
093 }
094
095 public void putAll(Map t) {
096 throw new UnsupportedOperationException();
097 }
098
099 public Object remove(Object k) {
100 throw new UnsupportedOperationException();
101 }
102
103 public int size() {
104 throw new UnsupportedOperationException();
105 }
106
107 public Collection values() {
108 throw new UnsupportedOperationException();
109 }
110 }