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 |
7 |
super(description, valueConverter, location); |
43 |
|
|
44 |
7 |
Defense.notNull(component, "component"); |
45 |
7 |
Defense.notNull(methodName, "methodName"); |
46 |
|
|
47 |
7 |
_component = component; |
48 |
7 |
_methodName = methodName; |
49 |
7 |
} |
50 |
|
|
51 |
|
public Object getComponent() |
52 |
|
{ |
53 |
1 |
return _component; |
54 |
|
} |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
public Object getObject() |
61 |
|
{ |
62 |
1 |
return this; |
63 |
|
} |
64 |
|
|
65 |
|
public String getMethodName() |
66 |
|
{ |
67 |
1 |
return _methodName; |
68 |
|
} |
69 |
|
|
70 |
|
public void actionTriggered(IComponent component, IRequestCycle cycle) |
71 |
|
{ |
72 |
|
try |
73 |
|
{ |
74 |
5 |
if (_listener == null) |
75 |
5 |
_listener = _component.getListeners().getListener(_methodName); |
76 |
|
|
77 |
5 |
_listener.actionTriggered(component, cycle); |
78 |
|
} |
79 |
1 |
catch (PageRedirectException ex) |
80 |
|
{ |
81 |
1 |
throw ex; |
82 |
|
} |
83 |
1 |
catch (RedirectException ex) |
84 |
|
{ |
85 |
1 |
throw ex; |
86 |
|
} |
87 |
1 |
catch (RenderRewoundException ex) |
88 |
|
{ |
89 |
1 |
throw ex; |
90 |
|
} |
91 |
1 |
catch (RuntimeException ex) |
92 |
|
{ |
93 |
1 |
throw new BindingException(BindingMessages.listenerMethodFailure( |
94 |
|
_component, |
95 |
|
_methodName, |
96 |
|
ex), _component, getLocation(), this, ex); |
97 |
1 |
} |
98 |
1 |
} |
99 |
|
|
100 |
|
protected void extendDescription(StringBuffer buffer) |
101 |
|
{ |
102 |
1 |
buffer.append(", component="); |
103 |
1 |
buffer.append(_component.getExtendedId()); |
104 |
1 |
buffer.append(", methodName="); |
105 |
1 |
buffer.append(_methodName); |
106 |
1 |
} |
107 |
|
} |