Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
InvokeListener |
|
| 1.25;1.25 |
1 | // Copyright 2005 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | ||
15 | package org.apache.tapestry.components; |
|
16 | ||
17 | import org.apache.tapestry.AbstractComponent; |
|
18 | import org.apache.tapestry.IActionListener; |
|
19 | import org.apache.tapestry.IMarkupWriter; |
|
20 | import org.apache.tapestry.IRequestCycle; |
|
21 | import org.apache.tapestry.link.DirectLink; |
|
22 | import org.apache.tapestry.listener.ListenerInvoker; |
|
23 | ||
24 | /** |
|
25 | * Invokes a listener method, passing listener parameters. This is used when a |
|
26 | * page or component needs some setup logic that can be best accomplished in |
|
27 | * Java code. If the listener parameter is not bound, attempt to locate an |
|
28 | * implicit listener named by the capitalized component id, prefixed by "do". |
|
29 | * |
|
30 | * @author Howard M. Lewis Ship |
|
31 | * @since 4.0 |
|
32 | */ |
|
33 | 2 | public abstract class InvokeListener extends AbstractComponent |
34 | { |
|
35 | ||
36 | protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
|
37 | { |
|
38 | 2 | Object[] parameters = DirectLink |
39 | .constructServiceParameters(getParameters()); |
|
40 | ||
41 | try |
|
42 | { |
|
43 | 2 | cycle.setListenerParameters(parameters); |
44 | ||
45 | 2 | IActionListener listener = getListener(); |
46 | ||
47 | 2 | if (listener == null) |
48 | 0 | listener = getContainer().getListeners().getImplicitListener(this); |
49 | ||
50 | 2 | getListenerInvoker().invokeListener(listener, this, cycle); |
51 | } |
|
52 | finally |
|
53 | { |
|
54 | 2 | cycle.setListenerParameters(null); |
55 | 1 | } |
56 | 1 | } |
57 | ||
58 | /** Parameter. */ |
|
59 | public abstract IActionListener getListener(); |
|
60 | ||
61 | /** Parameter. */ |
|
62 | public abstract Object getParameters(); |
|
63 | ||
64 | /** Injected. */ |
|
65 | public abstract ListenerInvoker getListenerInvoker(); |
|
66 | } |