001package ch.qos.logback.core.joran.util.beans; 002 003import java.lang.reflect.Method; 004import java.util.Collections; 005import java.util.Map; 006 007/** 008 * Lightweight pendant to the java.beans.BeanInfo class. An instance of this 009 * class encapsulates the properties of a certain class. The properties are the 010 * public setters and getters. In addition the 'add-er'-methods are included, 011 * which are the public methods which start with the prefix 'add'. 012 * 013 * @author urechm 014 * 015 */ 016public class BeanDescription { 017 018 private final Class<?> clazz; 019 020 private final Map<String, Method> propertyNameToGetter; 021 022 private final Map<String, Method> propertyNameToSetter; 023 024 private final Map<String, Method> propertyNameToAdder; 025 026 /** 027 * Scope protected since only the {@link BeanDescriptionFactory} must create 028 * BeanDescriptions in order to guarantee consistency between the given 029 * parameters. 030 * 031 * @param clazz of the bean. 032 * @param propertyNameToGetter map of property names to the associated getter. 033 * @param propertyNameToSetter map of property names to the associated setter. 034 * @param propertyNameToAdder map of property names to the associated adder. 035 */ 036 protected BeanDescription(Class<?> clazz, Map<String, Method> propertyNameToGetter, 037 Map<String, Method> propertyNameToSetter, Map<String, Method> propertyNameToAdder) { 038 this.clazz = clazz; 039 this.propertyNameToGetter = Collections.unmodifiableMap(propertyNameToGetter); 040 this.propertyNameToSetter = Collections.unmodifiableMap(propertyNameToSetter); 041 this.propertyNameToAdder = Collections.unmodifiableMap(propertyNameToAdder); 042 } 043 044 public Class<?> getClazz() { 045 return clazz; 046 } 047 048 public Map<String, Method> getPropertyNameToGetter() { 049 return propertyNameToGetter; 050 } 051 052 public Map<String, Method> getPropertyNameToSetter() { 053 return propertyNameToSetter; 054 } 055 056 public Method getGetter(String propertyName) { 057 return propertyNameToGetter.get(propertyName); 058 } 059 060 public Method getSetter(String propertyName) { 061 return propertyNameToSetter.get(propertyName); 062 } 063 064 public Map<String, Method> getPropertyNameToAdder() { 065 return propertyNameToAdder; 066 } 067 068 public Method getAdder(String propertyName) { 069 return propertyNameToAdder.get(propertyName); 070 } 071 072}