Clover coverage report - Code Coverage for tapestry release 4.0-alpha-3
Coverage timestamp: Mon May 16 2005 09:05:49 EDT
file stats: LOC: 111   Methods: 3
NCLOC: 56   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
DirectCallback.java 75% 95.7% 100% 93.3%
coverage 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.tapestry.IComponent;
 19   
 import org.apache.tapestry.IDirect;
 20   
 import org.apache.tapestry.IPage;
 21   
 import org.apache.tapestry.IRequestCycle;
 22   
 import org.apache.tapestry.Tapestry;
 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  1
     public String toString()
 46   
     {
 47  1
         StringBuffer buffer = new StringBuffer("DirectCallback[");
 48   
 
 49  1
         buffer.append(_pageName);
 50  1
         buffer.append('/');
 51  1
         buffer.append(_componentIdPath);
 52   
 
 53  1
         if (_parameters != null)
 54   
         {
 55  1
             String sep = " ";
 56   
 
 57  1
             for (int i = 0; i < _parameters.length; i++)
 58   
             {
 59  3
                 buffer.append(sep);
 60  3
                 buffer.append(_parameters[i]);
 61   
 
 62  3
                 sep = ", ";
 63   
             }
 64   
         }
 65   
 
 66  1
         buffer.append(']');
 67   
 
 68  1
         return buffer.toString();
 69   
 
 70   
     }
 71   
 
 72   
     /**
 73   
      * Creates a new DirectCallback for the component. The parameters (which may be null) is
 74   
      * retained, not copied.
 75   
      */
 76   
 
 77  1
     public DirectCallback(IDirect component, Object[] parameters)
 78   
     {
 79  1
         _pageName = component.getPage().getPageName();
 80  1
         _componentIdPath = component.getIdPath();
 81  1
         _parameters = parameters;
 82   
     }
 83   
 
 84   
     /**
 85   
      * Locates the {@link IDirect}component that was previously identified (and whose page and id
 86   
      * path were stored). Invokes {@link IRequestCycle#setListenerParameters(Object[])(Object[])}to
 87   
      * restore the service parameters, then invokes {@link IDirect#trigger(IRequestCycle)}on the
 88   
      * component.
 89   
      */
 90   
 
 91  1
     public void performCallback(IRequestCycle cycle)
 92   
     {
 93  1
         IPage page = cycle.getPage(_pageName);
 94  1
         IComponent component = page.getNestedComponent(_componentIdPath);
 95  1
         IDirect direct = null;
 96   
 
 97  1
         try
 98   
         {
 99  1
             direct = (IDirect) component;
 100   
         }
 101   
         catch (ClassCastException ex)
 102   
         {
 103  0
             throw new ApplicationRuntimeException(Tapestry.format(
 104   
                     "DirectCallback.wrong-type",
 105   
                     component.getExtendedId()), component, null, ex);
 106   
         }
 107   
 
 108  1
         cycle.setListenerParameters(_parameters);
 109  1
         direct.trigger(cycle);
 110   
     }
 111   
 }