|
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 |
12
| public String toString()
|
|
46 |
| { |
|
47 |
12
| StringBuffer buffer = new StringBuffer("DirectCallback[");
|
|
48 |
| |
|
49 |
12
| buffer.append(_pageName);
|
|
50 |
12
| buffer.append('/');
|
|
51 |
12
| buffer.append(_componentIdPath);
|
|
52 |
| |
|
53 |
12
| if (_parameters != null)
|
|
54 |
| { |
|
55 |
6
| for (int i = 0; i < _parameters.length; i++)
|
|
56 |
| { |
|
57 |
15
| buffer.append(i == 0 ? " " : ", ");
|
|
58 |
15
| buffer.append(_parameters[i]);
|
|
59 |
| } |
|
60 |
| } |
|
61 |
| |
|
62 |
12
| buffer.append(']');
|
|
63 |
| |
|
64 |
12
| return buffer.toString();
|
|
65 |
| |
|
66 |
| } |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
12
| public DirectCallback(IDirect component, Object[] parameters)
|
|
74 |
| { |
|
75 |
12
| Defense.notNull(component, "component");
|
|
76 |
| |
|
77 |
12
| _pageName = component.getPage().getPageName();
|
|
78 |
12
| _componentIdPath = component.getIdPath();
|
|
79 |
12
| _parameters = parameters;
|
|
80 |
| } |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
12
| public void performCallback(IRequestCycle cycle)
|
|
90 |
| { |
|
91 |
12
| IPage page = cycle.getPage(_pageName);
|
|
92 |
12
| IComponent component = page.getNestedComponent(_componentIdPath);
|
|
93 |
12
| IDirect direct = null;
|
|
94 |
| |
|
95 |
12
| try
|
|
96 |
| { |
|
97 |
12
| direct = (IDirect) component;
|
|
98 |
| } |
|
99 |
| catch (ClassCastException ex) |
|
100 |
| { |
|
101 |
3
| throw new ApplicationRuntimeException(CallbackMessages.componentNotDirect(component),
|
|
102 |
| component, null, ex); |
|
103 |
| } |
|
104 |
| |
|
105 |
9
| cycle.setListenerParameters(_parameters);
|
|
106 |
9
| direct.trigger(cycle);
|
|
107 |
| } |
|
108 |
| } |