Clover coverage report - Code Coverage for tapestry release 4.0-alpha-2
Coverage timestamp: Thu May 5 2005 09:57:44 EDT
file stats: LOC: 110   Methods: 3
NCLOC: 40   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
DirectLink.java 75% 86.7% 100% 84.6%
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.link;
 16   
 
 17   
 import java.util.List;
 18   
 
 19   
 import org.apache.tapestry.IActionListener;
 20   
 import org.apache.tapestry.IDirect;
 21   
 import org.apache.tapestry.IRequestCycle;
 22   
 import org.apache.tapestry.Tapestry;
 23   
 import org.apache.tapestry.engine.DirectServiceParameter;
 24   
 import org.apache.tapestry.engine.ILink;
 25   
 
 26   
 /**
 27   
  * A component for creating a link using the direct service; used for actions that are not dependant
 28   
  * on dynamic page state. [ <a href="../../../../../ComponentReference/DirectLink.html">Component
 29   
  * Reference </a>]
 30   
  * 
 31   
  * @author Howard Lewis Ship
 32   
  */
 33   
 
 34   
 public abstract class DirectLink extends AbstractLinkComponent implements IDirect
 35   
 {
 36   
     public abstract IActionListener getListener();
 37   
 
 38   
     /**
 39   
      * Returns true if the stateful parameter is bound to a true value. If stateful is not bound,
 40   
      * also returns the default, true.
 41   
      */
 42   
 
 43   
     public abstract boolean isStateful();
 44   
 
 45  52
     public ILink getLink(IRequestCycle cycle)
 46   
     {
 47  52
         Object[] serviceParameters = constructServiceParameters(getParameters());
 48   
 
 49  52
         DirectServiceParameter dsp = new DirectServiceParameter(this, serviceParameters);
 50   
 
 51  52
         return getLink(cycle, Tapestry.DIRECT_SERVICE, dsp);
 52   
     }
 53   
 
 54   
     /**
 55   
      * Converts a service parameters value to an array of objects. This is used by the
 56   
      * {@link DirectLink},{@link ServiceLink}and {@link ExternalLink}components.
 57   
      * 
 58   
      * @param parameterValue
 59   
      *            the input value which may be
 60   
      *            <ul>
 61   
      *            <li>null (returns null)
 62   
      *            <li>An array of Object (returns the array)
 63   
      *            <li>A {@link List}(returns an array of the values in the List})
 64   
      *            <li>A single object (returns the object as a single-element array)
 65   
      *            </ul>
 66   
      * @return An array representation of the input object.
 67   
      * @since 2.2
 68   
      */
 69   
 
 70  91
     public static Object[] constructServiceParameters(Object parameterValue)
 71   
     {
 72  91
         if (parameterValue == null)
 73  80
             return null;
 74   
 
 75  11
         if (parameterValue instanceof Object[])
 76  0
             return (Object[]) parameterValue;
 77   
 
 78  11
         if (parameterValue instanceof List)
 79   
         {
 80  8
             List list = (List) parameterValue;
 81   
 
 82  8
             return list.toArray();
 83   
         }
 84   
 
 85  3
         return new Object[]
 86   
         { parameterValue };
 87   
     }
 88   
 
 89   
     /**
 90   
      * Invoked by the direct service to trigger the application-specific action by notifying the
 91   
      * {@link IActionListener listener}.
 92   
      * 
 93   
      * @throws org.apache.tapestry.StaleSessionException
 94   
      *             if the component is stateful, and the session is new.
 95   
      */
 96   
 
 97  28
     public void trigger(IRequestCycle cycle)
 98   
     {
 99  28
         IActionListener listener = getListener();
 100   
 
 101  28
         if (listener == null)
 102  0
             throw Tapestry.createRequiredParameterException(this, "listener");
 103   
 
 104  28
         listener.actionTriggered(this, cycle);
 105   
     }
 106   
 
 107   
     /** @since 2.2 * */
 108   
 
 109   
     public abstract Object getParameters();
 110   
 }