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