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