001 package org.springframework.richclient.widget.table;
002
003 import java.lang.reflect.InvocationTargetException;
004 import java.lang.reflect.Method;
005
006 /**
007 * Basic implementation of an {@link Accessor}.
008 *
009 * @author Jan Hoskens
010 * @since 0.5.0
011 */
012 public class SimpleAccessor implements Accessor
013 {
014
015 /** The getter method. */
016 private final Method accessor;
017
018 /**
019 * Constructor. Retrieves the getter of the given property.
020 *
021 * @param clazz
022 * the type of the entity.
023 * @param propertyName
024 * name of the property.
025 */
026 public SimpleAccessor(Class<?> clazz, String propertyName)
027 {
028 this.accessor = ClassUtils.getReadMethod(clazz, propertyName);
029 if (accessor == null)
030 throw new IllegalArgumentException("propertyName " + propertyName
031 + " does not represent a readable property.");
032 }
033
034 /**
035 * {@inheritDoc}
036 */
037 public Object getValue(Object fromEntity) throws IllegalAccessException, InvocationTargetException
038 {
039 return accessor.invoke(fromEntity);
040 }
041
042 /**
043 * {@inheritDoc}
044 */
045 public Class<?> getPropertyType()
046 {
047 return ClassUtils.getTypeForProperty(accessor);
048 }
049
050 }