View Javadoc
1   package ch.qos.logback.core.joran.util.beans;
2   
3   import java.lang.reflect.Method;
4   import java.util.Collections;
5   import java.util.Map;
6   
7   /**
8    * Lightweight pendant to the java.beans.BeanInfo class. An instance of this
9    * class encapsulates the properties of a certain class. The properties are the
10   * public setters and getters. In addition the 'add-er'-methods are included,
11   * which are the public methods which start with the prefix 'add'.
12   *
13   * @author urechm
14   *
15   */
16  public class BeanDescription {
17  
18      private final Class<?> clazz;
19  
20      private final Map<String, Method> propertyNameToGetter;
21  
22      private final Map<String, Method> propertyNameToSetter;
23  
24      private final Map<String, Method> propertyNameToAdder;
25  
26      /**
27       * Scope protected since only the {@link BeanDescriptionFactory} must create
28       * BeanDescriptions in order to guarantee consistency between the given
29       * parameters.
30       *
31       * @param clazz                of the bean.
32       * @param propertyNameToGetter map of property names to the associated getter.
33       * @param propertyNameToSetter map of property names to the associated setter.
34       * @param propertyNameToAdder  map of property names to the associated adder.
35       */
36      protected BeanDescription(Class<?> clazz, Map<String, Method> propertyNameToGetter,
37              Map<String, Method> propertyNameToSetter, Map<String, Method> propertyNameToAdder) {
38          this.clazz = clazz;
39          this.propertyNameToGetter = Collections.unmodifiableMap(propertyNameToGetter);
40          this.propertyNameToSetter = Collections.unmodifiableMap(propertyNameToSetter);
41          this.propertyNameToAdder = Collections.unmodifiableMap(propertyNameToAdder);
42      }
43  
44      public Class<?> getClazz() {
45          return clazz;
46      }
47  
48      public Map<String, Method> getPropertyNameToGetter() {
49          return propertyNameToGetter;
50      }
51  
52      public Map<String, Method> getPropertyNameToSetter() {
53          return propertyNameToSetter;
54      }
55  
56      public Method getGetter(String propertyName) {
57          return propertyNameToGetter.get(propertyName);
58      }
59  
60      public Method getSetter(String propertyName) {
61          return propertyNameToSetter.get(propertyName);
62      }
63  
64      public Map<String, Method> getPropertyNameToAdder() {
65          return propertyNameToAdder;
66      }
67  
68      public Method getAdder(String propertyName) {
69          return propertyNameToAdder.get(propertyName);
70      }
71  
72  }