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