1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package org.apache.tapestry.enhance; |
15 | |
|
16 | |
import java.beans.BeanInfo; |
17 | |
import java.beans.Introspector; |
18 | |
import java.beans.PropertyDescriptor; |
19 | |
import java.lang.reflect.Method; |
20 | |
|
21 | |
import org.apache.hivemind.ApplicationRuntimeException; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 0 | public class ClassInspectorImpl implements ClassInspector |
29 | |
{ |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public MethodSignature getMethodSignature(Class implementing, Method m) |
35 | |
{ |
36 | 0 | return new MethodSignatureImpl(m); |
37 | |
} |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public MethodSignature getPropertyAccessor(Class type, String propertyName) |
43 | |
{ |
44 | |
try { |
45 | 0 | BeanInfo info = Introspector.getBeanInfo(type); |
46 | 0 | PropertyDescriptor[] props = info.getPropertyDescriptors(); |
47 | |
|
48 | 0 | for (int i=0; i < props.length; i++) { |
49 | |
|
50 | 0 | if (!propertyName.equals(props[i].getName())) { |
51 | 0 | continue; |
52 | |
} |
53 | |
|
54 | 0 | return new MethodSignatureImpl(props[i].getReadMethod() != null ? props[i].getReadMethod() : props[i].getWriteMethod()); |
55 | |
} |
56 | |
|
57 | 0 | } catch (Throwable t) { |
58 | |
|
59 | 0 | throw new ApplicationRuntimeException("Error reading property " + propertyName + " from base class : " + type, t); |
60 | 0 | } |
61 | |
|
62 | 0 | return null; |
63 | |
} |
64 | |
|
65 | |
} |