1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.el; |
20 | |
|
21 | |
import javax.el.ELContext; |
22 | |
import javax.el.ELException; |
23 | |
import javax.el.ValueExpression; |
24 | |
import javax.faces.application.Application; |
25 | |
import javax.faces.context.FacesContext; |
26 | |
import javax.faces.el.EvaluationException; |
27 | |
import javax.faces.el.VariableResolver; |
28 | |
|
29 | |
import org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver; |
30 | |
import org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.Scope; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
@SuppressWarnings("deprecation") |
44 | 0 | public final class VariableResolverImpl extends VariableResolver |
45 | |
{ |
46 | |
@Override |
47 | |
public Object resolveVariable(final FacesContext context, final String name) throws EvaluationException |
48 | |
{ |
49 | 0 | if (context == null) |
50 | |
{ |
51 | 0 | throw new NullPointerException("context must not be null"); |
52 | |
} |
53 | 0 | if (name == null) |
54 | |
{ |
55 | 0 | throw new NullPointerException("name must not be null"); |
56 | |
} |
57 | |
|
58 | |
try |
59 | |
{ |
60 | 0 | final Scope scope = getScope(context); |
61 | 0 | final ELContext elcontext = context.getELContext(); |
62 | 0 | final Application application = context.getApplication(); |
63 | 0 | if (Scope.Faces.equals(scope)) |
64 | |
{ |
65 | 0 | return application.getELResolver().getValue(elcontext, null, name); |
66 | |
} |
67 | 0 | else if (Scope.JSP.equals(scope)) |
68 | |
{ |
69 | 0 | ValueExpression expression = application.getExpressionFactory().createValueExpression(elcontext, |
70 | |
"#{" + name + "}", Object.class); |
71 | 0 | return expression.getValue(elcontext); |
72 | |
} |
73 | |
else |
74 | |
{ |
75 | 0 | throw new IllegalStateException("unknown scope defined: " + scope); |
76 | |
} |
77 | |
} |
78 | 0 | catch (ELException e) |
79 | |
{ |
80 | 0 | throw new EvaluationException(e.getMessage(), e); |
81 | |
} |
82 | |
} |
83 | |
|
84 | |
protected Scope getScope(final FacesContext context) |
85 | |
{ |
86 | 0 | return (Scope) context.getExternalContext().getRequestMap().get(FacesCompositeELResolver.SCOPE); |
87 | |
} |
88 | |
} |