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