1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.el.unified.resolver; |
20 | |
|
21 | |
import org.apache.myfaces.el.VariableResolverImpl; |
22 | |
|
23 | |
import javax.el.ELContext; |
24 | |
import javax.faces.application.Application; |
25 | |
import javax.faces.context.FacesContext; |
26 | |
import javax.servlet.jsp.JspApplicationContext; |
27 | |
import java.beans.FeatureDescriptor; |
28 | |
import java.util.Iterator; |
29 | |
import java.util.Map; |
30 | |
import java.util.Arrays; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
public final class FacesCompositeELResolver extends org.apache.myfaces.el.CompositeELResolver |
49 | |
{ |
50 | |
private final Scope _scope; |
51 | |
|
52 | 0 | public enum Scope |
53 | |
{ |
54 | 0 | Faces, JSP |
55 | |
} |
56 | |
|
57 | |
public static final String SCOPE = "org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.Scope"; |
58 | |
|
59 | |
public FacesCompositeELResolver(final Scope scope) |
60 | 0 | { |
61 | 0 | if (scope == null) |
62 | |
{ |
63 | 0 | throw new IllegalArgumentException("scope must not be one of " + Arrays.toString(Scope.values())); |
64 | |
} |
65 | 0 | _scope = scope; |
66 | 0 | } |
67 | |
|
68 | |
@Override |
69 | |
public Class<?> getCommonPropertyType(final ELContext context, final Object base) |
70 | |
{ |
71 | 0 | final FacesContext facesContext = FacesContext.getCurrentInstance(); |
72 | 0 | if (facesContext == null) |
73 | |
{ |
74 | 0 | return null; |
75 | |
} |
76 | 0 | final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap(); |
77 | |
try |
78 | |
{ |
79 | 0 | setScope(requestMap); |
80 | 0 | return super.getCommonPropertyType(context, base); |
81 | |
} |
82 | |
finally |
83 | |
{ |
84 | 0 | unsetScope(requestMap); |
85 | |
} |
86 | |
|
87 | |
} |
88 | |
|
89 | |
@Override |
90 | |
public Iterator<FeatureDescriptor> getFeatureDescriptors(final ELContext context, final Object base) |
91 | |
{ |
92 | 0 | final FacesContext facesContext = FacesContext.getCurrentInstance(); |
93 | 0 | if (facesContext == null) |
94 | |
{ |
95 | 0 | return null; |
96 | |
} |
97 | 0 | final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap(); |
98 | |
try |
99 | |
{ |
100 | 0 | setScope(requestMap); |
101 | 0 | return super.getFeatureDescriptors(context, base); |
102 | |
|
103 | |
} |
104 | |
finally |
105 | |
{ |
106 | 0 | unsetScope(requestMap); |
107 | |
} |
108 | |
} |
109 | |
|
110 | |
@Override |
111 | |
public Class<?> getType(final ELContext context, final Object base, final Object property) |
112 | |
{ |
113 | 0 | final FacesContext facesContext = FacesContext.getCurrentInstance(); |
114 | 0 | if (facesContext == null) |
115 | |
{ |
116 | 0 | return null; |
117 | |
} |
118 | 0 | final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap(); |
119 | |
try |
120 | |
{ |
121 | 0 | setScope(requestMap); |
122 | 0 | return super.getType(context, base, property); |
123 | |
} |
124 | |
finally |
125 | |
{ |
126 | 0 | unsetScope(requestMap); |
127 | |
} |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public Object getValue(final ELContext context, final Object base, final Object property) |
132 | |
{ |
133 | 0 | final FacesContext facesContext = FacesContext.getCurrentInstance(); |
134 | 0 | if (facesContext == null) |
135 | |
{ |
136 | 0 | return null; |
137 | |
} |
138 | 0 | final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap(); |
139 | |
try |
140 | |
{ |
141 | 0 | setScope(requestMap); |
142 | 0 | return super.getValue(context, base, property); |
143 | |
} |
144 | |
finally |
145 | |
{ |
146 | 0 | unsetScope(requestMap); |
147 | |
} |
148 | |
} |
149 | |
|
150 | |
@Override |
151 | |
public boolean isReadOnly(final ELContext context, final Object base, final Object property) |
152 | |
{ |
153 | 0 | final FacesContext facesContext = FacesContext.getCurrentInstance(); |
154 | 0 | if (facesContext == null) |
155 | |
{ |
156 | 0 | return false; |
157 | |
} |
158 | 0 | final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap(); |
159 | |
try |
160 | |
{ |
161 | 0 | setScope(requestMap); |
162 | 0 | return super.isReadOnly(context, base, property); |
163 | |
} |
164 | |
finally |
165 | |
{ |
166 | 0 | unsetScope(requestMap); |
167 | |
} |
168 | |
} |
169 | |
|
170 | |
@Override |
171 | |
public void setValue(final ELContext context, final Object base, final Object property, final Object val) |
172 | |
{ |
173 | 0 | final FacesContext facesContext = FacesContext.getCurrentInstance(); |
174 | 0 | if (facesContext == null) |
175 | |
{ |
176 | 0 | return; |
177 | |
} |
178 | 0 | final Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap(); |
179 | |
try |
180 | |
{ |
181 | 0 | setScope(requestMap); |
182 | 0 | super.setValue(context, base, property, val); |
183 | |
|
184 | |
} |
185 | |
finally |
186 | |
{ |
187 | 0 | unsetScope(requestMap); |
188 | 0 | } |
189 | 0 | } |
190 | |
|
191 | |
private void setScope(final Map<String, Object> requestMap) |
192 | |
{ |
193 | 0 | requestMap.put(SCOPE, _scope); |
194 | 0 | } |
195 | |
|
196 | |
private static void unsetScope(final Map<String, Object> requestMap) |
197 | |
{ |
198 | 0 | requestMap.remove(SCOPE); |
199 | 0 | } |
200 | |
} |