001 package org.springframework.richclient.widget.table; 002 import java.lang.reflect.InvocationTargetException; 003 import java.lang.reflect.Method; 004 005 /** 006 * Basic implementation of a {@link Writer}. 007 * 008 * @author Jan Hoskens 009 * @since 0.5.0 010 */ 011 public class SimpleWriter extends SimpleAccessor implements Writer 012 { 013 014 /** Setter method for the property. */ 015 private Method writeMethod; 016 017 /** 018 * Constructor. Uses the return type of the getter to find a matching setter. 019 * 020 * @param beanClass 021 * the type of the bean. 022 * @param propertyName 023 * name of the property. 024 * @see SimpleAccessor#SimpleAccessor(Class, String) 025 */ 026 public SimpleWriter(Class<?> beanClass, String propertyName) 027 { 028 super(beanClass, propertyName); 029 writeMethod = ClassUtils.getWriteMethod(beanClass, propertyName, getPropertyType()); 030 } 031 032 /** 033 * {@inheritDoc} 034 */ 035 public void setValue(Object toEntity, Object newValue) throws IllegalAccessException, 036 InvocationTargetException 037 { 038 writeMethod.invoke(toEntity, new Object[]{newValue}); 039 } 040 041 }