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 |
4 |
public class EventListenerAnnotationWorker implements SecondaryAnnotationWorker |
30 |
|
{ |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
public boolean canEnhance(Method method) |
35 |
|
{ |
36 |
5 |
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 |
3 |
EventListener listener = method.getAnnotation(EventListener.class); |
45 |
|
|
46 |
3 |
String[] targets = listener.targets(); |
47 |
3 |
String[] elements = listener.elements(); |
48 |
3 |
String formId = listener.submitForm(); |
49 |
3 |
boolean validateForm = listener.validateForm(); |
50 |
3 |
boolean async = listener.async(); |
51 |
3 |
boolean focus = listener.focus(); |
52 |
3 |
boolean autoSubmit = listener.autoSubmit(); |
53 |
|
|
54 |
3 |
if (targets.length < 1 && elements.length < 1) |
55 |
1 |
throw new ApplicationRuntimeException(AnnotationMessages.targetsNotFound(method)); |
56 |
|
|
57 |
4 |
for (int i=0; i < targets.length; i++) |
58 |
|
{ |
59 |
2 |
spec.addEventListener(targets[i], listener.events(), |
60 |
|
method.getName(), formId, validateForm, async, focus, autoSubmit); |
61 |
|
} |
62 |
|
|
63 |
3 |
for (int i=0; i < elements.length; i++) |
64 |
|
{ |
65 |
1 |
spec.addElementEventListener(elements[i], listener.events(), |
66 |
|
method.getName(), formId, validateForm, async, focus); |
67 |
|
} |
68 |
2 |
} |
69 |
|
} |