1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.shortbrain.vaadin.container.property;
17
18 import java.lang.reflect.Method;
19 import java.lang.reflect.Modifier;
20 import java.util.LinkedList;
21 import java.util.List;
22
23
24
25
26
27
28
29
30 public class GetterReaderAlgorithm implements PropertyReaderAlgorithm {
31
32 public GetterReaderAlgorithm() {
33 }
34
35
36
37
38 @Override
39 public List<PropertyMetadata> getProperties(Class<?> beanClass) {
40 if (beanClass == null) {
41 throw new IllegalArgumentException("beanClass cannot be null.");
42 }
43 List<PropertyMetadata> metadatas = new LinkedList<PropertyMetadata>();
44 for (Method method : beanClass.getDeclaredMethods()) {
45 if (Modifier.isPublic(method.getModifiers())
46 && method.getName().startsWith("get")) {
47 String propertyName = method.getName().substring(3);
48 Class<?> propertyClass = method.getReturnType();
49 String propertyAttribute = propertyName;
50 PropertyMetadata metadata = new PropertyMetadata(propertyName,
51 propertyClass, null, propertyAttribute);
52 metadatas.add(metadata);
53 }
54 }
55 return metadatas;
56 }
57 }