1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
package org.apache.tapestry.enhance; |
15 |
|
|
16 |
|
import org.apache.hivemind.ApplicationRuntimeException; |
17 |
|
|
18 |
|
import java.beans.Introspector; |
19 |
|
import java.lang.reflect.Method; |
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
7 |
public class GenericsClassInspectorImpl implements ClassInspector |
27 |
|
{ |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
public MethodSignature getMethodSignature(Class implementing, Method m) |
33 |
|
{ |
34 |
10 |
return new GenericsMethodSignatureImpl(implementing, m); |
35 |
|
} |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
public MethodSignature getPropertyAccessor(Class type, String propertyName) |
41 |
|
{ |
42 |
|
try { |
43 |
8 |
Method[] props = type.getMethods(); |
44 |
8 |
Method match = null; |
45 |
|
|
46 |
48 |
for (int i=0; i < props.length; i++) { |
47 |
|
|
48 |
46 |
String propName = getPropertyName(props[i]); |
49 |
|
|
50 |
46 |
if (!propertyName.equals(propName)) { |
51 |
37 |
continue; |
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
9 |
if (match == null) |
56 |
8 |
match = props[i]; |
57 |
|
|
58 |
|
|
59 |
9 |
if (props[i].getReturnType() == void.class) { |
60 |
3 |
continue; |
61 |
|
} |
62 |
|
|
63 |
6 |
return new GenericsMethodSignatureImpl(type, props[i]); |
64 |
|
} |
65 |
|
|
66 |
2 |
if (match != null) |
67 |
2 |
return new GenericsMethodSignatureImpl(type, match); |
68 |
|
|
69 |
0 |
} catch (Throwable t) { |
70 |
|
|
71 |
0 |
throw new ApplicationRuntimeException("Error reading property " + propertyName + " from base class : " + type, t); |
72 |
0 |
} |
73 |
|
|
74 |
0 |
return null; |
75 |
|
} |
76 |
|
|
77 |
|
static String getPropertyName(Method m) |
78 |
|
{ |
79 |
46 |
String name = m.getName(); |
80 |
|
|
81 |
46 |
if (name.startsWith("get")) |
82 |
22 |
name = name.substring(3); |
83 |
24 |
else if (name.startsWith("set")) |
84 |
6 |
name = name.substring(3); |
85 |
18 |
else if (name.startsWith("is")) |
86 |
0 |
name = name.substring(2); |
87 |
|
|
88 |
46 |
return Introspector.decapitalize(name); |
89 |
|
} |
90 |
|
} |