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