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;
}
}
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");
}
}
}
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);
}
}
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));
}
}
}
}
}
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);
}
Aggregations