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