Coverage Report - org.apache.tapestry.listener.ListenerMapImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ListenerMapImpl
0%
0/24
0%
0/4
1.833
 
 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  
 import org.apache.tapestry.IComponent;
 26  
 import org.apache.tapestry.TapestryUtils;
 27  
 
 28  
 /**
 29  
  * @author Howard M. Lewis Ship
 30  
  * @since 4.0
 31  
  */
 32  
 public class ListenerMapImpl implements ListenerMap
 33  
 {
 34  
 
 35  
     private final Object _target;
 36  
 
 37  
     /**
 38  
      * Keyed on String method name, value is
 39  
      * {@link org.apache.tapestry.listener.ListenerMethodInvoker}.
 40  
      */
 41  
 
 42  
     private final Map _invokers;
 43  
 
 44  0
     private final Map _listeners = new HashMap();
 45  
 
 46  
     public ListenerMapImpl(Object target, Map invokers)
 47  0
     {
 48  0
         Defense.notNull(target, "target");
 49  0
         Defense.notNull(invokers, "invokers");
 50  
 
 51  0
         _target = target;
 52  0
         _invokers = invokers;
 53  0
     }
 54  
 
 55  
     public boolean canProvideListener(String name)
 56  
     {
 57  0
         return _invokers.containsKey(name);
 58  
     }
 59  
 
 60  
     public synchronized IActionListener getListener(String name)
 61  
     {
 62  0
         IActionListener result = (IActionListener) _listeners.get(name);
 63  
 
 64  0
         if (result == null)
 65  
         {
 66  0
             result = createListener(name);
 67  0
             _listeners.put(name, result);
 68  
         }
 69  
 
 70  0
         return result;
 71  
     }
 72  
 
 73  
         public IActionListener getImplicitListener(IComponent component)
 74  
         {
 75  
                 IActionListener listener;
 76  0
                 String generatedName = "do" + TapestryUtils.capitalize(component.getId());
 77  
                 try
 78  
                 {
 79  0
                         listener = getListener(generatedName);
 80  
                 }
 81  0
                 catch (ApplicationRuntimeException e)
 82  
                 {
 83  0
                         throw new ApplicationRuntimeException(ListenerMessages.noImplicitListenerMethodFound(generatedName, component), component, null, e);
 84  0
                 }
 85  
 
 86  0
                 return listener;
 87  
         }
 88  
 
 89  
         private IActionListener createListener(String name)
 90  
     {
 91  0
         ListenerMethodInvoker invoker = (ListenerMethodInvoker) _invokers.get(name);
 92  
 
 93  0
         if (invoker == null)
 94  0
             throw new ApplicationRuntimeException(ListenerMessages.objectMissingMethod(_target, name),
 95  
                                                   _target, null, null);
 96  
 
 97  0
         return new SyntheticListener(_target, invoker);
 98  
     }
 99  
 
 100  
     public Collection getListenerNames()
 101  
     {
 102  0
         return Collections.unmodifiableCollection(_invokers.keySet());
 103  
     }
 104  
 }