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.ELContext; |
22 | |
import javax.el.ELException; |
23 | |
import javax.el.ELResolver; |
24 | |
import javax.el.PropertyNotFoundException; |
25 | |
import javax.el.PropertyNotWritableException; |
26 | |
import javax.faces.context.FacesContext; |
27 | |
import javax.faces.el.EvaluationException; |
28 | |
import javax.faces.el.VariableResolver; |
29 | |
|
30 | |
import java.beans.FeatureDescriptor; |
31 | |
import java.util.Collection; |
32 | |
import java.util.HashSet; |
33 | |
import java.util.Iterator; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
@SuppressWarnings("deprecation") |
43 | |
public final class VariableResolverToELResolver extends ELResolver |
44 | |
{ |
45 | |
|
46 | |
|
47 | 0 | private static final ThreadLocal<Collection<String>> propertyGuard = new ThreadLocal<Collection<String>>() { |
48 | |
@Override |
49 | |
protected Collection<String> initialValue() |
50 | |
{ |
51 | 0 | return new HashSet<String>(); |
52 | |
} |
53 | |
}; |
54 | |
|
55 | |
private VariableResolver variableResolver; |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
public VariableResolverToELResolver(final VariableResolver variableResolver) |
61 | 0 | { |
62 | 0 | this.variableResolver = variableResolver; |
63 | 0 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public VariableResolver getVariableResolver() |
69 | |
{ |
70 | 0 | return variableResolver; |
71 | |
} |
72 | |
|
73 | |
public Object getValue(ELContext context, Object base, Object property) throws NullPointerException, |
74 | |
PropertyNotFoundException, ELException |
75 | |
{ |
76 | |
|
77 | 0 | if (base != null) |
78 | 0 | return null; |
79 | 0 | if (property == null) |
80 | 0 | throw new PropertyNotFoundException(); |
81 | |
|
82 | 0 | context.setPropertyResolved(true); |
83 | |
|
84 | 0 | if (!(property instanceof String)) |
85 | 0 | return null; |
86 | |
|
87 | 0 | final String strProperty = (String) property; |
88 | |
|
89 | 0 | Object result = null; |
90 | |
try |
91 | |
{ |
92 | |
|
93 | 0 | if(!propertyGuard.get().contains(strProperty)) { |
94 | 0 | propertyGuard.get().add(strProperty); |
95 | 0 | result = variableResolver.resolveVariable(facesContext(context), strProperty); |
96 | |
} |
97 | |
} |
98 | 0 | catch (javax.faces.el.PropertyNotFoundException e) |
99 | |
{ |
100 | 0 | context.setPropertyResolved(false); |
101 | 0 | throw new PropertyNotFoundException(e.getMessage(), e); |
102 | |
} |
103 | 0 | catch (EvaluationException e) |
104 | |
{ |
105 | 0 | context.setPropertyResolved(false); |
106 | 0 | throw new ELException(e.getMessage(), e); |
107 | |
} |
108 | 0 | catch (RuntimeException e) |
109 | |
{ |
110 | 0 | context.setPropertyResolved(false); |
111 | 0 | throw e; |
112 | |
} |
113 | |
finally |
114 | |
{ |
115 | 0 | propertyGuard.get().remove(strProperty); |
116 | |
|
117 | 0 | context.setPropertyResolved(result != null); |
118 | 0 | } |
119 | |
|
120 | 0 | return result; |
121 | |
} |
122 | |
|
123 | |
|
124 | |
private static FacesContext facesContext(ELContext context) |
125 | |
{ |
126 | 0 | return (FacesContext) context.getContext(FacesContext.class); |
127 | |
} |
128 | |
|
129 | |
public Class<?> getCommonPropertyType(ELContext context, Object base) |
130 | |
{ |
131 | 0 | if (base != null) |
132 | 0 | return null; |
133 | |
|
134 | 0 | return String.class; |
135 | |
} |
136 | |
|
137 | |
public void setValue(ELContext context, Object base, Object property, Object value) throws NullPointerException, |
138 | |
PropertyNotFoundException, PropertyNotWritableException, ELException |
139 | |
{ |
140 | |
|
141 | 0 | if ((base == null) && (property == null)) |
142 | 0 | throw new PropertyNotFoundException(); |
143 | 0 | } |
144 | |
|
145 | |
public boolean isReadOnly(ELContext context, Object base, Object property) throws NullPointerException, |
146 | |
PropertyNotFoundException, ELException |
147 | |
{ |
148 | |
|
149 | 0 | if ((base == null) && (property == null)) |
150 | 0 | throw new PropertyNotFoundException(); |
151 | |
|
152 | 0 | return false; |
153 | |
} |
154 | |
|
155 | |
public Class<?> getType(ELContext context, Object base, Object property) throws NullPointerException, |
156 | |
PropertyNotFoundException, ELException |
157 | |
{ |
158 | |
|
159 | 0 | if ((base == null) && (property == null)) |
160 | 0 | throw new PropertyNotFoundException(); |
161 | |
|
162 | 0 | return null; |
163 | |
} |
164 | |
|
165 | |
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) |
166 | |
{ |
167 | 0 | return null; |
168 | |
} |
169 | |
|
170 | |
} |