1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.binding; |
16 |
| |
17 |
| import org.apache.hivemind.Location; |
18 |
| import org.apache.hivemind.util.Defense; |
19 |
| import org.apache.tapestry.BindingException; |
20 |
| import org.apache.tapestry.IActionListener; |
21 |
| import org.apache.tapestry.IComponent; |
22 |
| import org.apache.tapestry.IRequestCycle; |
23 |
| import org.apache.tapestry.PageRedirectException; |
24 |
| import org.apache.tapestry.RedirectException; |
25 |
| import org.apache.tapestry.coerce.ValueConverter; |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| public class ListenerMethodBinding extends AbstractBinding implements IActionListener |
32 |
| { |
33 |
| private final IComponent _component; |
34 |
| |
35 |
| private final String _methodName; |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| private IActionListener _listener; |
43 |
| |
44 |
46
| public ListenerMethodBinding(IComponent component, String methodName, String description,
|
45 |
| ValueConverter valueConverter, Location location) |
46 |
| { |
47 |
46
| super(description, valueConverter, location);
|
48 |
| |
49 |
46
| Defense.notNull(component, "component");
|
50 |
46
| Defense.notNull(methodName, "methodName");
|
51 |
| |
52 |
46
| _component = component;
|
53 |
46
| _methodName = methodName;
|
54 |
| } |
55 |
| |
56 |
1
| public Object getComponent()
|
57 |
| { |
58 |
1
| return _component;
|
59 |
| } |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
24
| public Object getObject()
|
66 |
| { |
67 |
24
| return this;
|
68 |
| } |
69 |
| |
70 |
40
| public void actionTriggered(IComponent component, IRequestCycle cycle)
|
71 |
| { |
72 |
40
| try
|
73 |
| { |
74 |
40
| if (_listener == null)
|
75 |
27
| _listener = _component.getListeners().getListener(_methodName);
|
76 |
| |
77 |
40
| _listener.actionTriggered(component, cycle);
|
78 |
| } |
79 |
| catch (PageRedirectException ex) |
80 |
| { |
81 |
3
| throw ex;
|
82 |
| } |
83 |
| catch (RedirectException ex) |
84 |
| { |
85 |
1
| throw ex;
|
86 |
| } |
87 |
| catch (RuntimeException ex) |
88 |
| { |
89 |
1
| throw new BindingException(BindingMessages.listenerMethodFailure(
|
90 |
| _component, |
91 |
| _methodName, |
92 |
| ex), _component, getLocation(), this, ex); |
93 |
| } |
94 |
| } |
95 |
| |
96 |
1
| protected void extendDescription(StringBuffer buffer)
|
97 |
| { |
98 |
1
| buffer.append(", component=");
|
99 |
1
| buffer.append(_component.getExtendedId());
|
100 |
1
| buffer.append(", methodName=");
|
101 |
1
| buffer.append(_methodName);
|
102 |
| } |
103 |
| |
104 |
| } |