View Javadoc
1   package org.andromda.maven.plugin.andromdapp;
2   
3   import java.io.File;
4   import java.util.Properties;
5   import org.codehaus.plexus.util.introspection.ReflectionValueExtractor;
6   
7   /**
8    * Extends properties and allows the key to be retrieved from the given bean.
9    *
10   * @author Chad Brandon
11   */
12  public class BeanProperties
13      extends Properties
14  {
15      private static final long serialVersionUID = 34L;
16      private Object bean;
17  
18      /**
19       * @param bean
20       */
21      public BeanProperties(final Object bean)
22      {
23          this.bean = bean;
24      }
25  
26      /**
27       * @see java.util.Dictionary#get(Object)
28       */
29      public synchronized Object get(Object key)
30      {
31          Object value = null;
32          try
33          {
34              value = ReflectionValueExtractor.evaluate(
35                      String.valueOf(key),
36                      bean);
37              // - convert file instances to strings
38              if (value instanceof File)
39              {
40                  value = ((File)value).getPath();
41                  this.put(key, value);
42              }
43          }
44          catch (Exception exception)
45          {
46              // ignore
47          }
48          return value;
49      }
50  }