1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.shale.test.el; |
19 | |
|
20 | |
import java.util.Iterator; |
21 | |
import java.util.List; |
22 | |
|
23 | |
import javax.el.ELContext; |
24 | |
import javax.el.ELException; |
25 | |
import javax.faces.context.FacesContext; |
26 | |
import javax.faces.el.EvaluationException; |
27 | |
import javax.faces.el.PropertyResolver; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 1 | public class FacesPropertyResolverChainWrapper extends AbstractELResolver { |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public Class getCommonPropertyType(ELContext context, Object base) { |
44 | |
|
45 | |
if (base != null) { |
46 | |
return null; |
47 | |
} else { |
48 | 1 | return Object.class; |
49 | |
} |
50 | |
|
51 | |
} |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public Iterator getFeatureDescriptors(ELContext context, Object base) { |
62 | |
|
63 | |
return null; |
64 | |
|
65 | |
} |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public Class getType(ELContext context, Object base, Object property) { |
79 | |
|
80 | |
if ((base == null) || (property == null)) { |
81 | |
return null; |
82 | |
} |
83 | |
|
84 | |
context.setPropertyResolved(true); |
85 | |
FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class); |
86 | |
ELContext elContext = fcontext.getELContext(); |
87 | |
PropertyResolver pr = fcontext.getApplication().getPropertyResolver(); |
88 | |
|
89 | |
if ((base instanceof List) || base.getClass().isArray()) { |
90 | |
Integer index = (Integer) fcontext.getApplication().getExpressionFactory(). |
91 | |
coerceToType(property, Integer.class); |
92 | |
try { |
93 | |
return pr.getType(base, index.intValue()); |
94 | |
} catch (EvaluationException e) { |
95 | |
context.setPropertyResolved(false); |
96 | |
throw new ELException(e); |
97 | |
} |
98 | |
} else { |
99 | |
try { |
100 | |
return pr.getType(base, property); |
101 | |
} catch (EvaluationException e) { |
102 | |
context.setPropertyResolved(false); |
103 | |
throw new ELException(e); |
104 | |
} |
105 | |
} |
106 | |
|
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
public Object getValue(ELContext context, Object base, Object property) { |
120 | |
|
121 | 1 | if ((base == null) || (property == null)) { |
122 | |
return null; |
123 | |
} |
124 | |
|
125 | 1 | context.setPropertyResolved(true); |
126 | 1 | FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class); |
127 | 1 | ELContext elContext = fcontext.getELContext(); |
128 | 1 | PropertyResolver pr = fcontext.getApplication().getPropertyResolver(); |
129 | |
|
130 | 1 | if ((base instanceof List) || base.getClass().isArray()) { |
131 | |
Integer index = (Integer) fcontext.getApplication().getExpressionFactory(). |
132 | |
coerceToType(property, Integer.class); |
133 | |
try { |
134 | |
return pr.getValue(base, index.intValue()); |
135 | |
} catch (EvaluationException e) { |
136 | |
context.setPropertyResolved(false); |
137 | |
throw new ELException(e); |
138 | |
} |
139 | |
} else { |
140 | |
try { |
141 | 1 | return pr.getValue(base, property); |
142 | |
} catch (EvaluationException e) { |
143 | |
context.setPropertyResolved(false); |
144 | |
throw new ELException(e); |
145 | |
} |
146 | |
} |
147 | |
|
148 | |
} |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public boolean isReadOnly(ELContext context, Object base, Object property) { |
160 | |
|
161 | |
if ((base == null) || (property == null)) { |
162 | |
return false; |
163 | |
} |
164 | |
|
165 | |
context.setPropertyResolved(true); |
166 | |
FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class); |
167 | |
ELContext elContext = fcontext.getELContext(); |
168 | |
PropertyResolver pr = fcontext.getApplication().getPropertyResolver(); |
169 | |
|
170 | |
if ((base instanceof List) || base.getClass().isArray()) { |
171 | |
Integer index = (Integer) fcontext.getApplication().getExpressionFactory(). |
172 | |
coerceToType(property, Integer.class); |
173 | |
try { |
174 | |
return pr.isReadOnly(base, index.intValue()); |
175 | |
} catch (EvaluationException e) { |
176 | |
context.setPropertyResolved(false); |
177 | |
throw new ELException(e); |
178 | |
} |
179 | |
} else { |
180 | |
try { |
181 | |
return pr.isReadOnly(base, property); |
182 | |
} catch (EvaluationException e) { |
183 | |
context.setPropertyResolved(false); |
184 | |
throw new ELException(e); |
185 | |
} |
186 | |
} |
187 | |
|
188 | |
} |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
public void setValue(ELContext context, Object base, Object property, Object value) { |
202 | |
|
203 | |
if ((base == null) || (property == null)) { |
204 | |
return; |
205 | |
} |
206 | |
|
207 | |
context.setPropertyResolved(true); |
208 | |
FacesContext fcontext = (FacesContext) context.getContext(FacesContext.class); |
209 | |
ELContext elContext = fcontext.getELContext(); |
210 | |
PropertyResolver pr = fcontext.getApplication().getPropertyResolver(); |
211 | |
|
212 | |
if ((base instanceof List) || base.getClass().isArray()) { |
213 | |
Integer index = (Integer) fcontext.getApplication().getExpressionFactory(). |
214 | |
coerceToType(property, Integer.class); |
215 | |
try { |
216 | |
pr.setValue(base, index.intValue(), value); |
217 | |
} catch (EvaluationException e) { |
218 | |
context.setPropertyResolved(false); |
219 | |
throw new ELException(e); |
220 | |
} |
221 | |
} else { |
222 | |
try { |
223 | |
pr.setValue(base, property, value); |
224 | |
} catch (EvaluationException e) { |
225 | |
context.setPropertyResolved(false); |
226 | |
throw new ELException(e); |
227 | |
} |
228 | |
} |
229 | |
|
230 | |
} |
231 | |
|
232 | |
|
233 | |
} |