1 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 30 public class ListenerMapImpl implements ListenerMap 31 { 32 private final Object _target; 33 34 38 39 private final Map _invokers; 40 41 private final Map _listeners = new HashMap (); 42 43 public ListenerMapImpl(Object target, Map invokers) 44 { 45 Defense.notNull(target, "target"); 46 Defense.notNull(invokers, "invokers"); 47 48 _target = target; 49 _invokers = invokers; 50 } 51 52 public boolean canProvideListener(String name) 53 { 54 return _invokers.containsKey(name); 55 } 56 57 public synchronized IActionListener getListener(String name) 58 { 59 IActionListener result = (IActionListener) _listeners.get(name); 60 61 if (result == null) 62 { 63 result = createListener(name); 64 _listeners.put(name, result); 65 } 66 67 return result; 68 } 69 70 private IActionListener createListener(String name) 71 { 72 ListenerMethodInvoker invoker = (ListenerMethodInvoker) _invokers.get(name); 73 74 if (invoker == null) 75 throw new ApplicationRuntimeException(ListenerMessages.objectMissingMethod( 76 _target, 77 name), _target, null, null); 78 79 return new SyntheticListener(_target, invoker); 80 } 81 82 public Collection getListenerNames() 83 { 84 return Collections.unmodifiableCollection(_invokers.keySet()); 85 } 86 } | Popular Tags |