|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ListenerMapImpl.java | 100% | 100% | 100% | 100% |
|
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 java.util.Collection;
|
|
18 |
import java.util.Collections;
|
|
19 |
import java.util.HashMap;
|
|
20 |
import java.util.Map;
|
|
21 |
|
|
22 |
import org.apache.hivemind.ApplicationRuntimeException;
|
|
23 |
import org.apache.hivemind.util.Defense;
|
|
24 |
import org.apache.tapestry.IActionListener;
|
|
25 |
|
|
26 |
/**
|
|
27 |
* @author Howard M. Lewis Ship
|
|
28 |
* @since 4.0
|
|
29 |
*/
|
|
30 |
public class ListenerMapImpl implements ListenerMap |
|
31 |
{ |
|
32 |
private final Object _target;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Keyed on String method name, value is
|
|
36 |
* {@link org.apache.tapestry.listener.ListenerMethodInvoker}.
|
|
37 |
*/
|
|
38 |
|
|
39 |
private final Map _invokers;
|
|
40 |
|
|
41 |
private final Map _listeners = new HashMap(); |
|
42 |
|
|
43 | 40 |
public ListenerMapImpl(Object target, Map invokers)
|
44 |
{ |
|
45 | 40 |
Defense.notNull(target, "target");
|
46 | 40 |
Defense.notNull(invokers, "invokers");
|
47 |
|
|
48 | 40 |
_target = target; |
49 | 40 |
_invokers = invokers; |
50 |
} |
|
51 |
|
|
52 | 9 |
public boolean canProvideListener(String name) |
53 |
{ |
|
54 | 9 |
return _invokers.containsKey(name);
|
55 |
} |
|
56 |
|
|
57 | 45 |
public synchronized IActionListener getListener(String name) |
58 |
{ |
|
59 | 45 |
IActionListener result = (IActionListener) _listeners.get(name); |
60 |
|
|
61 | 45 |
if (result == null) |
62 |
{ |
|
63 | 41 |
result = createListener(name); |
64 | 40 |
_listeners.put(name, result); |
65 |
} |
|
66 |
|
|
67 | 44 |
return result;
|
68 |
} |
|
69 |
|
|
70 | 41 |
private IActionListener createListener(String name)
|
71 |
{ |
|
72 | 41 |
ListenerMethodInvoker invoker = (ListenerMethodInvoker) _invokers.get(name); |
73 |
|
|
74 | 41 |
if (invoker == null) |
75 | 1 |
throw new ApplicationRuntimeException(ListenerMessages.objectMissingMethod( |
76 |
_target, |
|
77 |
name), _target, null, null); |
|
78 |
|
|
79 | 40 |
return new SyntheticListener(_target, invoker); |
80 |
} |
|
81 |
|
|
82 | 2 |
public Collection getListenerNames()
|
83 |
{ |
|
84 | 2 |
return Collections.unmodifiableCollection(_invokers.keySet());
|
85 |
} |
|
86 |
} |
|