001 /* 002 * BeanPropertyKeyProvider.java 003 * 004 * Created on February 4, 2007, 12:53 PM 005 */ 006 007 package net.sf.tacos.model.impl; 008 009 import java.io.Serializable; 010 import net.sf.tacos.model.IKeyProvider; 011 012 import org.apache.commons.beanutils.BeanUtils; 013 014 /** 015 * Key provider that uses a property of the object as a key. 016 * 017 * @author andyhot 018 */ 019 public class BeanPropertyKeyProvider implements IKeyProvider { 020 021 private String property; 022 023 public BeanPropertyKeyProvider(String property) { 024 this.property = property; 025 } 026 027 public Serializable getKey(Object obj) { 028 try { 029 return BeanUtils.getProperty(obj, property); 030 } catch (Exception e) { 031 throw new RuntimeException("Error getting property", e); 032 } 033 } 034 035 }