1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
package org.apache.tapestry.annotations; |
16 | |
|
17 | |
import java.lang.reflect.Method; |
18 | |
|
19 | |
import org.apache.hivemind.ApplicationRuntimeException; |
20 | |
import org.apache.hivemind.HiveMind; |
21 | |
import org.apache.hivemind.Location; |
22 | |
import org.apache.tapestry.IPage; |
23 | |
import org.apache.tapestry.enhance.EnhancementOperation; |
24 | |
import org.apache.tapestry.spec.IComponentSpecification; |
25 | |
import org.apache.tapestry.spec.IParameterSpecification; |
26 | |
import org.apache.tapestry.spec.ParameterSpecification; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public class ParameterAnnotationWorker implements MethodAnnotationEnhancementWorker |
37 | |
{ |
38 | |
|
39 | |
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec, |
40 | |
Method method, Location location) |
41 | |
{ |
42 | 0 | if (IPage.class.isAssignableFrom(method.getDeclaringClass())) |
43 | |
{ |
44 | 0 | throw new ApplicationRuntimeException( |
45 | |
AnnotationMessages.invalidAnnotationInClass(Parameter.class, method.getDeclaringClass())); |
46 | |
} |
47 | |
|
48 | 0 | Parameter parameter = method.getAnnotation(Parameter.class); |
49 | |
|
50 | 0 | String propertyName = AnnotationUtils.getPropertyName(method); |
51 | |
|
52 | 0 | boolean deprecated = method.isAnnotationPresent(Deprecated.class); |
53 | |
|
54 | 0 | IParameterSpecification ps = new ParameterSpecification(); |
55 | |
|
56 | 0 | String parameterName = parameter.name(); |
57 | |
|
58 | 0 | if (HiveMind.isBlank(parameterName)) |
59 | 0 | parameterName = propertyName; |
60 | |
|
61 | 0 | Class propertyType = op.getPropertyType(propertyName); |
62 | |
|
63 | 0 | ps.setAliases(parameter.aliases()); |
64 | 0 | ps.setCache(parameter.cache()); |
65 | |
|
66 | 0 | if (HiveMind.isNonBlank(parameter.defaultValue())) |
67 | 0 | ps.setDefaultValue(parameter.defaultValue()); |
68 | |
|
69 | 0 | ps.setDeprecated(deprecated); |
70 | 0 | ps.setParameterName(parameterName); |
71 | 0 | ps.setPropertyName(propertyName); |
72 | 0 | ps.setRequired(parameter.required()); |
73 | 0 | ps.setType(propertyType.getName()); |
74 | 0 | ps.setLocation(location); |
75 | |
|
76 | 0 | spec.addParameter(ps); |
77 | 0 | } |
78 | |
} |