View Javadoc

1   package com.vaadin.data.util;
2   
3   import com.vaadin.data.Property;
4   
5   /**
6    * Property descriptor that is able to create shortcut property instances for a bean (nested or not).
7    * 
8    * The property path is specified in the dotted notation, e.g. "address.street", and can contain multiple levels of nesting. The property
9    * name can be anything (but a String).
10   * 
11   * @param <BT>
12   *            bean type
13   * 
14   * @author Vincent Demeester <vincent.demeester@xgbi.fr>
15   * 
16   * @since 0.2.0
17   * 
18   * @see NestedPropertyDescriptor
19   */
20  public class ShortcutPropertyDescriptor<BT> implements VaadinPropertyDescriptor<BT> {
21  
22      private static final long serialVersionUID = -724628501672480236L;
23  
24      private final String name;
25      private final String path;
26      private final Class<?> propertyType;
27  
28      /**
29       * Create a {@link ShortcutPropertyDescriptor}.
30       * 
31       * @param name
32       *            The given name of the property
33       * @param path
34       *            The path of the real property
35       * @param beanType
36       *            the type of bean to look for this property
37       */
38      public ShortcutPropertyDescriptor(String name, String path, Class<BT> beanType) {
39          this.name = name;
40          this.path = path;
41          NestedMethodProperty property = new NestedMethodProperty(beanType, path);
42          this.propertyType = property.getType();
43      }
44  
45      @Override
46      public String getName() {
47          return name;
48      }
49  
50      @Override
51      public Class<?> getPropertyType() {
52          return propertyType;
53      }
54  
55      @Override
56      public Property createProperty(BT bean) {
57          return new NestedMethodProperty(bean, path);
58      }
59  
60  }