|
|||||||||||||||||||
30 day Evaluation License registered to hlship@comcast.net Your 30 day evaluation period has expired. Please visit http://www.cenqua.com to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
StaleLinkExceptionPresenterImpl.java | - | 72.7% | 100% | 80% |
|
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 _pageName; | |
38 | ||
39 | 1 | public void presentStaleLinkException(IRequestCycle cycle, StaleLinkException cause) |
40 | { | |
41 | 1 | try |
42 | { | |
43 | 1 | IPage exceptionPage = cycle.getPage(_pageName); |
44 | ||
45 | 1 | exceptionPage.setProperty("message", cause.getMessage()); |
46 | ||
47 | 1 | cycle.activate(exceptionPage); |
48 | ||
49 | 1 | _responseRenderer.renderResponse(cycle); |
50 | } | |
51 | catch (Throwable 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 | 0 | _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 | 0 | _requestExceptionReporter.reportRequestException(ErrorMessages |
63 | .unableToPresentExceptionPage(ex), ex); | |
64 | ||
65 | // And throw the exception. | |
66 | ||
67 | 0 | throw new ApplicationRuntimeException(ex.getMessage(), ex); |
68 | } | |
69 | ||
70 | } | |
71 | ||
72 | 1 | public void setPageName(String pageName) |
73 | { | |
74 | 1 | _pageName = pageName; |
75 | } | |
76 | ||
77 | 1 | public void setRequestExceptionReporter(RequestExceptionReporter requestExceptionReporter) |
78 | { | |
79 | 1 | _requestExceptionReporter = requestExceptionReporter; |
80 | } | |
81 | ||
82 | 1 | public void setResponseRenderer(ResponseRenderer responseRenderer) |
83 | { | |
84 | 1 | _responseRenderer = responseRenderer; |
85 | } | |
86 | ||
87 | } |
|