/******************************************************************************* * Copyright (c) 2012, 2013 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.g3d.property; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; public class MethodWithMapValueProvider implements ValueProvider { Method getter; Method setter; String key; public MethodWithMapValueProvider(Method getter, Method setter, String key) { this.getter = getter; this.setter = setter; this.key = key; } @Override public Object getValue(Object obj) throws Exception{ Map map = (Map)getter.invoke(obj); return map.get(key); } @Override public void setValue(Object obj, Object value) throws Exception { Map map = new HashMap(); map.putAll((Map)getter.invoke(obj)); map.put(key, value); setter.invoke(obj,map); } }