001/* 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2026, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v2.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014 015package ch.qos.logback.core.joran.util.beans; 016 017import java.lang.reflect.Method; 018import java.util.Collections; 019import java.util.Map; 020 021/** 022 * Lightweight pendant to the java.beans.BeanInfo class. An instance of this 023 * class encapsulates the properties of a certain class. The properties are the 024 * public setters and getters. In addition the 'add-er'-methods are included, 025 * which are the public methods which start with the prefix 'add'. 026 * 027 * @author urechm 028 * 029 */ 030public class BeanDescription { 031 032 private final Class<?> clazz; 033 034 private final Map<String, Method> propertyNameToGetter; 035 036 private final Map<String, Method> propertyNameToSetter; 037 038 private final Map<String, Method> propertyNameToAdder; 039 040 /** 041 * Scope protected since only the {@link BeanDescriptionFactory} must create 042 * BeanDescriptions in order to guarantee consistency between the given 043 * parameters. 044 * 045 * @param clazz of the bean. 046 * @param propertyNameToGetter map of property names to the associated getter. 047 * @param propertyNameToSetter map of property names to the associated setter. 048 * @param propertyNameToAdder map of property names to the associated adder. 049 */ 050 protected BeanDescription(Class<?> clazz, Map<String, Method> propertyNameToGetter, 051 Map<String, Method> propertyNameToSetter, Map<String, Method> propertyNameToAdder) { 052 this.clazz = clazz; 053 this.propertyNameToGetter = Collections.unmodifiableMap(propertyNameToGetter); 054 this.propertyNameToSetter = Collections.unmodifiableMap(propertyNameToSetter); 055 this.propertyNameToAdder = Collections.unmodifiableMap(propertyNameToAdder); 056 } 057 058 public Class<?> getClazz() { 059 return clazz; 060 } 061 062 public Map<String, Method> getPropertyNameToGetter() { 063 return propertyNameToGetter; 064 } 065 066 public Map<String, Method> getPropertyNameToSetter() { 067 return propertyNameToSetter; 068 } 069 070 public Method getGetter(String propertyName) { 071 return propertyNameToGetter.get(propertyName); 072 } 073 074 public Method getSetter(String propertyName) { 075 return propertyNameToSetter.get(propertyName); 076 } 077 078 public Map<String, Method> getPropertyNameToAdder() { 079 return propertyNameToAdder; 080 } 081 082 public Method getAdder(String propertyName) { 083 return propertyNameToAdder.get(propertyName); 084 } 085 086}