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,Map<String, Method> propertyNameToSetter,Map<String, Method> propertyNameToAdder) {
037                this.clazz = clazz;
038                this.propertyNameToGetter = Collections.unmodifiableMap(propertyNameToGetter);
039                this.propertyNameToSetter = Collections.unmodifiableMap(propertyNameToSetter);
040                this.propertyNameToAdder = Collections.unmodifiableMap(propertyNameToAdder);
041        }
042
043        public Class<?> getClazz() {
044                return clazz;
045        }
046
047        public Map<String, Method> getPropertyNameToGetter() {
048                return propertyNameToGetter;
049        }
050
051        public Map<String, Method> getPropertyNameToSetter() {
052                return propertyNameToSetter;
053        }
054
055        public Method getGetter(String propertyName) {
056                return propertyNameToGetter.get(propertyName);
057        }
058
059        public Method getSetter(String propertyName) {
060                return propertyNameToSetter.get(propertyName);
061        }
062
063        public Map<String, Method> getPropertyNameToAdder() {
064                return propertyNameToAdder;
065        }
066
067        public Method getAdder(String propertyName) {
068                return propertyNameToAdder.get(propertyName);
069        }
070
071}