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 {
51 _delegate = delegate;
52 _beanInfo = beanInfo;
53
54 _pd = new HashMap<String, PropertyDescriptor>();
55
56 for (PropertyDescriptor descriptor : _beanInfo.getPropertyDescriptors())
57 {
58 _pd.put(descriptor.getName(), descriptor);
59 }
60 }
61
62 public PropertyDescriptor getProperty(String name)
63 {
64 PropertyDescriptor pd = _delegate.getProperty(name);
65 if (pd == null)
66 {
67 pd = _pd.get(name);
68 }
69 return pd;
70 }
71
72 public Class<?> getPropertyType(String name)
73 {
74 PropertyDescriptor pd = getProperty(name);
75 if (pd != null)
76 {
77 Object type = pd.getValue("type");
78 if (type != null)
79 {
80 type = ((ValueExpression)type).getValue(FacesContext.getCurrentInstance().getELContext());
81 if (type instanceof String)
82 {
83 try
84 {
85 type = ClassUtils.javaDefaultTypeToClass((String)type);
86 }
87 catch (ClassNotFoundException e)
88 {
89 type = Object.class;
90 }
91 }
92 return (Class<?>) type;
93 }
94 return pd.getPropertyType();
95 }
96
97 return null;
98 }
99
100 public Method getReadMethod(String name)
101 {
102 PropertyDescriptor pd = getProperty(name);
103 if (pd != null)
104 {
105 return pd.getReadMethod();
106 }
107
108 return null;
109 }
110
111 public Class<?> getTargetClass()
112 {
113 return _delegate.getTargetClass();
114 }
115
116 public Method getWriteMethod(String name)
117 {
118 PropertyDescriptor pd = getProperty(name);
119 if (pd != null)
120 {
121 return pd.getWriteMethod();
122 }
123
124 return null;
125 }
126
127 public boolean isTargetInstanceOf(Class type)
128 {
129 return _delegate.isTargetInstanceOf(type);
130 }
131 }