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