1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.component;
20
21 import javax.el.ELException;
22 import javax.el.MethodExpression;
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.el.MethodNotFoundException;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class MethodExpressionToMethodBinding extends MethodBinding implements StateHolder {
44
45 private MethodExpression methodExpression;
46
47 private boolean isTransient = false;
48
49 public MethodExpressionToMethodBinding() {
50 methodExpression = null;
51 }
52
53
54 public MethodExpressionToMethodBinding(MethodExpression methodExpression) {
55 this.methodExpression = methodExpression;
56 }
57
58 @Override
59 public String getExpressionString()
60 {
61 return methodExpression.getExpressionString();
62 }
63
64 public Class getType(FacesContext facesContext)
65 throws MethodNotFoundException {
66
67 try {
68 return methodExpression.getMethodInfo(facesContext.getELContext()).getReturnType();
69 } catch (javax.el.MethodNotFoundException e) {
70 throw new javax.faces.el.MethodNotFoundException(e);
71 } catch (ELException e) {
72 throw new EvaluationException(e);
73 }
74 }
75
76 public Object invoke(FacesContext facesContext, Object[] params)
77 throws EvaluationException, MethodNotFoundException {
78
79 try {
80 return methodExpression.invoke(facesContext.getELContext(), params);
81 } catch (javax.el.MethodNotFoundException e) {
82 throw new javax.faces.el.MethodNotFoundException(e);
83 } catch (ELException e) {
84 throw new EvaluationException(e);
85 }
86 }
87
88
89
90 public void restoreState(FacesContext context, Object state) {
91 if(state != null)
92 methodExpression = (MethodExpression)state;
93 }
94
95 public Object saveState(FacesContext context) {
96 if(!isTransient)
97 return methodExpression;
98 return null;
99 }
100
101 public void setTransient(boolean newTransientValue) {
102 isTransient = newTransientValue;
103 }
104
105 public boolean isTransient() {
106 return isTransient;
107 }
108
109 }