1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.beanutils;
18
19 import java.beans.PropertyDescriptor;
20 import java.util.HashMap;
21 import java.util.Map;
22 import java.util.Set;
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 class DefaultIntrospectionContext implements IntrospectionContext {
39
40 private static final PropertyDescriptor[] EMPTY_DESCRIPTORS = new PropertyDescriptor[0];
41
42
43 private final Class<?> currentClass;
44
45
46 private final Map<String, PropertyDescriptor> descriptors;
47
48
49
50
51
52
53
54
55 public DefaultIntrospectionContext(final Class<?> cls) {
56 currentClass = cls;
57 descriptors = new HashMap<String, PropertyDescriptor>();
58 }
59
60 public Class<?> getTargetClass() {
61 return currentClass;
62 }
63
64 public void addPropertyDescriptor(final PropertyDescriptor desc) {
65 if (desc == null) {
66 throw new IllegalArgumentException(
67 "Property descriptor must not be null!");
68 }
69 descriptors.put(desc.getName(), desc);
70 }
71
72 public void addPropertyDescriptors(final PropertyDescriptor[] descs) {
73 if (descs == null) {
74 throw new IllegalArgumentException(
75 "Array with descriptors must not be null!");
76 }
77
78 for (PropertyDescriptor desc : descs) {
79 addPropertyDescriptor(desc);
80 }
81 }
82
83 public boolean hasProperty(final String name) {
84 return descriptors.containsKey(name);
85 }
86
87 public PropertyDescriptor getPropertyDescriptor(final String name) {
88 return descriptors.get(name);
89 }
90
91 public void removePropertyDescriptor(final String name) {
92 descriptors.remove(name);
93 }
94
95 public Set<String> propertyNames() {
96 return descriptors.keySet();
97 }
98
99
100
101
102
103
104
105 public PropertyDescriptor[] getPropertyDescriptors() {
106 return descriptors.values().toArray(EMPTY_DESCRIPTORS);
107 }
108 }