Clover coverage report - Code Coverage for tapestry release 4.0-beta-1
Coverage timestamp: Fri Jun 24 2005 14:32:46 EDT
file stats: LOC: 109   Methods: 3
NCLOC: 55   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DirectCallback.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.callback;
 16   
 17    import org.apache.hivemind.ApplicationRuntimeException;
 18    import org.apache.hivemind.util.Defense;
 19    import org.apache.tapestry.IComponent;
 20    import org.apache.tapestry.IDirect;
 21    import org.apache.tapestry.IPage;
 22    import org.apache.tapestry.IRequestCycle;
 23    import org.apache.tapestry.Tapestry;
 24   
 25    /**
 26    * Simple callback for re-invoking a {@link IDirect} trigger.
 27    *
 28    * @author Howard Lewis Ship
 29    * @since 0.2.9
 30    */
 31   
 32    public class DirectCallback implements ICallback
 33    {
 34    /**
 35    * @since 2.0.4
 36    */
 37   
 38    private static final long serialVersionUID = -8888847655917503471L;
 39   
 40    private String _pageName;
 41   
 42    private String _componentIdPath;
 43   
 44    private Object[] _parameters;
 45   
 46  4 public String toString()
 47    {
 48  4 StringBuffer buffer = new StringBuffer("DirectCallback[");
 49   
 50  4 buffer.append(_pageName);
 51  4 buffer.append('/');
 52  4 buffer.append(_componentIdPath);
 53   
 54  4 if (_parameters != null)
 55    {
 56  2 for (int i = 0; i < _parameters.length; i++)
 57    {
 58  5 buffer.append(i == 0 ? " " : ", ");
 59  5 buffer.append(_parameters[i]);
 60    }
 61    }
 62   
 63  4 buffer.append(']');
 64   
 65  4 return buffer.toString();
 66   
 67    }
 68   
 69    /**
 70    * Creates a new DirectCallback for the component. The parameters (which may be null) is
 71    * retained, not copied.
 72    */
 73   
 74  4 public DirectCallback(IDirect component, Object[] parameters)
 75    {
 76  4 Defense.notNull(component, "component");
 77   
 78  4 _pageName = component.getPage().getPageName();
 79  4 _componentIdPath = component.getIdPath();
 80  4 _parameters = parameters;
 81    }
 82   
 83    /**
 84    * Locates the {@link IDirect}component that was previously identified (and whose page and id
 85    * path were stored). Invokes {@link IRequestCycle#setListenerParameters(Object[])(Object[])}to
 86    * restore the service parameters, then invokes {@link IDirect#trigger(IRequestCycle)}on the
 87    * component.
 88    */
 89   
 90  4 public void performCallback(IRequestCycle cycle)
 91    {
 92  4 IPage page = cycle.getPage(_pageName);
 93  4 IComponent component = page.getNestedComponent(_componentIdPath);
 94  4 IDirect direct = null;
 95   
 96  4 try
 97    {
 98  4 direct = (IDirect) component;
 99    }
 100    catch (ClassCastException ex)
 101    {
 102  1 throw new ApplicationRuntimeException(CallbackMessages.componentNotDirect(component),
 103    component, null, ex);
 104    }
 105   
 106  3 cycle.setListenerParameters(_parameters);
 107  3 direct.trigger(cycle);
 108    }
 109    }