Search in sources :

Example 6 with ReflectivePropertyAccessor

use of org.springframework.expression.spel.support.ReflectivePropertyAccessor in project cas by apereo.

the class AbstractCasWebflowConfigurer method getSpringExpressionParser.

/**
 * Gets spring expression parser.
 *
 * @return the spring expression parser
 */
public SpringELExpressionParser getSpringExpressionParser() {
    val configuration = new SpelParserConfiguration();
    val spelExpressionParser = new SpelExpressionParser(configuration);
    val parser = new SpringELExpressionParser(spelExpressionParser, this.flowBuilderServices.getConversionService());
    parser.addPropertyAccessor(new ActionPropertyAccessor());
    parser.addPropertyAccessor(new BeanFactoryPropertyAccessor());
    parser.addPropertyAccessor(new FlowVariablePropertyAccessor());
    parser.addPropertyAccessor(new MapAdaptablePropertyAccessor());
    parser.addPropertyAccessor(new MessageSourcePropertyAccessor());
    parser.addPropertyAccessor(new ScopeSearchingPropertyAccessor());
    parser.addPropertyAccessor(new BeanExpressionContextAccessor());
    parser.addPropertyAccessor(new MapAccessor());
    parser.addPropertyAccessor(new MapAdaptablePropertyAccessor());
    parser.addPropertyAccessor(new EnvironmentAccessor());
    parser.addPropertyAccessor(new ReflectivePropertyAccessor());
    return parser;
}
Also used : lombok.val(lombok.val) ActionPropertyAccessor(org.springframework.webflow.expression.spel.ActionPropertyAccessor) MessageSourcePropertyAccessor(org.springframework.webflow.expression.spel.MessageSourcePropertyAccessor) BeanFactoryPropertyAccessor(org.springframework.webflow.expression.spel.BeanFactoryPropertyAccessor) ScopeSearchingPropertyAccessor(org.springframework.webflow.expression.spel.ScopeSearchingPropertyAccessor) FlowVariablePropertyAccessor(org.springframework.webflow.expression.spel.FlowVariablePropertyAccessor) SpringELExpressionParser(org.springframework.binding.expression.spel.SpringELExpressionParser) ReflectivePropertyAccessor(org.springframework.expression.spel.support.ReflectivePropertyAccessor) BeanExpressionContextAccessor(org.springframework.context.expression.BeanExpressionContextAccessor) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) MapAccessor(org.springframework.context.expression.MapAccessor) EnvironmentAccessor(org.springframework.context.expression.EnvironmentAccessor) MapAdaptablePropertyAccessor(org.springframework.webflow.expression.spel.MapAdaptablePropertyAccessor) SpelParserConfiguration(org.springframework.expression.spel.SpelParserConfiguration)

Example 7 with ReflectivePropertyAccessor

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

the class SpelReproTests method propertyAccessOnNullTarget_SPR5663.

@Test
void propertyAccessOnNullTarget_SPR5663() throws AccessException {
    PropertyAccessor accessor = new ReflectivePropertyAccessor();
    EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
    assertThat(accessor.canRead(context, null, "abc")).isFalse();
    assertThat(accessor.canWrite(context, null, "abc")).isFalse();
    assertThatIllegalStateException().isThrownBy(() -> accessor.read(context, null, "abc"));
    assertThatIllegalStateException().isThrownBy(() -> accessor.write(context, null, "abc", "foo"));
}
Also used : ReflectivePropertyAccessor(org.springframework.expression.spel.support.ReflectivePropertyAccessor) PropertyAccessor(org.springframework.expression.PropertyAccessor) EvaluationContext(org.springframework.expression.EvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) ReflectivePropertyAccessor(org.springframework.expression.spel.support.ReflectivePropertyAccessor) Test(org.junit.jupiter.api.Test)

Example 8 with ReflectivePropertyAccessor

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

the class SpelReproTests method SPR9994_bridgeMethods.

@Test
void SPR9994_bridgeMethods() throws Exception {
    ReflectivePropertyAccessor accessor = new ReflectivePropertyAccessor();
    StandardEvaluationContext context = new StandardEvaluationContext();
    GenericImplementation target = new GenericImplementation();
    accessor.write(context, target, "property", "1");
    assertThat(target.value).isEqualTo(1);
    TypedValue value = accessor.read(context, target, "property");
    assertThat(value.getValue()).isEqualTo(1);
    assertThat(value.getTypeDescriptor().getType()).isEqualTo(Integer.class);
    assertThat(value.getTypeDescriptor().getAnnotations()).isNotEmpty();
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) ReflectivePropertyAccessor(org.springframework.expression.spel.support.ReflectivePropertyAccessor) TypedValue(org.springframework.expression.TypedValue) Test(org.junit.jupiter.api.Test)

Aggregations

ReflectivePropertyAccessor (org.springframework.expression.spel.support.ReflectivePropertyAccessor)8 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)5 Test (org.junit.jupiter.api.Test)3 PropertyAccessor (org.springframework.expression.PropertyAccessor)3 SpringELExpressionParser (org.springframework.binding.expression.spel.SpringELExpressionParser)2 BeanExpressionContextAccessor (org.springframework.context.expression.BeanExpressionContextAccessor)2 EnvironmentAccessor (org.springframework.context.expression.EnvironmentAccessor)2 MapAccessor (org.springframework.context.expression.MapAccessor)2 AccessException (org.springframework.expression.AccessException)2 EvaluationContext (org.springframework.expression.EvaluationContext)2 TypedValue (org.springframework.expression.TypedValue)2 SpelParserConfiguration (org.springframework.expression.spel.SpelParserConfiguration)2 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)2 ActionPropertyAccessor (org.springframework.webflow.expression.spel.ActionPropertyAccessor)2 BeanFactoryPropertyAccessor (org.springframework.webflow.expression.spel.BeanFactoryPropertyAccessor)2 FlowVariablePropertyAccessor (org.springframework.webflow.expression.spel.FlowVariablePropertyAccessor)2 MapAdaptablePropertyAccessor (org.springframework.webflow.expression.spel.MapAdaptablePropertyAccessor)2 MessageSourcePropertyAccessor (org.springframework.webflow.expression.spel.MessageSourcePropertyAccessor)2 ScopeSearchingPropertyAccessor (org.springframework.webflow.expression.spel.ScopeSearchingPropertyAccessor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1