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