1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package org.apache.tapestry.annotations; |
15 | |
|
16 | |
import org.apache.hivemind.ApplicationRuntimeException; |
17 | |
import org.apache.hivemind.Resource; |
18 | |
import org.apache.tapestry.enhance.EnhancementOperation; |
19 | |
import org.apache.tapestry.spec.IComponentSpecification; |
20 | |
|
21 | |
import java.lang.reflect.Method; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | 0 | public class EventListenerAnnotationWorker implements SecondaryAnnotationWorker |
30 | |
{ |
31 | |
|
32 | |
|
33 | |
|
34 | |
public boolean canEnhance(Method method) |
35 | |
{ |
36 | 0 | return method.getAnnotation(EventListener.class) != null; |
37 | |
} |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public void peformEnhancement(EnhancementOperation op, IComponentSpecification spec, Method method, Resource classResource) |
43 | |
{ |
44 | 0 | EventListener listener = method.getAnnotation(EventListener.class); |
45 | |
|
46 | 0 | String[] targets = listener.targets(); |
47 | 0 | String[] elements = listener.elements(); |
48 | 0 | String formId = listener.submitForm(); |
49 | 0 | boolean validateForm = listener.validateForm(); |
50 | 0 | boolean async = listener.async(); |
51 | 0 | boolean focus = listener.focus(); |
52 | 0 | boolean autoSubmit = listener.autoSubmit(); |
53 | |
|
54 | 0 | if (targets.length < 1 && elements.length < 1) |
55 | 0 | throw new ApplicationRuntimeException(AnnotationMessages.targetsNotFound(method)); |
56 | |
|
57 | 0 | for (int i=0; i < targets.length; i++) |
58 | |
{ |
59 | 0 | spec.addEventListener(targets[i], listener.events(), |
60 | |
method.getName(), formId, validateForm, async, focus, autoSubmit); |
61 | |
} |
62 | |
|
63 | 0 | for (int i=0; i < elements.length; i++) |
64 | |
{ |
65 | 0 | spec.addElementEventListener(elements[i], listener.events(), |
66 | |
method.getName(), formId, validateForm, async, focus); |
67 | |
} |
68 | 0 | } |
69 | |
} |