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.reflect.Method; |
19 |
| |
20 |
| import org.apache.hivemind.ApplicationRuntimeException; |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| public class AnnotationUtils |
28 |
| { |
29 |
34
| public static String getPropertyName(Method method)
|
30 |
| { |
31 |
34
| String name = method.getName();
|
32 |
| |
33 |
34
| if (name.startsWith("is"))
|
34 |
| { |
35 |
2
| checkGetter(method);
|
36 |
1
| return Introspector.decapitalize(name.substring(2));
|
37 |
| } |
38 |
| |
39 |
32
| if (name.startsWith("get"))
|
40 |
| { |
41 |
28
| checkGetter(method);
|
42 |
27
| return Introspector.decapitalize(name.substring(3));
|
43 |
| } |
44 |
| |
45 |
4
| if (name.startsWith("set"))
|
46 |
| { |
47 |
3
| checkSetter(method);
|
48 |
1
| return Introspector.decapitalize(name.substring(3));
|
49 |
| } |
50 |
| |
51 |
1
| throw new ApplicationRuntimeException(AnnotationMessages.notAccessor(method));
|
52 |
| } |
53 |
| |
54 |
30
| private static void checkGetter(Method method)
|
55 |
| { |
56 |
30
| if (method.getParameterTypes().length > 0)
|
57 |
1
| throw new ApplicationRuntimeException(AnnotationMessages.noParametersExpected(method));
|
58 |
| |
59 |
29
| if (method.getReturnType().equals(void.class))
|
60 |
1
| throw new ApplicationRuntimeException(AnnotationMessages.voidAccessor(method));
|
61 |
| |
62 |
| } |
63 |
| |
64 |
3
| private static void checkSetter(Method method)
|
65 |
| { |
66 |
3
| if (!method.getReturnType().equals(void.class))
|
67 |
1
| throw new ApplicationRuntimeException(AnnotationMessages.nonVoidMutator(method));
|
68 |
| |
69 |
2
| if (method.getParameterTypes().length != 1)
|
70 |
1
| throw new ApplicationRuntimeException(AnnotationMessages.wrongParameterCount(method));
|
71 |
| } |
72 |
| } |