Search in sources :

Example 6 with StandardTypeLocator

use of org.springframework.expression.spel.support.StandardTypeLocator in project spring-integration by spring-projects.

the class TwitterSearchOutboundGateway method doInit.

@Override
protected void doInit() {
    super.doInit();
    if (this.evaluationContext == null) {
        this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
        TypeLocator typeLocator = this.evaluationContext.getTypeLocator();
        if (typeLocator instanceof StandardTypeLocator) {
            /*
				 * Register the twitter api package so they don't need a FQCN for SearchParameters.
				 */
            ((StandardTypeLocator) typeLocator).registerImport("org.springframework.social.twitter.api");
        }
    }
}
Also used : StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator) TypeLocator(org.springframework.expression.TypeLocator) StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator)

Example 7 with StandardTypeLocator

use of org.springframework.expression.spel.support.StandardTypeLocator in project spring-integration by spring-projects.

the class MongoDbMessageSource method onInit.

@Override
protected void onInit() throws Exception {
    this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
    TypeLocator typeLocator = this.evaluationContext.getTypeLocator();
    if (typeLocator instanceof StandardTypeLocator) {
        // Register MongoDB query API package so FQCN can be avoided in query-expression.
        ((StandardTypeLocator) typeLocator).registerImport("org.springframework.data.mongodb.core.query");
    }
    if (this.mongoTemplate == null) {
        this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mongoConverter);
    }
    this.initialized = true;
}
Also used : StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator) TypeLocator(org.springframework.expression.TypeLocator) StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate)

Example 8 with StandardTypeLocator

use of org.springframework.expression.spel.support.StandardTypeLocator in project spring-integration-aws by spring-projects.

the class SnsMessageHandler method onInit.

@Override
protected void onInit() throws Exception {
    super.onInit();
    TypeLocator typeLocator = getEvaluationContext().getTypeLocator();
    if (typeLocator instanceof StandardTypeLocator) {
        /*
			 * Register the 'org.springframework.integration.aws.support' package
			 * you don't need a FQCN for the 'SnsMessageBuilder'.
			 */
        ((StandardTypeLocator) typeLocator).registerImport("org.springframework.integration.aws.support");
    }
}
Also used : StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator) TypeLocator(org.springframework.expression.TypeLocator) StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator)

Example 9 with StandardTypeLocator

use of org.springframework.expression.spel.support.StandardTypeLocator 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);
    }
}
Also used : StandardTypeConverter(org.springframework.expression.spel.support.StandardTypeConverter) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) BeanExpressionException(org.springframework.beans.factory.BeanExpressionException) StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator) Expression(org.springframework.expression.Expression) ConversionService(org.springframework.core.convert.ConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Nullable(org.springframework.lang.Nullable)

Example 10 with StandardTypeLocator

use of org.springframework.expression.spel.support.StandardTypeLocator in project spring-framework by spring-projects.

the class EvaluationTests method testResolvingList.

@Test
public void testResolvingList() {
    StandardEvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
    assertThatExceptionOfType(EvaluationException.class).isThrownBy(() -> parser.parseExpression("T(List)!=null").getValue(context, Boolean.class));
    ((StandardTypeLocator) context.getTypeLocator()).registerImport("java.util");
    assertThat(parser.parseExpression("T(List)!=null").getValue(context, Boolean.class)).isTrue();
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator) EvaluationException(org.springframework.expression.EvaluationException) Test(org.junit.jupiter.api.Test)

Aggregations

StandardTypeLocator (org.springframework.expression.spel.support.StandardTypeLocator)10 TypeLocator (org.springframework.expression.TypeLocator)5 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)4 Test (org.junit.jupiter.api.Test)2 ConversionService (org.springframework.core.convert.ConversionService)2 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)2 StandardTypeConverter (org.springframework.expression.spel.support.StandardTypeConverter)2 PostConstruct (javax.annotation.PostConstruct)1 BeanExpressionException (org.springframework.beans.factory.BeanExpressionException)1 BeanFactoryAccessor (org.springframework.context.expression.BeanFactoryAccessor)1 BeanFactoryResolver (org.springframework.context.expression.BeanFactoryResolver)1 DefaultConversionService (org.springframework.core.convert.support.DefaultConversionService)1 EvaluationException (org.springframework.expression.EvaluationException)1 Expression (org.springframework.expression.Expression)1 Nullable (org.springframework.lang.Nullable)1