001package org.andromda.maven.plugin.configuration; 002 003import java.io.File; 004import java.util.Properties; 005import org.codehaus.plexus.util.introspection.ReflectionValueExtractor; 006 007/** 008 * Extends properties and allows the key to be retrieved from the given bean. 009 * 010 * @author Chad Brandon 011 */ 012public class BeanProperties 013 extends Properties 014{ 015 private static final long serialVersionUID = 34L; 016 private Object bean; 017 018 /** 019 * @param bean 020 */ 021 public BeanProperties(final Object bean) 022 { 023 this.bean = bean; 024 } 025 026 /** 027 * @see java.util.Dictionary#get(Object) 028 */ 029 public synchronized Object get(Object key) 030 { 031 Object value = null; 032 try 033 { 034 value = ReflectionValueExtractor.evaluate( 035 String.valueOf(key), 036 bean); 037 // - convert file instances to strings 038 if (value instanceof File) 039 { 040 value = ((File)value).getPath(); 041 this.put(key, value); 042 } 043 } 044 catch (Exception exception) 045 { 046 // ignore 047 } 048 return value; 049 } 050}