KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > error > StaleLinkExceptionPresenterImpl


1 // Copyright 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.error;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.tapestry.IPage;
19 import org.apache.tapestry.IRequestCycle;
20 import org.apache.tapestry.StaleLinkException;
21 import org.apache.tapestry.services.ResponseRenderer;
22
23 /**
24  * Implementation of {@link org.apache.tapestry.error.StaleLinkExceptionPresenter} that uses a page
25  * to present the exception. The page must implement a property named "message" of type String and
26  * should present that message to the user.
27  *
28  * @author Howard M. Lewis Ship
29  * @since 4.0
30  */

31 public class StaleLinkExceptionPresenterImpl implements StaleLinkExceptionPresenter
32 {
33     private RequestExceptionReporter _requestExceptionReporter;
34
35     private ResponseRenderer _responseRenderer;
36
37     private String JavaDoc _pageName;
38
39     public void presentStaleLinkException(IRequestCycle cycle, StaleLinkException cause)
40     {
41         try
42         {
43             IPage exceptionPage = cycle.getPage(_pageName);
44
45             exceptionPage.setProperty("message", cause.getMessage());
46
47             cycle.activate(exceptionPage);
48
49             _responseRenderer.renderResponse(cycle);
50         }
51         catch (Throwable JavaDoc ex)
52         {
53             // Worst case scenario. The exception page itself is broken, leaving
54
// us with no option but to write the cause to the output.
55

56             _requestExceptionReporter.reportRequestException(ErrorMessages
57                     .unableToProcessClientRequest(cause), cause);
58
59             // Also, write the exception thrown when redendering the exception
60
// page, so that can get fixed as well.
61

62             _requestExceptionReporter.reportRequestException(ErrorMessages
63                     .unableToPresentExceptionPage(ex), ex);
64
65             // And throw the exception.
66

67             throw new ApplicationRuntimeException(ex.getMessage(), ex);
68         }
69
70     }
71
72     public void setPageName(String JavaDoc pageName)
73     {
74         _pageName = pageName;
75     }
76
77     public void setRequestExceptionReporter(RequestExceptionReporter requestExceptionReporter)
78     {
79         _requestExceptionReporter = requestExceptionReporter;
80     }
81
82     public void setResponseRenderer(ResponseRenderer responseRenderer)
83     {
84         _responseRenderer = responseRenderer;
85     }
86
87 }
88
Popular Tags