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 {
39 }
40
41
42
43
44 public _MethodBindingToListener(MethodBinding methodBinding)
45 {
46 if (methodBinding == null)
47 {
48 throw new NullPointerException("methodBinding can not be null");
49 }
50 if (!(methodBinding instanceof StateHolder))
51 {
52 throw new IllegalArgumentException("methodBinding must implement the StateHolder interface");
53 }
54
55 this.methodBinding = methodBinding;
56 }
57
58 private FacesContext getFacesContext()
59 {
60 return FacesContext.getCurrentInstance();
61 }
62
63 protected void invokeMethodBinding(FacesEvent event) throws AbortProcessingException
64 {
65 try
66 {
67 methodBinding.invoke(getFacesContext(), new Object[]{event});
68 }
69 catch (EvaluationException e)
70 {
71 Throwable cause = e.getCause();
72 if (cause != null && cause instanceof AbortProcessingException)
73 {
74 throw (AbortProcessingException) cause;
75 }
76
77 throw e;
78 }
79 }
80
81 public MethodBinding getMethodBinding()
82 {
83 return methodBinding;
84 }
85
86 public void restoreState(FacesContext context, Object state)
87 {
88 Object[] stateArray = (Object[]) state;
89 try
90 {
91 methodBinding = (MethodBinding) _ClassUtils.getContextClassLoader()
92 .loadClass((String) stateArray[0])
93 .newInstance();
94 }
95 catch (Exception e)
96 {
97 throw new FacesException(e);
98 }
99
100 ((StateHolder) methodBinding).restoreState(context, stateArray[1]);
101 }
102
103 public Object saveState(FacesContext context)
104 {
105 Object[] stateArray = new Object[2];
106 stateArray[0] = methodBinding.getClass().getName();
107 stateArray[1] = ((StateHolder) methodBinding).saveState(context);
108 return stateArray;
109 }
110
111 public void setTransient(boolean newTransientValue)
112 {
113 ((StateHolder) methodBinding).setTransient(newTransientValue);
114 }
115
116 public boolean isTransient()
117 {
118 return ((StateHolder) methodBinding).isTransient();
119 }
120
121 }