1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.tiles.util;
23
24 import java.beans.FeatureDescriptor;
25 import java.beans.PropertyDescriptor;
26 import java.util.ArrayList;
27 import java.util.LinkedHashMap;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Set;
31
32 import org.apache.tiles.reflect.ClassUtil;
33
34 /***
35 * Contains the bean infos about one or more classes.
36 *
37 * @version $Rev: 797905 $ $Date: 2009-07-26 13:21:31 +0200 (dom, 26 lug 2009) $
38 * @since 2.2.0
39 */
40 public class CombinedBeanInfo {
41 /***
42 * The descriptors of the introspected classes.
43 */
44 private List<FeatureDescriptor> descriptors;
45
46 /***
47 * Maps analyzed classes to the map of introspected properties.
48 */
49 private Map<Class<?>, Map<String, PropertyDescriptor>> class2descriptors;
50
51 /***
52 * Constructor.
53 * @param clazzes The list of classes to analyze and combine.
54 *
55 * @since 2.2.0
56 */
57 public CombinedBeanInfo(Class<?>... clazzes) {
58 descriptors = new ArrayList<FeatureDescriptor>();
59 class2descriptors = new LinkedHashMap<Class<?>, Map<String, PropertyDescriptor>>();
60 for (int i = 0; i < clazzes.length; i++) {
61 Class<?> clazz = clazzes[i];
62 Map<String, PropertyDescriptor> mappedDescriptors = new LinkedHashMap<String, PropertyDescriptor>();
63 ClassUtil.collectBeanInfo(clazz, mappedDescriptors);
64 descriptors.addAll(mappedDescriptors.values());
65 class2descriptors.put(clazz, mappedDescriptors);
66 }
67 }
68
69 /***
70 * Returns the descriptors of all the introspected classes.
71 *
72 * @return The feature descriptors.
73 * @since 2.2.0
74 */
75 public List<FeatureDescriptor> getDescriptors() {
76 return descriptors;
77 }
78
79 /***
80 * Returns a map of the introspected properties for the given class.
81 *
82 * @param clazz The class to get the properties from.
83 * @return The map of property descriptors.
84 * @since 2.2.0
85 */
86 public Map<String, PropertyDescriptor> getMappedDescriptors(Class<?> clazz) {
87 return class2descriptors.get(clazz);
88 }
89
90 /***
91 * Returns the set of properties for the given introspected class.
92 *
93 * @param clazz The class to get the properties from.
94 * @return The set of properties.
95 * @since 2.2.0
96 */
97 public Set<String> getProperties(Class<?> clazz) {
98 return class2descriptors.get(clazz).keySet();
99 }
100 }