KickJava   Java API By Example, From Geeks To Geeks.

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


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.StaleSessionException;
21 import org.apache.tapestry.services.ResponseRenderer;
22
23 /**
24  * Used to activate a particular page to report the
25  * {@link org.apache.tapestry.StaleSessionException}.
26  *
27  * @author Howard M. Lewis Ship
28  * @since 4.0
29  */

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

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

59             _requestExceptionReporter.reportRequestException(ErrorMessages
60                     .unableToPresentExceptionPage(ex), ex);
61
62             // And throw the exception.
63

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