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