Search in sources :

Example 1 with BeanExpressionException

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);
    }
}
Also used : StandardTypeConverter(cn.taketoday.expression.spel.support.StandardTypeConverter) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) BeanExpressionException(cn.taketoday.beans.factory.BeanExpressionException) StandardTypeLocator(cn.taketoday.expression.spel.support.StandardTypeLocator) Expression(cn.taketoday.expression.Expression) ConversionService(cn.taketoday.core.conversion.ConversionService) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService) Nullable(cn.taketoday.lang.Nullable)

Example 2 with BeanExpressionException

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);
    }
}
Also used : StandardTypeConverter(cn.taketoday.expression.spel.support.StandardTypeConverter) StandardEvaluationContext(cn.taketoday.expression.spel.support.StandardEvaluationContext) BeanExpressionException(cn.taketoday.beans.factory.BeanExpressionException) StandardTypeLocator(cn.taketoday.expression.spel.support.StandardTypeLocator) Expression(cn.taketoday.expression.Expression) ConversionService(cn.taketoday.core.conversion.ConversionService) ApplicationConversionService(cn.taketoday.format.support.ApplicationConversionService) Nullable(cn.taketoday.lang.Nullable)

Aggregations

BeanExpressionException (cn.taketoday.beans.factory.BeanExpressionException)2 ConversionService (cn.taketoday.core.conversion.ConversionService)2 Expression (cn.taketoday.expression.Expression)2 StandardEvaluationContext (cn.taketoday.expression.spel.support.StandardEvaluationContext)2 StandardTypeConverter (cn.taketoday.expression.spel.support.StandardTypeConverter)2 StandardTypeLocator (cn.taketoday.expression.spel.support.StandardTypeLocator)2 ApplicationConversionService (cn.taketoday.format.support.ApplicationConversionService)2 Nullable (cn.taketoday.lang.Nullable)2