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