2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.view.faces;
19
20 import javax.faces.context.FacesContext;
21 import org.apache.shale.view.Constants;
22 import org.apache.shale.view.ExceptionHandler;
23 import org.apache.shale.view.ViewController;
24
25 /***
26 * <p>Utility class to perform the event callbacks specified by the
27 * {@link ViewController} interface. The method signatures make it
28 * possible to specialize the behavior for annotated callbacks in the
29 * <em>Shale Tiger Extensions</em> module.</p>
30 *
31 * @since 1.0.1
32 *
33 * $Id: ViewControllerCallbacks.java 464373 2006-10-16 04:21:54Z rahul $
34 */
35 public class ViewControllerCallbacks {
36
37
38
39
40
41
42
43
44
45
46
47 /***
48 * <p>Perform the <code>preprocess</code> callback on the specified
49 * instance.</p>
50 *
51 * @param instance Bean instance on which to perform this callback
52 */
53 public void preprocess(Object instance) {
54
55 if (instance instanceof ViewController) {
56 try {
57 ((ViewController) instance).preprocess();
58 } catch (Exception e) {
59 handleException(FacesContext.getCurrentInstance(), e);
60 }
61 }
62
63 }
64
65
66 /***
67 * <p>Perform the <code>prerender</code> callback on the specified
68 * instance.</p>
69 *
70 * @param instance Bean instance on which to perform this callback
71 */
72 public void prerender(Object instance) {
73
74 if (instance instanceof ViewController) {
75 try {
76 ((ViewController) instance).prerender();
77 } catch (Exception e) {
78 handleException(FacesContext.getCurrentInstance(), e);
79 }
80 }
81
82 }
83
84
85
86
87
88 /***
89 * <p>Handle the specified exception according to the strategy
90 * defined by our current {@link ExceptionHandler}.</p>
91 *
92 * @param context FacesContext for the current request
93 * @param exception Exception to be handled
94 */
95 protected void handleException(FacesContext context, Exception exception) {
96
97 if (context == null) {
98 exception.printStackTrace(System.out);
99 return;
100 }
101 ExceptionHandler handler = (ExceptionHandler)
102 context.getApplication().getVariableResolver().resolveVariable
103 (context, Constants.EXCEPTION_HANDLER);
104 handler.handleException(exception);
105
106 }
107
108
109 }