1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
package javax.faces.component; |
21 | |
|
22 | |
import javax.faces.FacesException; |
23 | |
import javax.faces.context.FacesContext; |
24 | |
import javax.faces.el.EvaluationException; |
25 | |
import javax.faces.el.MethodBinding; |
26 | |
import javax.faces.event.AbortProcessingException; |
27 | |
import javax.faces.event.FacesEvent; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
abstract class _MethodBindingToListener implements StateHolder |
33 | |
{ |
34 | |
|
35 | |
protected MethodBinding methodBinding; |
36 | |
|
37 | |
public _MethodBindingToListener() |
38 | 0 | { |
39 | 0 | } |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
public _MethodBindingToListener(MethodBinding methodBinding) |
45 | 0 | { |
46 | 0 | if (methodBinding == null) |
47 | |
{ |
48 | 0 | throw new NullPointerException("methodBinding can not be null"); |
49 | |
} |
50 | 0 | if (!(methodBinding instanceof StateHolder)) |
51 | |
{ |
52 | 0 | throw new IllegalArgumentException("methodBinding must implement the StateHolder interface"); |
53 | |
} |
54 | |
|
55 | 0 | this.methodBinding = methodBinding; |
56 | 0 | } |
57 | |
|
58 | |
private FacesContext getFacesContext() |
59 | |
{ |
60 | 0 | return FacesContext.getCurrentInstance(); |
61 | |
} |
62 | |
|
63 | |
protected void invokeMethodBinding(FacesEvent event) throws AbortProcessingException |
64 | |
{ |
65 | |
try |
66 | |
{ |
67 | 0 | methodBinding.invoke(getFacesContext(), new Object[]{event}); |
68 | |
} |
69 | 0 | catch (EvaluationException e) |
70 | |
{ |
71 | 0 | Throwable cause = e.getCause(); |
72 | 0 | if (cause != null && cause instanceof AbortProcessingException) |
73 | |
{ |
74 | 0 | throw (AbortProcessingException) cause; |
75 | |
} |
76 | |
|
77 | 0 | throw e; |
78 | 0 | } |
79 | 0 | } |
80 | |
|
81 | |
public MethodBinding getMethodBinding() |
82 | |
{ |
83 | 0 | return methodBinding; |
84 | |
} |
85 | |
|
86 | |
public void restoreState(FacesContext context, Object state) |
87 | |
{ |
88 | 0 | Object[] stateArray = (Object[]) state; |
89 | |
try |
90 | |
{ |
91 | 0 | methodBinding = (MethodBinding) _ClassUtils.getContextClassLoader() |
92 | |
.loadClass((String) stateArray[0]) |
93 | |
.newInstance(); |
94 | |
} |
95 | 0 | catch (Exception e) |
96 | |
{ |
97 | 0 | throw new FacesException(e); |
98 | 0 | } |
99 | |
|
100 | 0 | ((StateHolder) methodBinding).restoreState(context, stateArray[1]); |
101 | 0 | } |
102 | |
|
103 | |
public Object saveState(FacesContext context) |
104 | |
{ |
105 | 0 | Object[] stateArray = new Object[2]; |
106 | 0 | stateArray[0] = methodBinding.getClass().getName(); |
107 | 0 | stateArray[1] = ((StateHolder) methodBinding).saveState(context); |
108 | 0 | return stateArray; |
109 | |
} |
110 | |
|
111 | |
public void setTransient(boolean newTransientValue) |
112 | |
{ |
113 | 0 | ((StateHolder) methodBinding).setTransient(newTransientValue); |
114 | 0 | } |
115 | |
|
116 | |
public boolean isTransient() |
117 | |
{ |
118 | 0 | return ((StateHolder) methodBinding).isTransient(); |
119 | |
} |
120 | |
|
121 | |
} |