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.Location; |
20 |
| import org.apache.hivemind.Resource; |
21 |
| import org.apache.tapestry.enhance.EnhancementOperation; |
22 |
| import org.apache.tapestry.spec.IComponentSpecification; |
23 |
| import org.apache.tapestry.spec.IPropertySpecification; |
24 |
| import org.apache.tapestry.spec.PropertySpecification; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| public class InitialValueAnnotationWorker implements SecondaryAnnotationWorker |
37 |
| { |
38 |
| |
39 |
| |
40 |
| |
41 |
4
| public boolean canEnhance(Method method)
|
42 |
| { |
43 |
4
| return method.getAnnotation(InitialValue.class) != null;
|
44 |
| } |
45 |
| |
46 |
6
| public void peformEnhancement(EnhancementOperation op, IComponentSpecification spec,
|
47 |
| Method method, Resource classResource) |
48 |
| { |
49 |
6
| InitialValue iv = method.getAnnotation(InitialValue.class);
|
50 |
| |
51 |
6
| if (iv == null)
|
52 |
2
| return;
|
53 |
| |
54 |
4
| if (method.getAnnotation(Persist.class) != null)
|
55 |
2
| return;
|
56 |
| |
57 |
2
| Location location = AnnotationUtils.buildLocationForAnnotation(method, iv, classResource);
|
58 |
| |
59 |
2
| String propertyName = AnnotationUtils.getPropertyName(method);
|
60 |
| |
61 |
| |
62 |
| |
63 |
2
| IPropertySpecification pspec = new PropertySpecification();
|
64 |
| |
65 |
2
| pspec.setName(propertyName);
|
66 |
2
| pspec.setLocation(location);
|
67 |
2
| pspec.setInitialValue(iv.value());
|
68 |
| |
69 |
2
| spec.addPropertySpecification(pspec);
|
70 |
| } |
71 |
| } |