|
@@ -125,11 +125,10 @@ public final class SpelHelper {
|
125
|
125
|
|
126
|
126
|
static final String CONTEXT_LOOKUP_KEY = SpelHelper.class.getName();
|
127
|
127
|
|
128
|
|
- private static final ExpressionParser PARSER = new SpelExpressionParser();
|
|
128
|
+ private final ExpressionParser PARSER = new SpelExpressionParser();
|
129
|
129
|
private static final ThreadLocal<EvaluationContext> CURRENT_CONTEXT =
|
130
|
130
|
new ThreadLocal<EvaluationContext>();
|
131
|
131
|
|
132
|
|
- private EvaluationContext context;
|
133
|
132
|
private final Set<Method> registeredFunctions = new HashSet<Method>();
|
134
|
133
|
private final Map<String,Method> registeredMethods =
|
135
|
134
|
new ConcurrentHashMap<String, Method>();
|
|
@@ -177,9 +176,6 @@ public final class SpelHelper {
|
177
|
176
|
*/
|
178
|
177
|
public SpelHelper registerFunctionsFromClass(final Class<?> clazz) {
|
179
|
178
|
registeredFunctions.addAll(filterFunctions(clazz));
|
180
|
|
- synchronized (PARSER) {
|
181
|
|
- context = null;
|
182
|
|
- }
|
183
|
179
|
return this;
|
184
|
180
|
}
|
185
|
181
|
|
|
@@ -194,7 +190,7 @@ public final class SpelHelper {
|
194
|
190
|
for (Constructor<?> constructor : asList(clazz.getConstructors())) {
|
195
|
191
|
registeredConstructors.put(
|
196
|
192
|
constructor.getDeclaringClass().getSimpleName()
|
197
|
|
- + Arrays.toString(constructor.getParameterTypes()),
|
|
193
|
+ + Arrays.toString(constructor.getParameterTypes()),
|
198
|
194
|
constructor);
|
199
|
195
|
}
|
200
|
196
|
return this;
|
|
@@ -254,14 +250,8 @@ public final class SpelHelper {
|
254
|
250
|
*/
|
255
|
251
|
public <T> T evalExpressions(final String[] expressionStrings,
|
256
|
252
|
final Object rootElement, final Class<T> desiredType) {
|
257
|
|
- int length = expressionStrings.length;
|
258
|
|
- Assert.isTrue(length > 0,
|
259
|
|
- "expressionStrings should have length more than 0");
|
260
|
|
- for (int i = 0; i < length - 1; i++) {
|
261
|
|
- evalExpression(expressionStrings[i], rootElement, Object.class);
|
262
|
|
- }
|
263
|
|
- return evalExpression(expressionStrings[length - 1],
|
264
|
|
- rootElement, desiredType);
|
|
253
|
+ return evalExpressions(
|
|
254
|
+ expressionStrings, getEvaluationContext(rootElement), desiredType);
|
265
|
255
|
}
|
266
|
256
|
|
267
|
257
|
/**
|
|
@@ -288,23 +278,16 @@ public final class SpelHelper {
|
288
|
278
|
}
|
289
|
279
|
|
290
|
280
|
private EvaluationContext getEvaluationContext(final Object rootObject) {
|
291
|
|
- if (context == null) {
|
292
|
|
- synchronized (PARSER) {
|
293
|
|
- if (context == null) {
|
294
|
|
- StandardEvaluationContext newContext = new StandardEvaluationContext(rootObject);
|
295
|
|
- newContext.getMethodResolvers().add(new ImplicitMethodResolver());
|
296
|
|
- newContext.getPropertyAccessors().add(new ImplicitPropertyAccessor());
|
297
|
|
- newContext.setConstructorResolvers(
|
298
|
|
- asList((ConstructorResolver) new ImplicitConstructorResolver()));
|
299
|
|
- for (Method method : registeredFunctions) {
|
300
|
|
- newContext.setVariable(method.getName(), method);
|
301
|
|
- }
|
302
|
|
- newContext.setVariable(CONTEXT_LOOKUP_KEY, this);
|
303
|
|
- context = newContext;
|
304
|
|
- }
|
305
|
|
- }
|
|
281
|
+ StandardEvaluationContext newContext = new StandardEvaluationContext(rootObject);
|
|
282
|
+ newContext.getMethodResolvers().add(new ImplicitMethodResolver());
|
|
283
|
+ newContext.getPropertyAccessors().add(new ImplicitPropertyAccessor());
|
|
284
|
+ newContext.setConstructorResolvers(
|
|
285
|
+ asList((ConstructorResolver) new ImplicitConstructorResolver()));
|
|
286
|
+ for (Method method : registeredFunctions) {
|
|
287
|
+ newContext.setVariable(method.getName(), method);
|
306
|
288
|
}
|
307
|
|
- return context;
|
|
289
|
+ newContext.setVariable(CONTEXT_LOOKUP_KEY, this);
|
|
290
|
+ return newContext;
|
308
|
291
|
}
|
309
|
292
|
|
310
|
293
|
/**
|