01: package org.andromda.maven.plugin.andromdapp;
02:
03: import java.io.File;
04: import java.util.Properties;
05:
06: import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
07:
08: /**
09: * Extends properties and allows the key to be retrieved from the given bean.
10: *
11: * @author Chad Brandon
12: */
13: public class BeanProperties extends Properties {
14: private Object bean;
15:
16: public BeanProperties(final Object bean) {
17: this .bean = bean;
18: }
19:
20: /**
21: * @see java.util.Dictionary#get(java.lang.Object)
22: */
23: public Object get(Object key) {
24: Object value = null;
25: try {
26: value = ReflectionValueExtractor.evaluate(key + "", bean);
27: // - convert file instances to strings
28: if (value instanceof File) {
29: value = ((File) value).getPath();
30: this .put(key, value);
31: }
32: } catch (Exception exception) {
33: // ignore
34: }
35: return value;
36: }
37: }
|