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,Map<String, Method> propertyNameToSetter,Map<String, Method> propertyNameToAdder) {
37  		this.clazz = clazz;
38  		this.propertyNameToGetter = Collections.unmodifiableMap(propertyNameToGetter);
39  		this.propertyNameToSetter = Collections.unmodifiableMap(propertyNameToSetter);
40  		this.propertyNameToAdder = Collections.unmodifiableMap(propertyNameToAdder);
41  	}
42  
43  	public Class<?> getClazz() {
44  		return clazz;
45  	}
46  
47  	public Map<String, Method> getPropertyNameToGetter() {
48  		return propertyNameToGetter;
49  	}
50  
51  	public Map<String, Method> getPropertyNameToSetter() {
52  		return propertyNameToSetter;
53  	}
54  
55  	public Method getGetter(String propertyName) {
56  		return propertyNameToGetter.get(propertyName);
57  	}
58  
59  	public Method getSetter(String propertyName) {
60  		return propertyNameToSetter.get(propertyName);
61  	}
62  
63  	public Map<String, Method> getPropertyNameToAdder() {
64  		return propertyNameToAdder;
65  	}
66  
67  	public Method getAdder(String propertyName) {
68  		return propertyNameToAdder.get(propertyName);
69  	}
70  
71  }