001    // Copyright 2004, 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.link;
016    
017    import org.apache.tapestry.IAction;
018    import org.apache.tapestry.IActionListener;
019    import org.apache.tapestry.IRequestCycle;
020    import org.apache.tapestry.RenderRewoundException;
021    import org.apache.tapestry.Tapestry;
022    import org.apache.tapestry.engine.ActionServiceParameter;
023    import org.apache.tapestry.engine.ILink;
024    import org.apache.tapestry.listener.ListenerInvoker;
025    
026    /**
027     * A component for creating a link that is handled using the action service. [ <a
028     * href="../../../../../ComponentReference/ActionLink.html">Component Reference </a>]
029     * 
030     * @author Howard Lewis Ship
031     */
032    
033    public abstract class ActionLink extends AbstractLinkComponent implements IAction
034    {
035        public abstract boolean isStateful();
036    
037        /**
038         * Returns true if the stateful parameter is bound to a true value. If stateful is not bound,
039         * also returns the default, true.
040         * <p>
041         * Note that this method can be called when the component is not rendering, therefore it must
042         * directly access the {@link IBinding}for the stateful parameter.
043         */
044    
045        public boolean getRequiresSession()
046        {
047            return isStateful();
048        }
049    
050        public ILink getLink(IRequestCycle cycle)
051        {
052            String actionId = cycle.getNextActionId();
053    
054            if (cycle.isRewound(this))
055            {
056                getListenerInvoker().invokeListener(getListener(), this, cycle);
057    
058                throw new RenderRewoundException(this);
059            }
060    
061            return getLink(cycle, Tapestry.ACTION_SERVICE, new ActionServiceParameter(this, actionId));
062        }
063    
064        public abstract IActionListener getListener();
065    
066        public abstract ListenerInvoker getListenerInvoker();
067    }