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.composite; |
20 | |
|
21 | |
import java.beans.BeanInfo; |
22 | |
import java.beans.IntrospectionException; |
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.el.ValueExpression; |
29 | |
import javax.faces.view.facelets.MetadataTarget; |
30 | |
import javax.faces.context.FacesContext; |
31 | |
import org.apache.myfaces.shared.util.ClassUtils; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
final class CompositeMetadataTargetImpl extends MetadataTarget |
42 | |
{ |
43 | |
private final Map<String, PropertyDescriptor> _pd; |
44 | |
|
45 | |
private final MetadataTarget _delegate; |
46 | |
|
47 | |
private final BeanInfo _beanInfo; |
48 | |
|
49 | |
public CompositeMetadataTargetImpl(MetadataTarget delegate, BeanInfo beanInfo) throws IntrospectionException |
50 | 0 | { |
51 | 0 | _delegate = delegate; |
52 | 0 | _beanInfo = beanInfo; |
53 | |
|
54 | 0 | _pd = new HashMap<String, PropertyDescriptor>(); |
55 | |
|
56 | 0 | for (PropertyDescriptor descriptor : _beanInfo.getPropertyDescriptors()) |
57 | |
{ |
58 | 0 | _pd.put(descriptor.getName(), descriptor); |
59 | |
} |
60 | 0 | } |
61 | |
|
62 | |
public PropertyDescriptor getProperty(String name) |
63 | |
{ |
64 | 0 | PropertyDescriptor pd = _delegate.getProperty(name); |
65 | 0 | if (pd == null) |
66 | |
{ |
67 | 0 | pd = _pd.get(name); |
68 | |
} |
69 | 0 | return pd; |
70 | |
} |
71 | |
|
72 | |
public Class<?> getPropertyType(String name) |
73 | |
{ |
74 | 0 | PropertyDescriptor pd = getProperty(name); |
75 | 0 | if (pd != null) |
76 | |
{ |
77 | 0 | Object type = pd.getValue("type"); |
78 | 0 | if (type != null) |
79 | |
{ |
80 | 0 | type = ((ValueExpression)type).getValue(FacesContext.getCurrentInstance().getELContext()); |
81 | 0 | if (type instanceof String) |
82 | |
{ |
83 | |
try |
84 | |
{ |
85 | 0 | type = ClassUtils.javaDefaultTypeToClass((String)type); |
86 | |
} |
87 | 0 | catch (ClassNotFoundException e) |
88 | |
{ |
89 | 0 | type = Object.class; |
90 | 0 | } |
91 | |
} |
92 | 0 | return (Class<?>) type; |
93 | |
} |
94 | 0 | return pd.getPropertyType(); |
95 | |
} |
96 | |
|
97 | 0 | return null; |
98 | |
} |
99 | |
|
100 | |
public Method getReadMethod(String name) |
101 | |
{ |
102 | 0 | PropertyDescriptor pd = getProperty(name); |
103 | 0 | if (pd != null) |
104 | |
{ |
105 | 0 | return pd.getReadMethod(); |
106 | |
} |
107 | |
|
108 | 0 | return null; |
109 | |
} |
110 | |
|
111 | |
public Class<?> getTargetClass() |
112 | |
{ |
113 | 0 | return _delegate.getTargetClass(); |
114 | |
} |
115 | |
|
116 | |
public Method getWriteMethod(String name) |
117 | |
{ |
118 | 0 | PropertyDescriptor pd = getProperty(name); |
119 | 0 | if (pd != null) |
120 | |
{ |
121 | 0 | return pd.getWriteMethod(); |
122 | |
} |
123 | |
|
124 | 0 | return null; |
125 | |
} |
126 | |
|
127 | |
public boolean isTargetInstanceOf(Class type) |
128 | |
{ |
129 | 0 | return _delegate.isTargetInstanceOf(type); |
130 | |
} |
131 | |
} |