001: /*
002: * Copyright 2004-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package org.springframework.binding.collection;
017:
018: import java.io.Serializable;
019: import java.util.Collection;
020: import java.util.Map;
021: import java.util.Set;
022:
023: import org.springframework.core.style.ToStringCreator;
024:
025: /**
026: * A map decorator that implements <code>SharedMap</code>. By default, simply
027: * returns the map itself as the mutex. Subclasses may override to return a
028: * different mutex object.
029: *
030: * @author Keith Donald
031: */
032: public class SharedMapDecorator implements SharedMap, Serializable {
033:
034: /**
035: * The wrapped, target map.
036: */
037: private Map map;
038:
039: /**
040: * Creates a new shared map decorator.
041: * @param map the map that is shared by multiple threads, to be synced
042: */
043: public SharedMapDecorator(Map map) {
044: this .map = map;
045: }
046:
047: // implementing Map
048:
049: public void clear() {
050: map.clear();
051: }
052:
053: public boolean containsKey(Object key) {
054: return map.containsKey(key);
055: }
056:
057: public boolean containsValue(Object value) {
058: return map.containsValue(value);
059: }
060:
061: public Set entrySet() {
062: return map.entrySet();
063: }
064:
065: public Object get(Object key) {
066: return map.get(key);
067: }
068:
069: public boolean isEmpty() {
070: return map.isEmpty();
071: }
072:
073: public Set keySet() {
074: return map.keySet();
075: }
076:
077: public Object put(Object key, Object value) {
078: return map.put(key, value);
079: }
080:
081: public void putAll(Map map) {
082: this .map.putAll(map);
083: }
084:
085: public Object remove(Object key) {
086: return map.remove(key);
087: }
088:
089: public int size() {
090: return map.size();
091: }
092:
093: public Collection values() {
094: return map.values();
095: }
096:
097: // implementing SharedMap
098:
099: public Object getMutex() {
100: return map;
101: }
102:
103: public String toString() {
104: return new ToStringCreator(this ).append("map", map).append(
105: "mutex", getMutex()).toString();
106: }
107: }
|