1/*2 * $Id: CombinedBeanInfo.java 797905 2009-07-26 11:21:31Z apetrelli $3 *4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122package org.apache.tiles.util;
2324import java.beans.FeatureDescriptor;
25import java.beans.PropertyDescriptor;
26import java.util.ArrayList;
27import java.util.LinkedHashMap;
28import java.util.List;
29import java.util.Map;
30import java.util.Set;
3132import org.apache.tiles.reflect.ClassUtil;
3334/***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.039 */40publicclassCombinedBeanInfo {
41/***42 * The descriptors of the introspected classes.43 */44private List<FeatureDescriptor> descriptors;
4546/***47 * Maps analyzed classes to the map of introspected properties.48 */49private Map<Class<?>, Map<String, PropertyDescriptor>> class2descriptors;
5051/***52 * Constructor.53 * @param clazzes The list of classes to analyze and combine.54 *55 * @since 2.2.056 */57publicCombinedBeanInfo(Class<?>... clazzes) {
58 descriptors = new ArrayList<FeatureDescriptor>();
59class2descriptors = new LinkedHashMap<Class<?>, Map<String, PropertyDescriptor>>();
60for (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());
65class2descriptors.put(clazz, mappedDescriptors);
66 }
67 }
6869/***70 * Returns the descriptors of all the introspected classes.71 *72 * @return The feature descriptors.73 * @since 2.2.074 */75public List<FeatureDescriptor> getDescriptors() {
76return descriptors;
77 }
7879/***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.085 */86public Map<String, PropertyDescriptor> getMappedDescriptors(Class<?> clazz) {
87returnclass2descriptors.get(clazz);
88 }
8990/***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.096 */97public Set<String> getProperties(Class<?> clazz) {
98returnclass2descriptors.get(clazz).keySet();
99 }
100 }