001 /*
002 * Copyright 2004-2005 the original author or authors.
003 */
004 package org.springframework.binding.value.support;
005
006 import java.util.Map;
007
008 import org.springframework.binding.value.ValueModel;
009
010 /**
011 *
012 * @author HP
013 */
014 public class MapKeyAdapter extends AbstractValueModel {
015
016 private ValueModel mapValueModel;
017
018 private Object key;
019
020 public MapKeyAdapter(ValueModel valueModel, Object key) {
021 super();
022 this.mapValueModel = valueModel;
023 setKey(key);
024 }
025
026 public void setKey(Object key) {
027 this.key = key;
028 }
029
030 public Object getValue() {
031 Map map = (Map)mapValueModel.getValue();
032 if (map == null) {
033 return null;
034 }
035 return map.get(key);
036 }
037
038 public void setValue(Object value) {
039 Map map = (Map)mapValueModel.getValue();
040 if (map == null) {
041 return;
042 }
043 map.put(key, value);
044 }
045
046 }