1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v2.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  
15  package ch.qos.logback.core.joran.util.beans;
16  
17  import java.lang.reflect.Method;
18  import java.util.Collections;
19  import java.util.Map;
20  
21  /**
22   * Lightweight pendant to the java.beans.BeanInfo class. An instance of this
23   * class encapsulates the properties of a certain class. The properties are the
24   * public setters and getters. In addition the 'add-er'-methods are included,
25   * which are the public methods which start with the prefix 'add'.
26   *
27   * @author urechm
28   *
29   */
30  public class BeanDescription {
31  
32      private final Class<?> clazz;
33  
34      private final Map<String, Method> propertyNameToGetter;
35  
36      private final Map<String, Method> propertyNameToSetter;
37  
38      private final Map<String, Method> propertyNameToAdder;
39  
40      /**
41       * Scope protected since only the {@link BeanDescriptionFactory} must create
42       * BeanDescriptions in order to guarantee consistency between the given
43       * parameters.
44       *
45       * @param clazz                of the bean.
46       * @param propertyNameToGetter map of property names to the associated getter.
47       * @param propertyNameToSetter map of property names to the associated setter.
48       * @param propertyNameToAdder  map of property names to the associated adder.
49       */
50      protected BeanDescription(Class<?> clazz, Map<String, Method> propertyNameToGetter,
51              Map<String, Method> propertyNameToSetter, Map<String, Method> propertyNameToAdder) {
52          this.clazz = clazz;
53          this.propertyNameToGetter = Collections.unmodifiableMap(propertyNameToGetter);
54          this.propertyNameToSetter = Collections.unmodifiableMap(propertyNameToSetter);
55          this.propertyNameToAdder = Collections.unmodifiableMap(propertyNameToAdder);
56      }
57  
58      public Class<?> getClazz() {
59          return clazz;
60      }
61  
62      public Map<String, Method> getPropertyNameToGetter() {
63          return propertyNameToGetter;
64      }
65  
66      public Map<String, Method> getPropertyNameToSetter() {
67          return propertyNameToSetter;
68      }
69  
70      public Method getGetter(String propertyName) {
71          return propertyNameToGetter.get(propertyName);
72      }
73  
74      public Method getSetter(String propertyName) {
75          return propertyNameToSetter.get(propertyName);
76      }
77  
78      public Map<String, Method> getPropertyNameToAdder() {
79          return propertyNameToAdder;
80      }
81  
82      public Method getAdder(String propertyName) {
83          return propertyNameToAdder.get(propertyName);
84      }
85  
86  }