Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
ShaleViewRoot |
|
| 2.2;2.2 |
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to you under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.shale.view.faces; |
|
18 | ||
19 | import javax.faces.component.UIViewRoot; |
|
20 | import javax.faces.context.FacesContext; |
|
21 | ||
22 | import org.apache.shale.view.Constants; |
|
23 | import org.apache.shale.view.ExceptionHandler; |
|
24 | ||
25 | /** |
|
26 | * <p>Extending the UIViewRoot to provide specialized exception |
|
27 | * handling needed for the Shale view controller to enforce the contracts |
|
28 | * of the callbacks.</p> |
|
29 | */ |
|
30 | 0 | public class ShaleViewRoot extends UIViewRoot { |
31 | ||
32 | /** |
|
33 | * <p>Override to catch exceptions raised by the action listeners |
|
34 | * in the invoke application phase.</p> |
|
35 | * |
|
36 | * @param context faces context |
|
37 | */ |
|
38 | public void processApplication(FacesContext context) { |
|
39 | try { |
|
40 | 0 | super.processApplication(context); |
41 | 0 | } catch (Exception e) { |
42 | 0 | handleException(context, e); |
43 | 0 | context.responseComplete(); |
44 | 0 | } |
45 | 0 | } |
46 | ||
47 | /** |
|
48 | * <p>Override to catch and handle exceptions with immediate commands |
|
49 | * and value change listeners in the apply request values phase.</p> |
|
50 | * |
|
51 | * @param context faces context |
|
52 | */ |
|
53 | public void processDecodes(FacesContext context) { |
|
54 | try { |
|
55 | 0 | super.processDecodes(context); |
56 | 0 | } catch (Exception e) { |
57 | 0 | handleException(context, e); |
58 | 0 | context.responseComplete(); |
59 | 0 | } |
60 | 0 | } |
61 | ||
62 | /** |
|
63 | * <p>Override to catch and handle exceptions raised in the |
|
64 | * update model phase.</p> |
|
65 | * |
|
66 | * @param context faces context |
|
67 | */ |
|
68 | public void processUpdates(FacesContext context) { |
|
69 | try { |
|
70 | 0 | super.processUpdates(context); |
71 | 0 | } catch (Exception e) { |
72 | 0 | handleException(context, e); |
73 | 0 | context.responseComplete(); |
74 | 0 | } |
75 | 0 | } |
76 | ||
77 | /** |
|
78 | * <p>Override to catch and handle exceptions in value change |
|
79 | * listeners that might have occured in the process validations |
|
80 | * phase.</p> |
|
81 | * |
|
82 | * @param context faces context |
|
83 | */ |
|
84 | public void processValidators(FacesContext context) { |
|
85 | try { |
|
86 | 0 | super.processValidators(context); |
87 | 0 | } catch (Exception e) { |
88 | 0 | handleException(context, e); |
89 | 0 | context.responseComplete(); |
90 | 0 | } |
91 | 0 | } |
92 | ||
93 | ||
94 | /** |
|
95 | * <p>Handle the specified exception according to the strategy |
|
96 | * defined by our current {@link ExceptionHandler}.</p> |
|
97 | * |
|
98 | * @param context FacesContext for the current request |
|
99 | * @param exception Exception to be handled |
|
100 | */ |
|
101 | private void handleException(FacesContext context, Exception exception) { |
|
102 | ||
103 | 0 | if (context == null) { |
104 | 0 | exception.printStackTrace(System.out); |
105 | 0 | return; |
106 | } |
|
107 | 0 | ExceptionHandler handler = (ExceptionHandler) |
108 | context.getApplication().getVariableResolver().resolveVariable |
|
109 | (context, Constants.EXCEPTION_HANDLER); |
|
110 | 0 | handler.handleException(exception); |
111 | ||
112 | 0 | } |
113 | } |