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 | 0 | { |
43 | 0 | _type = type; |
44 | |
|
45 | 0 | _pd = new HashMap<String, PropertyDescriptor>(); |
46 | 0 | for (PropertyDescriptor descriptor : Introspector.getBeanInfo(type).getPropertyDescriptors()) |
47 | |
{ |
48 | 0 | _pd.put(descriptor.getName(), descriptor); |
49 | |
} |
50 | 0 | } |
51 | |
|
52 | |
public PropertyDescriptor getProperty(String name) |
53 | |
{ |
54 | 0 | return _pd.get(name); |
55 | |
} |
56 | |
|
57 | |
public Class<?> getPropertyType(String name) |
58 | |
{ |
59 | 0 | PropertyDescriptor pd = getProperty(name); |
60 | 0 | if (pd != null) |
61 | |
{ |
62 | 0 | return pd.getPropertyType(); |
63 | |
} |
64 | |
|
65 | 0 | return null; |
66 | |
} |
67 | |
|
68 | |
public Method getReadMethod(String name) |
69 | |
{ |
70 | 0 | PropertyDescriptor pd = getProperty(name); |
71 | 0 | if (pd != null) |
72 | |
{ |
73 | 0 | return pd.getReadMethod(); |
74 | |
} |
75 | |
|
76 | 0 | return null; |
77 | |
} |
78 | |
|
79 | |
public Class<?> getTargetClass() |
80 | |
{ |
81 | 0 | return _type; |
82 | |
} |
83 | |
|
84 | |
public Method getWriteMethod(String name) |
85 | |
{ |
86 | 0 | PropertyDescriptor pd = getProperty(name); |
87 | 0 | if (pd != null) |
88 | |
{ |
89 | 0 | return pd.getWriteMethod(); |
90 | |
} |
91 | |
|
92 | 0 | return null; |
93 | |
} |
94 | |
|
95 | |
public boolean isTargetInstanceOf(Class type) |
96 | |
{ |
97 | 0 | return type.isAssignableFrom(_type); |
98 | |
} |
99 | |
} |