Package org.springframework.expression.spel.support

Examples of org.springframework.expression.spel.support.StandardEvaluationContext.addPropertyAccessor()


    ExpressionParser expressionParser = new SpelExpressionParser();
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new ContextObject());

    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("firstContext"));
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("secondContext"));
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("thirdContext"));
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("fourthContext"));

    assertEquals("first", expressionParser.parseExpression("shouldBeFirst").getValue(evaluationContext));
    assertEquals("second", expressionParser.parseExpression("shouldBeSecond").getValue(evaluationContext));
    assertEquals("third", expressionParser.parseExpression("shouldBeThird").getValue(evaluationContext));
View Full Code Here


    StandardEvaluationContext evaluationContext = new StandardEvaluationContext(new ContextObject());

    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("firstContext"));
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("secondContext"));
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("thirdContext"));
    evaluationContext.addPropertyAccessor(new TestPropertyAccessor("fourthContext"));

    assertEquals("first", expressionParser.parseExpression("shouldBeFirst").getValue(evaluationContext));
    assertEquals("second", expressionParser.parseExpression("shouldBeSecond").getValue(evaluationContext));
    assertEquals("third", expressionParser.parseExpression("shouldBeThird").getValue(evaluationContext));
    assertEquals("fourth", expressionParser.parseExpression("shouldBeFourth").getValue(evaluationContext));
View Full Code Here

  @Test
  public void testScenario02_ComparingNames() throws Exception {
    SpelExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext ctx = new StandardEvaluationContext();

    ctx.addPropertyAccessor(new SecurityPrincipalAccessor());

    // Multiple options for supporting this expression: "p.name == principal.name"
    // (1) If the right person is the root context object then "name==principal.name" is good enough
    Expression expr = parser.parseRaw("name == principal.name");
View Full Code Here

    // (2) Or register an accessor that can understand 'p' and return the right person
    expr = parser.parseRaw("p.name == principal.name");

    PersonAccessor pAccessor = new PersonAccessor();
    ctx.addPropertyAccessor(pAccessor);
    ctx.setRootObject(null);

    pAccessor.setPerson(new Person("Andy"));
    value = expr.getValue(ctx,Boolean.class);
    assertTrue(value);
View Full Code Here

    StandardEvaluationContext ctx = new StandardEvaluationContext();

    // Even though this property accessor is added after the reflection one, it specifically
    // names the String class as the type it is interested in so is chosen in preference to
    // any 'default' ones
    ctx.addPropertyAccessor(new StringyPropertyAccessor());
    Expression expr = parser.parseRaw("new String('hello').flibbles");
    Integer i = expr.getValue(ctx, Integer.class);
    assertEquals((int) i, 7);

    // The reflection one will be used for other properties...
View Full Code Here

    // reflective property accessor is the only one by default
    List<PropertyAccessor> propertyAccessors = ctx.getPropertyAccessors();
    assertEquals(1,propertyAccessors.size());

    StringyPropertyAccessor spa = new StringyPropertyAccessor();
    ctx.addPropertyAccessor(spa);
    assertEquals(2,ctx.getPropertyAccessors().size());

    List<PropertyAccessor> copy = new ArrayList<PropertyAccessor>();
    copy.addAll(ctx.getPropertyAccessors());
    assertTrue(ctx.removePropertyAccessor(spa));
View Full Code Here

    Map<String, String> map =  new HashMap<String, String>();
    map.put("foo", "bar");
    property.put("property", map);
    SpelExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.addPropertyAccessor(new MapAccessor());
    context.setRootObject(property);
    Expression expression = parser.parseExpression("property");
    assertEquals("java.util.HashMap<?, ?>", expression.getValueTypeDescriptor(context).toString());
    assertEquals(map, expression.getValue(context));
    assertEquals(map, expression.getValue(context, Map.class));
View Full Code Here

      }
      StandardEvaluationContext sec = this.evaluationCache.get(evalContext);
      if (sec == null) {
        sec = new StandardEvaluationContext();
        sec.setRootObject(evalContext);
        sec.addPropertyAccessor(new BeanExpressionContextAccessor());
        sec.addPropertyAccessor(new BeanFactoryAccessor());
        sec.addPropertyAccessor(new MapAccessor());
        sec.setTypeLocator(new StandardTypeLocator(evalContext.getBeanFactory().getBeanClassLoader()));
        ConversionService conversionService = evalContext.getBeanFactory().getConversionService();
        if (conversionService != null) {
View Full Code Here

      StandardEvaluationContext sec = this.evaluationCache.get(evalContext);
      if (sec == null) {
        sec = new StandardEvaluationContext();
        sec.setRootObject(evalContext);
        sec.addPropertyAccessor(new BeanExpressionContextAccessor());
        sec.addPropertyAccessor(new BeanFactoryAccessor());
        sec.addPropertyAccessor(new MapAccessor());
        sec.setTypeLocator(new StandardTypeLocator(evalContext.getBeanFactory().getBeanClassLoader()));
        ConversionService conversionService = evalContext.getBeanFactory().getConversionService();
        if (conversionService != null) {
          sec.setTypeConverter(new StandardTypeConverter(conversionService));
View Full Code Here

      if (sec == null) {
        sec = new StandardEvaluationContext();
        sec.setRootObject(evalContext);
        sec.addPropertyAccessor(new BeanExpressionContextAccessor());
        sec.addPropertyAccessor(new BeanFactoryAccessor());
        sec.addPropertyAccessor(new MapAccessor());
        sec.setTypeLocator(new StandardTypeLocator(evalContext.getBeanFactory().getBeanClassLoader()));
        ConversionService conversionService = evalContext.getBeanFactory().getConversionService();
        if (conversionService != null) {
          sec.setTypeConverter(new StandardTypeConverter(conversionService));
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.