Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
SyntheticListener |
|
| 1.0;1 |
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.listener; |
|
16 | ||
17 | import org.apache.hivemind.util.Defense; |
|
18 | import org.apache.tapestry.IActionListener; |
|
19 | import org.apache.tapestry.IComponent; |
|
20 | import org.apache.tapestry.IRequestCycle; |
|
21 | ||
22 | /** |
|
23 | * Adapter class that combines a target object (typically, a component) with a |
|
24 | * {@link org.apache.tapestry.listener.ListenerMethodInvoker}. This is the |
|
25 | * bridge from listener method names to listener method invocations. |
|
26 | * <p> |
|
27 | * TODO: It would really be nice if we could get the location of the listener |
|
28 | * binding into thrown exceptions. As implemented, as best, it will be the |
|
29 | * location of the <page-specification> (or <component>) of the page |
|
30 | * (or component) containing the listener method. |
|
31 | * |
|
32 | * @author Howard M. Lewis Ship |
|
33 | * @since 4.0 |
|
34 | */ |
|
35 | public class SyntheticListener implements IActionListener |
|
36 | { |
|
37 | private final Object _target; |
|
38 | ||
39 | private final ListenerMethodInvoker _invoker; |
|
40 | ||
41 | public SyntheticListener(Object target, ListenerMethodInvoker invoker) |
|
42 | 13 | { |
43 | 13 | Defense.notNull(target, "target"); |
44 | 13 | Defense.notNull(invoker, "invoker"); |
45 | ||
46 | 13 | _target = target; |
47 | 13 | _invoker = invoker; |
48 | 13 | } |
49 | ||
50 | public void actionTriggered(IComponent component, IRequestCycle cycle) |
|
51 | { |
|
52 | 13 | _invoker.invokeListenerMethod(_target, cycle); |
53 | 10 | } |
54 | ||
55 | public String getMethodName() |
|
56 | { |
|
57 | 0 | return _invoker.getMethodName(); |
58 | } |
|
59 | ||
60 | public String toString() |
|
61 | { |
|
62 | 0 | return "SyntheticListener[methodName = " + _invoker.getMethodName() + "]"; |
63 | } |
|
64 | } |