1 /*
2 * $Id: CombinedBeanInfo.java 995228 2010-09-08 19:50:09Z apetrelli $
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
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.request.reflect.ClassUtil;
33
34 /**
35 * Contains the bean infos about one or more classes.
36 *
37 * @version $Rev: 995228 $ $Date: 2010-09-09 05:50:09 +1000 (Thu, 09 Sep 2010) $
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 }