use of cn.taketoday.beans.factory.BeanExpressionException in project today-infrastructure by TAKETODAY.
the class StandardBeanExpressionResolver method evaluate.
@Override
@Nullable
public Object evaluate(@Nullable String value, BeanExpressionContext evalContext) throws BeansException {
if (StringUtils.isEmpty(value)) {
return value;
}
try {
Expression expr = expressionCache.get(value);
if (expr == null) {
expr = expressionParser.parseExpression(value, this.beanExpressionParserContext);
expressionCache.put(value, expr);
}
StandardEvaluationContext sec = 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 : ApplicationConversionService.getSharedInstance();
}));
customizeEvaluationContext(sec);
evaluationCache.put(evalContext, sec);
}
return expr.getValue(sec);
} catch (Throwable ex) {
throw new BeanExpressionException("Expression parsing failed", ex);
}
}
use of cn.taketoday.beans.factory.BeanExpressionException in project today-framework by TAKETODAY.
the class StandardBeanExpressionResolver method evaluate.
@Override
@Nullable
public Object evaluate(@Nullable String value, BeanExpressionContext evalContext) throws BeansException {
if (StringUtils.isEmpty(value)) {
return value;
}
try {
Expression expr = expressionCache.get(value);
if (expr == null) {
expr = expressionParser.parseExpression(value, this.beanExpressionParserContext);
expressionCache.put(value, expr);
}
StandardEvaluationContext sec = 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 : ApplicationConversionService.getSharedInstance();
}));
customizeEvaluationContext(sec);
evaluationCache.put(evalContext, sec);
}
return expr.getValue(sec);
} catch (Throwable ex) {
throw new BeanExpressionException("Expression parsing failed", ex);
}
}
Aggregations