1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
package org.apache.tapestry.callback; |
16 |
|
|
17 |
|
import org.apache.hivemind.ApplicationRuntimeException; |
18 |
|
import org.apache.hivemind.util.Defense; |
19 |
|
import org.apache.tapestry.IComponent; |
20 |
|
import org.apache.tapestry.IDirect; |
21 |
|
import org.apache.tapestry.IPage; |
22 |
|
import org.apache.tapestry.IRequestCycle; |
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
public class DirectCallback implements ICallback |
32 |
|
{ |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
private static final long serialVersionUID = -8888847655917503471L; |
38 |
|
|
39 |
|
private String _pageName; |
40 |
|
|
41 |
|
private String _componentIdPath; |
42 |
|
|
43 |
|
private Object[] _parameters; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
public DirectCallback(IDirect component, Object[] parameters) |
51 |
3 |
{ |
52 |
3 |
Defense.notNull(component, "component"); |
53 |
|
|
54 |
3 |
_pageName = component.getPage().getPageName(); |
55 |
3 |
_componentIdPath = component.getIdPath(); |
56 |
3 |
_parameters = parameters; |
57 |
3 |
} |
58 |
|
|
59 |
|
public String toString() |
60 |
|
{ |
61 |
3 |
StringBuffer buffer = new StringBuffer("DirectCallback["); |
62 |
|
|
63 |
3 |
buffer.append(_pageName); |
64 |
3 |
buffer.append('/'); |
65 |
3 |
buffer.append(_componentIdPath); |
66 |
|
|
67 |
3 |
if (_parameters != null) |
68 |
|
{ |
69 |
3 |
for (int i = 0; i < _parameters.length; i++) |
70 |
|
{ |
71 |
2 |
buffer.append(i == 0 ? " " : ", "); |
72 |
2 |
buffer.append(_parameters[i]); |
73 |
|
} |
74 |
|
} |
75 |
|
|
76 |
3 |
buffer.append(']'); |
77 |
|
|
78 |
3 |
return buffer.toString(); |
79 |
|
|
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
public void performCallback(IRequestCycle cycle) |
90 |
|
{ |
91 |
3 |
IPage page = cycle.getPage(_pageName); |
92 |
3 |
IComponent component = page.getNestedComponent(_componentIdPath); |
93 |
3 |
IDirect direct = null; |
94 |
|
|
95 |
|
try |
96 |
|
{ |
97 |
3 |
direct = (IDirect) component; |
98 |
|
} |
99 |
1 |
catch (ClassCastException ex) |
100 |
|
{ |
101 |
1 |
throw new ApplicationRuntimeException(CallbackMessages.componentNotDirect(component), |
102 |
|
component, null, ex); |
103 |
2 |
} |
104 |
|
|
105 |
2 |
cycle.setListenerParameters(_parameters); |
106 |
2 |
direct.trigger(cycle); |
107 |
2 |
} |
108 |
|
} |