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 |
8 |
public class ParameterAnnotationWorker implements MethodAnnotationEnhancementWorker |
37 |
|
{ |
38 |
|
|
39 |
|
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec, |
40 |
|
Method method, Location location) |
41 |
|
{ |
42 |
8 |
if (IPage.class.isAssignableFrom(method.getDeclaringClass())) |
43 |
|
{ |
44 |
1 |
throw new ApplicationRuntimeException( |
45 |
|
AnnotationMessages.invalidAnnotationInClass(Parameter.class, method.getDeclaringClass())); |
46 |
|
} |
47 |
|
|
48 |
7 |
Parameter parameter = method.getAnnotation(Parameter.class); |
49 |
|
|
50 |
7 |
String propertyName = AnnotationUtils.getPropertyName(method); |
51 |
|
|
52 |
7 |
boolean deprecated = method.isAnnotationPresent(Deprecated.class); |
53 |
|
|
54 |
7 |
IParameterSpecification ps = new ParameterSpecification(); |
55 |
|
|
56 |
7 |
String parameterName = parameter.name(); |
57 |
|
|
58 |
7 |
if (HiveMind.isBlank(parameterName)) |
59 |
6 |
parameterName = propertyName; |
60 |
|
|
61 |
7 |
Class propertyType = op.getPropertyType(propertyName); |
62 |
|
|
63 |
7 |
ps.setAliases(parameter.aliases()); |
64 |
7 |
ps.setCache(parameter.cache()); |
65 |
|
|
66 |
7 |
if (HiveMind.isNonBlank(parameter.defaultValue())) |
67 |
1 |
ps.setDefaultValue(parameter.defaultValue()); |
68 |
|
|
69 |
7 |
ps.setDeprecated(deprecated); |
70 |
7 |
ps.setParameterName(parameterName); |
71 |
7 |
ps.setPropertyName(propertyName); |
72 |
7 |
ps.setRequired(parameter.required()); |
73 |
7 |
ps.setType(propertyType.getName()); |
74 |
7 |
ps.setLocation(location); |
75 |
|
|
76 |
7 |
spec.addParameter(ps); |
77 |
7 |
} |
78 |
|
} |