1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.tag;
20
21 import java.beans.IntrospectionException;
22 import java.beans.Introspector;
23 import java.beans.PropertyDescriptor;
24 import java.lang.reflect.Method;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import javax.faces.view.facelets.MetadataTarget;
29
30
31
32
33
34
35 public final class MetadataTargetImpl extends MetadataTarget
36 {
37 private final Map<String, PropertyDescriptor> _pd;
38
39 private final Class<?> _type;
40
41 public MetadataTargetImpl(Class<?> type) throws IntrospectionException
42 {
43 _type = type;
44
45 _pd = new HashMap<String, PropertyDescriptor>();
46 for (PropertyDescriptor descriptor : Introspector.getBeanInfo(type).getPropertyDescriptors())
47 {
48 _pd.put(descriptor.getName(), descriptor);
49 }
50 }
51
52 public PropertyDescriptor getProperty(String name)
53 {
54 return _pd.get(name);
55 }
56
57 public Class<?> getPropertyType(String name)
58 {
59 PropertyDescriptor pd = getProperty(name);
60 if (pd != null)
61 {
62 return pd.getPropertyType();
63 }
64
65 return null;
66 }
67
68 public Method getReadMethod(String name)
69 {
70 PropertyDescriptor pd = getProperty(name);
71 if (pd != null)
72 {
73 return pd.getReadMethod();
74 }
75
76 return null;
77 }
78
79 public Class<?> getTargetClass()
80 {
81 return _type;
82 }
83
84 public Method getWriteMethod(String name)
85 {
86 PropertyDescriptor pd = getProperty(name);
87 if (pd != null)
88 {
89 return pd.getWriteMethod();
90 }
91
92 return null;
93 }
94
95 public boolean isTargetInstanceOf(Class type)
96 {
97 return type.isAssignableFrom(_type);
98 }
99 }