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
015package org.apache.tapestry;
016
017import org.apache.hivemind.ApplicationRuntimeException;
018
019/**
020 *  Exception thrown by an {@link org.apache.tapestry.engine.IEngineService} when it discovers that
021 *  the an action link was for an out-of-date version of the page.
022 *
023 *  <p>The application should redirect to the StaleLink page.
024 *
025 *
026 *  @author Howard Lewis Ship
027 * 
028 **/
029
030public class StaleLinkException extends ApplicationRuntimeException
031{
032    private static final long serialVersionUID = -1266992401198999606L;
033    
034        private transient IPage _page;
035    private String _pageName;
036    private String _targetIdPath;
037    private String _targetActionId;
038
039    public StaleLinkException()
040    {
041        super(null, null, null, null);
042    }
043
044    /**
045     *  Constructor used when the action id is found, but the target id path
046     *  did not match the actual id path.
047     *
048     **/
049
050    public StaleLinkException(IComponent component, String targetActionId, String targetIdPath)
051    {
052        super(
053            Tapestry.format(
054                "StaleLinkException.action-mismatch",
055                new String[] { targetActionId, component.getIdPath(), targetIdPath }),
056            component,
057            null,
058            null);
059
060        _page = component.getPage();
061        _pageName = _page.getPageName();
062
063        _targetActionId = targetActionId;
064        _targetIdPath = targetIdPath;
065    }
066
067    /**
068     *  Constructor used when the target action id is not found.
069     *
070     **/
071
072    public StaleLinkException(IPage page, String targetActionId, String targetIdPath)
073    {
074        this(
075            Tapestry.format(
076                "StaleLinkException.component-mismatch",
077                targetActionId,
078                targetIdPath),
079            page);
080
081        _targetActionId = targetActionId;
082        _targetIdPath = targetIdPath;
083    }
084
085    public StaleLinkException(String message, IComponent component)
086    {
087        super(message, component, null, null);
088    }
089
090
091
092    public String getPageName()
093    {
094        return _pageName;
095    }
096
097    /**
098     *  Returns the page referenced by the service URL, if known, 
099     *  or null otherwise.
100     *
101     **/
102
103    public IPage getPage()
104    {
105        return _page;
106    }
107    
108    public String getTargetActionId()
109    {
110        return _targetActionId;
111    }
112
113    public String getTargetIdPath()
114    {
115        return _targetIdPath;
116    }
117
118}