use of org.springframework.expression.spel.support.StandardTypeConverter in project spring-framework by spring-projects.
the class StandardBeanExpressionResolver method evaluate.
@Override
@Nullable
public Object evaluate(@Nullable String value, BeanExpressionContext evalContext) throws BeansException {
if (!StringUtils.hasLength(value)) {
return value;
}
try {
Expression expr = this.expressionCache.get(value);
if (expr == null) {
expr = this.expressionParser.parseExpression(value, this.beanExpressionParserContext);
this.expressionCache.put(value, expr);
}
StandardEvaluationContext sec = this.evaluationCache.get(evalContext);
if (sec == null) {
sec = new StandardEvaluationContext(evalContext);
sec.addPropertyAccessor(new BeanExpressionContextAccessor());
sec.addPropertyAccessor(new BeanFactoryAccessor());
sec.addPropertyAccessor(new MapAccessor());
sec.addPropertyAccessor(new EnvironmentAccessor());
sec.setBeanResolver(new BeanFactoryResolver(evalContext.getBeanFactory()));
sec.setTypeLocator(new StandardTypeLocator(evalContext.getBeanFactory().getBeanClassLoader()));
sec.setTypeConverter(new StandardTypeConverter(() -> {
ConversionService cs = evalContext.getBeanFactory().getConversionService();
return (cs != null ? cs : DefaultConversionService.getSharedInstance());
}));
customizeEvaluationContext(sec);
this.evaluationCache.put(evalContext, sec);
}
return expr.getValue(sec);
} catch (Throwable ex) {
throw new BeanExpressionException("Expression parsing failed", ex);
}
}
use of org.springframework.expression.spel.support.StandardTypeConverter in project spring-framework by spring-projects.
the class EvalTag method createEvaluationContext.
private EvaluationContext createEvaluationContext(PageContext pageContext) {
StandardEvaluationContext context = new StandardEvaluationContext();
context.addPropertyAccessor(new JspPropertyAccessor(pageContext));
context.addPropertyAccessor(new MapAccessor());
context.addPropertyAccessor(new EnvironmentAccessor());
context.setBeanResolver(new BeanFactoryResolver(getRequestContext().getWebApplicationContext()));
ConversionService conversionService = getConversionService(pageContext);
if (conversionService != null) {
context.setTypeConverter(new StandardTypeConverter(conversionService));
}
return context;
}
Aggregations