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