Coverage Report - org.apache.tapestry.binding.ListenerMethodBinding
 
Classes in this File Line Coverage Branch Coverage Complexity
ListenerMethodBinding
0%
0/27
0%
0/2
2.5
 
 1  
 // Copyright 2004, 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.binding;
 16  
 
 17  
 import org.apache.hivemind.Location;
 18  
 import org.apache.hivemind.util.Defense;
 19  
 import org.apache.tapestry.*;
 20  
 import org.apache.tapestry.coerce.ValueConverter;
 21  
 
 22  
 /**
 23  
  * @author Howard M. Lewis Ship
 24  
  * @since 4.0
 25  
  */
 26  
 public class ListenerMethodBinding extends AbstractBinding implements IActionListener
 27  
 {
 28  
     private final IComponent _component;
 29  
 
 30  
     private final String _methodName;
 31  
 
 32  
     // We have to defer obtaining the listener until after the page is loaded, because it is
 33  
     // (currently) reliant on the page's engine property to gain access to the
 34  
     // ListenerMapSource. I'd prefer it if this was a final field, resolved by the constructor,
 35  
     // but that will involve injecting the ListenerMapSource into AbstractComponent.
 36  
 
 37  
     private IActionListener _listener;
 38  
 
 39  
     public ListenerMethodBinding(String description, ValueConverter valueConverter, Location location,
 40  
                                  IComponent component, String methodName)
 41  
     {
 42  0
         super(description, valueConverter, location);
 43  
 
 44  0
         Defense.notNull(component, "component");
 45  0
         Defense.notNull(methodName, "methodName");
 46  
 
 47  0
         _component = component;
 48  0
         _methodName = methodName;
 49  0
     }
 50  
 
 51  
     public Object getComponent()
 52  
     {
 53  0
         return _component;
 54  
     }
 55  
 
 56  
     /**
 57  
      * Returns this binding object; the binding object delegates to the actual listener. This allows
 58  
      * us to intercept errors and report the location of the binding.
 59  
      */
 60  
     public Object getObject()
 61  
     {
 62  0
         return this;
 63  
     }
 64  
 
 65  
     public String getMethodName()
 66  
     {
 67  0
         return _methodName;
 68  
     }
 69  
 
 70  
     public void actionTriggered(IComponent component, IRequestCycle cycle)
 71  
     {
 72  
         try
 73  
         {
 74  0
             if (_listener == null)
 75  0
                 _listener = _component.getListeners().getListener(_methodName);
 76  
 
 77  0
             _listener.actionTriggered(component, cycle);
 78  
         }
 79  0
         catch (PageRedirectException ex)
 80  
         {
 81  0
             throw ex;
 82  
         }
 83  0
         catch (RedirectException ex)
 84  
         {
 85  0
             throw ex;
 86  
         }
 87  0
         catch (RenderRewoundException ex)
 88  
         {
 89  0
             throw ex;
 90  
         }
 91  0
         catch (RuntimeException ex)
 92  
         {
 93  0
             throw new BindingException(BindingMessages.listenerMethodFailure(
 94  
               _component,
 95  
               _methodName,
 96  
               ex), _component, getLocation(), this, ex);
 97  0
         }
 98  0
     }
 99  
 
 100  
     protected void extendDescription(StringBuffer buffer)
 101  
     {
 102  0
         buffer.append(", component=");
 103  0
         buffer.append(_component.getExtendedId());
 104  0
         buffer.append(", methodName=");
 105  0
         buffer.append(_methodName);
 106  0
     }
 107  
 }