use of org.springframework.context.expression.MapAccessor in project spring-integration by spring-projects.
the class IntegrationEvaluationContextFactoryBean method getObject.
@Override
public StandardEvaluationContext getObject() throws Exception {
StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
if (this.typeLocator != null) {
evaluationContext.setTypeLocator(this.typeLocator);
}
evaluationContext.setBeanResolver(this.beanResolver);
evaluationContext.setTypeConverter(getTypeConverter());
for (PropertyAccessor propertyAccessor : getPropertyAccessors().values()) {
evaluationContext.addPropertyAccessor(propertyAccessor);
}
evaluationContext.addPropertyAccessor(new MapAccessor());
for (Entry<String, Method> functionEntry : getFunctions().entrySet()) {
evaluationContext.registerFunction(functionEntry.getKey(), functionEntry.getValue());
}
return evaluationContext;
}
use of org.springframework.context.expression.MapAccessor in project spring-integration by spring-projects.
the class ExpressionUtils method createEvaluationContext.
/**
* Create a {@link StandardEvaluationContext} with a {@link MapAccessor} in its
* property accessor property and the supplied {@link ConversionService} in its
* conversionService property.
* @param conversionService the conversion service.
* @param beanFactory the bean factory.
* @param simple true if simple.
* @return the evaluation context.
*/
private static EvaluationContext createEvaluationContext(ConversionService conversionService, BeanFactory beanFactory, boolean simple) {
if (simple) {
Builder ecBuilder = SimpleEvaluationContext.forPropertyAccessors(new MapAccessor(), DataBindingPropertyAccessor.forReadOnlyAccess()).withInstanceMethods();
if (conversionService != null) {
ecBuilder.withConversionService(conversionService);
}
return ecBuilder.build();
} else {
StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
evaluationContext.addPropertyAccessor(new MapAccessor());
if (conversionService != null) {
evaluationContext.setTypeConverter(new StandardTypeConverter(conversionService));
}
if (beanFactory != null) {
evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
}
return evaluationContext;
}
}
use of org.springframework.context.expression.MapAccessor in project spring-integration by spring-projects.
the class ObjectToJsonTransformerTests method testBoonJsonObjectMapper_toNode.
@Test
public void testBoonJsonObjectMapper_toNode() throws Exception {
ObjectToJsonTransformer transformer = new ObjectToJsonTransformer(new BoonJsonObjectMapper(), ObjectToJsonTransformer.ResultType.NODE);
TestPerson person = new TestPerson("John", "Doe", 42);
person.setAddress(new TestAddress(123, "Main Street"));
Object payload = transformer.transform(new GenericMessage<TestPerson>(person)).getPayload();
assertThat(payload, instanceOf(Map.class));
SpelExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("firstName + ': ' + address.street");
StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
evaluationContext.addPropertyAccessor(new MapAccessor());
String value = expression.getValue(evaluationContext, payload, String.class);
assertEquals("John: Main Street", value);
}
use of org.springframework.context.expression.MapAccessor in project beetl2.0 by javamonkey.
the class SpELFunction method createEvaluationContext.
/**
* 创建SpEL执行上下文
*
* @param rootObject
* SpEL表达式根对象
* @param context
* Beetl上下文对象
* @return SpEL表达式执行上下文
*/
private EvaluationContext createEvaluationContext(Object rootObject, Context beetlContext) {
StandardEvaluationContext context = new StandardEvaluationContext(rootObject);
// 允许使用#context访问Beetl上下文
context.setVariable("context", beetlContext);
// 允许使用#global访问Beetl上下文的全局变量
context.setVariable("global", beetlContext.globalVar);
// 注册WebRender定义的全局变量
context.setVariable("ctxPath", beetlContext.getGlobal("ctxPath"));
context.setVariable("servlet", beetlContext.getGlobal("servlet"));
context.setVariable("parameter", beetlContext.getGlobal("parameter"));
context.setVariable("request", beetlContext.getGlobal("request"));
context.setVariable("session", beetlContext.getGlobal("session"));
// 允许使用属性格式访问Map
context.addPropertyAccessor(new MapAccessor());
// 允许访问Spring容器Bean
context.setBeanResolver(new BeanFactoryResolver(applicationContext));
return context;
}
use of org.springframework.context.expression.MapAccessor in project spring-framework by spring-projects.
the class EvalTag method createEvaluationContext.
private EvaluationContext createEvaluationContext(PageContext pageContext) {
StandardEvaluationContext context = new StandardEvaluationContext();
context.addPropertyAccessor(new JspPropertyAccessor(pageContext));
context.addPropertyAccessor(new MapAccessor());
context.addPropertyAccessor(new EnvironmentAccessor());
context.setBeanResolver(new BeanFactoryResolver(getRequestContext().getWebApplicationContext()));
ConversionService conversionService = getConversionService(pageContext);
if (conversionService != null) {
context.setTypeConverter(new StandardTypeConverter(conversionService));
}
return context;
}
Aggregations