Coverage Report - org.apache.tapestry.link.DirectLink
 
Classes in this File Line Coverage Branch Coverage Complexity
DirectLink
0%
0/16
0%
0/8
1.778
 
 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.Collection;
 18  
 
 19  
 import org.apache.tapestry.IActionListener;
 20  
 import org.apache.tapestry.IDirect;
 21  
 import org.apache.tapestry.IRequestCycle;
 22  
 import org.apache.tapestry.IScript;
 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="../../../../../components/link/directlink.html">Component
 31  
  * Reference </a>]
 32  
  * 
 33  
  */
 34  
 
 35  0
 public abstract class DirectLink extends AbstractLinkComponent implements IDirect
 36  
 {
 37  
     public abstract IActionListener getListener();
 38  
 
 39  
     /**
 40  
      * Returns true if the stateful parameter is bound to a true value. If stateful is not bound,
 41  
      * also returns the default, true.
 42  
      */
 43  
     
 44  
     public abstract boolean isStateful();
 45  
     
 46  
     public ILink getLink(IRequestCycle cycle)
 47  
     {
 48  0
         Object[] serviceParameters = constructServiceParameters(getParameters());
 49  
         
 50  0
         DirectServiceParameter dsp = new DirectServiceParameter(this, serviceParameters);
 51  
         
 52  0
         return getEngine().getLink(isStateful(), dsp);
 53  
     }
 54  
     
 55  
     /**
 56  
      * Converts a service parameters value to an array of objects. This is used by the
 57  
      * {@link DirectLink},{@link ServiceLink}and {@link ExternalLink}components.
 58  
      * 
 59  
      * @param parameterValue
 60  
      *            the input value which may be
 61  
      *            <ul>
 62  
      *              <li>null (returns null)
 63  
      *              <li>An array of Object (returns the array)
 64  
      *              <li>A {@link Collection}(returns an array of the values in the Collection})
 65  
      *              <li>A single object (returns the object as a single-element array)
 66  
      *            </ul>
 67  
      * @return An array representation of the input object.
 68  
      * @since 2.2
 69  
      */
 70  
 
 71  
     public static Object[] constructServiceParameters(Object parameterValue)
 72  
     {
 73  0
         if (parameterValue == null)
 74  0
             return null;
 75  
 
 76  0
         if (parameterValue instanceof Object[])
 77  0
             return (Object[]) parameterValue;
 78  
 
 79  0
         if (parameterValue instanceof Collection)
 80  0
             return ((Collection) parameterValue).toArray();
 81  
 
 82  0
         return new Object[] { parameterValue };
 83  
     }
 84  
 
 85  
     /**
 86  
      * Invoked by the direct service to trigger the application-specific action by notifying the
 87  
      * {@link IActionListener listener}. If the listener parameter is not bound, attempt to locate
 88  
      * an implicit listener named by the capitalized component id, prefixed by "do".
 89  
      * 
 90  
      * @throws org.apache.tapestry.StaleSessionException
 91  
      *             if the component is stateful, and the session is new.
 92  
      */
 93  
 
 94  
     public void trigger(IRequestCycle cycle)
 95  
     {
 96  0
         IActionListener listener = getListener();
 97  
 
 98  0
         if (listener == null)
 99  0
                 listener = getContainer().getListeners().getImplicitListener(this);
 100  
 
 101  0
         getListenerInvoker().invokeListener(listener, this, cycle);
 102  0
     }
 103  
 
 104  
     /** @since 2.2 * */
 105  
 
 106  
     public abstract Object getParameters();
 107  
 
 108  
     /**
 109  
      * Injected.
 110  
      * 
 111  
      * @since 4.0
 112  
      */
 113  
 
 114  
     public abstract ListenerInvoker getListenerInvoker();
 115  
     
 116  
     /**
 117  
      * Injected.
 118  
      * 
 119  
      * @since 4.1
 120  
      */
 121  
     public abstract IEngineService getEngine();
 122  
     
 123  
     /**
 124  
      * Injected.
 125  
      * @return The script to process asynchronous connection hookups.
 126  
      */
 127  
     public abstract IScript getScript();
 128  
 }