1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.annotations; |
16 |
| |
17 |
| import java.beans.Introspector; |
18 |
| import java.lang.annotation.Annotation; |
19 |
| import java.lang.reflect.Method; |
20 |
| |
21 |
| import org.apache.hivemind.ApplicationRuntimeException; |
22 |
| import org.apache.hivemind.Location; |
23 |
| import org.apache.hivemind.Resource; |
24 |
| import org.apache.tapestry.util.DescribedLocation; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| public class AnnotationUtils |
32 |
| { |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
38
| public static String getPropertyName(Method method)
|
44 |
| { |
45 |
38
| String name = method.getName();
|
46 |
| |
47 |
38
| if (name.startsWith("is"))
|
48 |
| { |
49 |
2
| checkGetter(method);
|
50 |
1
| return Introspector.decapitalize(name.substring(2));
|
51 |
| } |
52 |
| |
53 |
36
| if (name.startsWith("get"))
|
54 |
| { |
55 |
32
| checkGetter(method);
|
56 |
31
| return Introspector.decapitalize(name.substring(3));
|
57 |
| } |
58 |
| |
59 |
4
| if (name.startsWith("set"))
|
60 |
| { |
61 |
3
| checkSetter(method);
|
62 |
1
| return Introspector.decapitalize(name.substring(3));
|
63 |
| } |
64 |
| |
65 |
1
| throw new ApplicationRuntimeException(AnnotationMessages.notAccessor(method));
|
66 |
| } |
67 |
| |
68 |
34
| private static void checkGetter(Method method)
|
69 |
| { |
70 |
34
| if (method.getParameterTypes().length > 0)
|
71 |
1
| throw new ApplicationRuntimeException(AnnotationMessages.noParametersExpected(method));
|
72 |
| |
73 |
33
| if (method.getReturnType().equals(void.class))
|
74 |
1
| throw new ApplicationRuntimeException(AnnotationMessages.voidAccessor(method));
|
75 |
| |
76 |
| } |
77 |
| |
78 |
3
| private static void checkSetter(Method method)
|
79 |
| { |
80 |
3
| if (!method.getReturnType().equals(void.class))
|
81 |
1
| throw new ApplicationRuntimeException(AnnotationMessages.nonVoidMutator(method));
|
82 |
| |
83 |
2
| if (method.getParameterTypes().length != 1)
|
84 |
1
| throw new ApplicationRuntimeException(AnnotationMessages.wrongParameterCount(method));
|
85 |
| } |
86 |
| |
87 |
14
| public static Location buildLocationForAnnotation(Method method, Annotation annotation,
|
88 |
| Resource classResource) |
89 |
| { |
90 |
14
| return new DescribedLocation(classResource, AnnotationMessages.methodAnnotation(
|
91 |
| annotation, |
92 |
| method)); |
93 |
| } |
94 |
| } |