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.component.StateHolder; |
24 | |
import javax.faces.context.FacesContext; |
25 | |
import javax.faces.el.EvaluationException; |
26 | |
import javax.faces.el.MethodBinding; |
27 | |
import javax.faces.event.AbortProcessingException; |
28 | |
import javax.faces.event.FacesEvent; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
abstract class _MethodBindingToListener implements StateHolder { |
36 | |
|
37 | |
protected MethodBinding methodBinding; |
38 | |
|
39 | 0 | public _MethodBindingToListener() { |
40 | 0 | } |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | 0 | public _MethodBindingToListener(MethodBinding methodBinding) { |
46 | 0 | if (methodBinding == null) throw new NullPointerException("methodBinding can not be null"); |
47 | 0 | if (!(methodBinding instanceof StateHolder)) throw new IllegalArgumentException("methodBinding must implement the StateHolder interface"); |
48 | |
|
49 | 0 | this.methodBinding = methodBinding; |
50 | 0 | } |
51 | |
|
52 | |
private FacesContext getFacesContext() { |
53 | 0 | return FacesContext.getCurrentInstance(); |
54 | |
} |
55 | |
|
56 | |
protected void invokeMethodBinding(FacesEvent event) throws AbortProcessingException { |
57 | |
try { |
58 | 0 | methodBinding.invoke(getFacesContext(), new Object[] {event}); |
59 | |
} |
60 | 0 | catch (EvaluationException e) { |
61 | 0 | Throwable cause = e.getCause(); |
62 | 0 | if (cause != null && cause instanceof AbortProcessingException) { |
63 | 0 | throw (AbortProcessingException)cause; |
64 | |
} |
65 | |
|
66 | 0 | throw e; |
67 | 0 | } |
68 | 0 | } |
69 | |
|
70 | |
public MethodBinding getMethodBinding() { |
71 | 0 | return methodBinding; |
72 | |
} |
73 | |
|
74 | |
public void restoreState(FacesContext context, Object state) { |
75 | 0 | Object[] stateArray = (Object[])state; |
76 | |
try { |
77 | 0 | methodBinding = (MethodBinding)Thread.currentThread() |
78 | |
.getContextClassLoader() |
79 | |
.loadClass((String)stateArray[0]) |
80 | |
.newInstance(); |
81 | 0 | } catch (Exception e) { |
82 | 0 | throw new FacesException(e); |
83 | 0 | } |
84 | |
|
85 | 0 | ((StateHolder)methodBinding).restoreState(context, stateArray[1]); |
86 | 0 | } |
87 | |
|
88 | |
public Object saveState(FacesContext context) { |
89 | 0 | Object[] stateArray = new Object[2]; |
90 | 0 | stateArray[0] = methodBinding.getClass().getName(); |
91 | 0 | stateArray[1] = ((StateHolder)methodBinding).saveState(context); |
92 | 0 | return stateArray; |
93 | |
} |
94 | |
|
95 | |
public void setTransient(boolean newTransientValue) { |
96 | 0 | ((StateHolder)methodBinding).setTransient(newTransientValue); |
97 | 0 | } |
98 | |
|
99 | |
public boolean isTransient() { |
100 | 0 | return ((StateHolder)methodBinding).isTransient(); |
101 | |
} |
102 | |
|
103 | |
} |