Search in sources :

Example 1 with StandardTypeLocator

use of org.springframework.expression.spel.support.StandardTypeLocator in project java-function-invoker by projectriff.

the class ApplicationRunner method run.

public void run(String... args) {
    ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
    try {
        ClassUtils.overrideThreadContextClassLoader(this.classLoader);
        Class<?> cls = this.classLoader.loadClass(ContextRunner.class.getName());
        this.app = new StandardEvaluationContext(cls.newInstance());
        this.app.setTypeLocator(new StandardTypeLocator(this.classLoader));
        runContext(this.source, defaultProperties(UUID.randomUUID().toString()), args);
    } catch (Exception e) {
        logger.error("Cannot deploy", e);
    } finally {
        ClassUtils.overrideThreadContextClassLoader(contextLoader);
    }
    RuntimeException e = getError();
    if (e != null) {
        throw e;
    }
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator)

Example 2 with StandardTypeLocator

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

the class StatusUpdatingMessageHandler method onInit.

@Override
protected void onInit() throws Exception {
    super.onInit();
    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 TweetData.
				 */
            ((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 3 with StandardTypeLocator

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

the class MongoDbOutboundGateway method doInit.

@Override
protected void doInit() {
    Assert.state(this.queryExpression != null || this.collectionCallback != null, "no query or collectionCallback is specified");
    Assert.state(this.collectionNameExpression != null, "no collection name specified");
    if (this.queryExpression != null && this.collectionCallback != null) {
        throw new IllegalStateException("query and collectionCallback are mutually exclusive");
    }
    if (this.evaluationContext == null) {
        this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
        TypeLocator typeLocator = this.evaluationContext.getTypeLocator();
        if (typeLocator instanceof StandardTypeLocator) {
            ((StandardTypeLocator) typeLocator).registerImport(Query.class.getPackage().getName());
        }
    }
    if (this.mongoTemplate == null) {
        this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mongoConverter);
    }
}
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 4 with StandardTypeLocator

use of org.springframework.expression.spel.support.StandardTypeLocator in project core by craftercms.

the class SpELStringTemplateCompiler method init.

@PostConstruct
public void init() {
    if (evalContext == null) {
        evalContext = new StandardEvaluationContext();
    }
    if (evalContext instanceof StandardEvaluationContext) {
        StandardEvaluationContext standardEvalContext = (StandardEvaluationContext) evalContext;
        // PropertyAccessor used when the model is a BeanFactory.
        standardEvalContext.addPropertyAccessor(new BeanFactoryAccessor());
        if (beanFactory != null) {
            if (standardEvalContext.getBeanResolver() == null) {
                standardEvalContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
            }
            if (standardEvalContext.getTypeLocator() == null) {
                standardEvalContext.setTypeLocator(new StandardTypeLocator(beanFactory.getBeanClassLoader()));
            }
            if (standardEvalContext.getTypeConverter() == null) {
                ConversionService conversionService = beanFactory.getConversionService();
                if (conversionService != null) {
                    standardEvalContext.setTypeConverter(new StandardTypeConverter(conversionService));
                }
            }
        }
    }
}
Also used : StandardTypeConverter(org.springframework.expression.spel.support.StandardTypeConverter) BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator) ConversionService(org.springframework.core.convert.ConversionService) BeanFactoryAccessor(org.springframework.context.expression.BeanFactoryAccessor) PostConstruct(javax.annotation.PostConstruct)

Example 5 with StandardTypeLocator

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

the class StandardTypeLocatorTests method testImports.

@Test
void testImports() throws EvaluationException {
    StandardTypeLocator locator = new StandardTypeLocator();
    assertThat(locator.findType("java.lang.Integer")).isEqualTo(Integer.class);
    assertThat(locator.findType("java.lang.String")).isEqualTo(String.class);
    List<String> prefixes = locator.getImportPrefixes();
    assertThat(prefixes.size()).isEqualTo(1);
    assertThat(prefixes.contains("java.lang")).isTrue();
    assertThat(prefixes.contains("java.util")).isFalse();
    assertThat(locator.findType("Boolean")).isEqualTo(Boolean.class);
    // currently does not know about java.util by default
    // assertEquals(java.util.List.class,locator.findType("List"));
    assertThatExceptionOfType(SpelEvaluationException.class).isThrownBy(() -> locator.findType("URL")).satisfies(ex -> assertThat(ex.getMessageCode()).isEqualTo(SpelMessage.TYPE_NOT_FOUND));
    locator.registerImport("java.net");
    assertThat(locator.findType("URL")).isEqualTo(java.net.URL.class);
}
Also used : StandardTypeLocator(org.springframework.expression.spel.support.StandardTypeLocator) 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