Package org.springframework.expression

Examples of org.springframework.expression.Expression


    StandardEvaluationContext evalContext = new StandardEvaluationContext();
    evalContext.setVariable(ENTITY_NAME, metadata.getEntityName());

    SpelExpressionParser parser = new SpelExpressionParser();
    Expression expr = parser.parseExpression(query, ParserContext.TEMPLATE_EXPRESSION);

    Object result = expr.getValue(evalContext, String.class);
    return result == null ? query : String.valueOf(result);
  }
View Full Code Here


    for (ParameterBinding binding : query.getParameterBindings()) {

      if (binding.isExpression()) {

        Expression expr = parseExpressionString(binding.getExpression());

        Object value = evaluateExpression(expr);

        try {
          if (binding.getName() != null) {
View Full Code Here

  @Test
  public void repro() {
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setBeanResolver(new MyBeanResolver());
    Expression expr = new SpelExpressionParser().parseRaw("@dummyAction.isZero(@dummyBean.getCalls())");
    boolean value = expr.getValue(context, boolean.class);
    System.out.println(value);
  }
View Full Code Here

  @Autowired
  private BeanFactory beanFactory;

  @Test
  public void testBytesNotCopied() throws Exception {
    Expression expression = new SpelExpressionParser().parseExpression("@service.handleBytes(#root)");
    byte[] bytes = new byte[100];
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext(bytes);
    evaluationContext.setBeanResolver(new BeanFactoryResolver(this.beanFactory));
    byte[] outBytes = expression.getValue(evaluationContext, byte[].class);
    assertSame(bytes, outBytes);
  }
View Full Code Here

*/
public class ReproTests {

  @Test
  public void spr11494() {
    Expression exp = new SpelExpressionParser().parseExpression("T(java.util.Arrays).asList('a','b')");
    List<String> list = (List<String>) exp.getValue();
    assertThat(list.size(), is(2));
  }
View Full Code Here

 
  public SitemapNode getNode(String id) { return nodes.get(id); }
 
  public String resolve(String exprStr, Map<String, Object> context) {
    log.debug("Resolving expression: {}", exprStr);
    Expression expr = exprParser.parseExpression(exprStr);
    EvaluationContext evalContext = new StandardEvaluationContext(context);
    return (String) expr.getValue(evalContext);
  }
View Full Code Here

    if (annotation == null || !StringUtils.hasText(annotation.value())) {
      return delegate.invoke(invocation);
    }

    Expression expression = parser.parseExpression(annotation.value(), parserContext);
    return expression.getValue(evaluationContext);
  }
View Full Code Here

        if (!accessToken.equals(token)) {
            headers.set("Status", "403 Forbidden");
            return new HttpEntity<>("{ \"message\": \"Forbidden\" }\n", headers);
        }
        SpelExpressionParser parser = new SpelExpressionParser();
        Expression spel = parser.parseExpression(template, new TemplateParserContext());

        Map<?, ?> push;
        try {
            push = this.objectMapper.readValue(payload, Map.class);
            logger.info("Recieved new webhook payload for push with head_commit message: "
View Full Code Here

  public Object evaluate(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();
        sec.setRootObject(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()));
        ConversionService conversionService = evalContext.getBeanFactory().getConversionService();
        if (conversionService != null) {
          sec.setTypeConverter(new StandardTypeConverter(conversionService));
        }
        customizeEvaluationContext(sec);
        this.evaluationCache.put(evalContext, sec);
      }
      return expr.getValue(sec);
    }
    catch (Exception ex) {
      throw new BeanExpressionException("Expression parsing failed", ex);
    }
  }
View Full Code Here

    return getExpression(this.unlessCache, unlessExpression, methodKey).getValue(evalContext, boolean.class);
  }

  private Expression getExpression(Map<ExpressionKey, Expression> cache, String expression, MethodCacheKey methodKey) {
    ExpressionKey key = createKey(methodKey, expression);
    Expression expr = cache.get(key);
    if (expr == null) {
      expr = this.parser.parseExpression(expression);
      cache.put(key, expr);
    }
    return expr;
View Full Code Here

TOP

Related Classes of org.springframework.expression.Expression

Copyright © 2018 www.massapicom. 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.