Clover coverage report - Code Coverage for tapestry release 3.1-alpha-1
Coverage timestamp: Mon Feb 21 2005 09:16:14 EST
file stats: LOC: 116   Methods: 3
NCLOC: 58   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} component trigger..
 26   
  *
 27   
  *  @author Howard Lewis Ship
 28   
  *  @since 0.2.9
 29   
  *
 30   
  **/
 31   
 
 32   
 public class DirectCallback implements ICallback
 33   
 {
 34   
     /**
 35   
      *  @since 2.0.4
 36   
      * 
 37   
      **/
 38   
 
 39   
     private static final long serialVersionUID = -8888847655917503471L;
 40   
 
 41   
     private String _pageName;
 42   
     private String _componentIdPath;
 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
 74   
      *  (which may be null) is retained, not copied.
 75   
      *
 76   
      **/
 77   
 
 78  1
     public DirectCallback(IDirect component, Object[] parameters)
 79   
     {
 80  1
         _pageName = component.getPage().getPageName();
 81  1
         _componentIdPath = component.getIdPath();
 82  1
         _parameters = parameters;
 83   
     }
 84   
 
 85   
     /**
 86   
      *  Locates the {@link IDirect} component that was previously identified
 87   
      *  (and whose page and id path were stored).
 88   
      *  Invokes {@link IRequestCycle#setServiceParameters(Object[])} to
 89   
      *  restore the service parameters, then
 90   
      *  invokes {@link IDirect#trigger(IRequestCycle)} on the component.
 91   
      *
 92   
      **/
 93   
 
 94  1
     public void performCallback(IRequestCycle cycle)
 95   
     {
 96  1
         IPage page = cycle.getPage(_pageName);
 97  1
         IComponent component = page.getNestedComponent(_componentIdPath);
 98  1
         IDirect direct = null;
 99   
 
 100  1
         try
 101   
         {
 102  1
             direct = (IDirect) component;
 103   
         }
 104   
         catch (ClassCastException ex)
 105   
         {
 106  0
             throw new ApplicationRuntimeException(
 107   
                 Tapestry.format("DirectCallback.wrong-type", component.getExtendedId()),
 108   
                 component,
 109   
                 null,
 110   
                 ex);
 111   
         }
 112   
 
 113  1
         cycle.setServiceParameters(_parameters);
 114  1
         direct.trigger(cycle);
 115   
     }
 116   
 }