Package org.springframework.expression.spel.standard

Examples of org.springframework.expression.spel.standard.SpelExpressionParser


  }

  @SuppressWarnings("unchecked")
  private List<Object> getModel() {
    Map<String, Object> model = Context.getCurrentContext().getModel(modelId);
    ExpressionParser parser = new SpelExpressionParser();
    List<Object> d = new ArrayList<Object>();
    for (Object val : data) {
      Map<String, Object> m = new HashMap<String, Object>();
      for (Map.Entry<String, Object> entry : model.entrySet()) {
        Map<String, Object> modelEntry = (Map<String, Object>) entry.getValue();
        String name = entry.getKey();
        String expr = (String) (modelEntry.containsKey("jread") ? modelEntry.get("jread") : modelEntry
            .get("jbind"));
        if (expr != null) {
          Object value = parser.parseExpression(expr).getValue(val);
          m.put(name, value);
        }
      }
      d.add(m);
    }
View Full Code Here


  private List<Object> getModel() {
    Map<String, Object> model = Context.getCurrentContext().getModel(modelId);
    if (model == null) {
      model = (Map<String, Object>) configService.getConfig(modelId + ".dataModel");
    }
    ExpressionParser parser = new SpelExpressionParser();
    List<Object> d = new ArrayList<Object>();
    for (Map.Entry<String, Object> entry : model.entrySet()) {
      Map<String, Object> modelEntry = (Map<String, Object>) entry.getValue();
      String name = entry.getKey();
      String expr = (String) (modelEntry.containsKey("jread") ? modelEntry.get("jread") : modelEntry.get("jbind"));
      if (expr != null) {
        Object value = parser.parseExpression(expr).getValue(data);
        Map<String, Object> m = new HashMap<String, Object>();
        m.put("id", name);
        m.put("value", value);
        d.add(m);
      }
View Full Code Here

  @Test
  public void test() {
    StandardEvaluationContext context = new StandardEvaluationContext();
    context.setRootObject(new Object());
    context.addMethodResolver(new ConditionEvalMethodResolver());
    ExpressionParser parser = new SpelExpressionParser();

    Expression exp = parser.parseExpression("test('test') or paet(true)");
    System.out.println(exp.getValue(context));

  }
View Full Code Here

  }

  @Test
  public void test1() {
    System.out.println(new Date().toString());
    ExpressionParser parser = new SpelExpressionParser();
   
    Expression exp = parser.parseExpression("date");
    TestBean b = new TestBean();
    exp.setValue(b, "Sat Nov 20 10:52:05 CET 2010");

    System.out.println(b.getInn().getVal());
  }
View Full Code Here

  @Test
  public void testPerfWithResolverAndAccessor() {
    Message<String> message = MessageBuilder.withPayload("jee").build();

    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    PartitionKeyMethodResolver resolver = new PartitionKeyMethodResolver();
    MessagePartitionKeyPropertyAccessor accessor = new MessagePartitionKeyPropertyAccessor();
    context.addMethodResolver(resolver);
    context.addPropertyAccessor(accessor);

    Expression expression1 = parser.parseExpression("payload");
    Expression expression2 = parser.parseExpression("timestamp");
    for (int i = 0; i<1000000; i++) {
      expression1.getValue(context, message, String.class);
      expression2.getValue(context, message, Long.class);
    }
  }
View Full Code Here

  @Test
  public void testPerfWithNativeSpel() {
    Message<String> message = MessageBuilder.withPayload("jee").build();

    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();

    Expression expression1 = parser.parseExpression("payload");
    Expression expression2 = parser.parseExpression("headers.timestamp");
    for (int i = 0; i<1000000; i++) {
      expression1.getValue(context, message, String.class);
      expression2.getValue(context, message, Long.class);
    }
  }
View Full Code Here

    private final Expression expression;
    private final MessageExpressionMethods methods;

    public MessagePartitionResolver(String expression, EvaluationContext evaluationContext) {
      ExpressionParser parser = new SpelExpressionParser();
      this.expression = parser.parseExpression(expression);
      this.methods = new MessageExpressionMethods(evaluationContext);
      log.info("Using expression=[" + this.expression.getExpressionString() + "]");
    }
View Full Code Here

    headers.put("headerkey", "headervalue");
    Message<String> message = MessageBuilder.withPayload("jee").copyHeaders(headers).build();
    String nowYYYYMM = new SimpleDateFormat("yyyy/MM").format(new Date());
    String nowYYYY = new SimpleDateFormat("yyyy").format(new Date());

    ExpressionParser parser = new SpelExpressionParser();
    StandardEvaluationContext context = new StandardEvaluationContext();
    MessagePartitionKeyMethodResolver resolver = new MessagePartitionKeyMethodResolver();
    MessagePartitionKeyPropertyAccessor accessor = new MessagePartitionKeyPropertyAccessor();
    context.addMethodResolver(resolver);
    context.addPropertyAccessor(accessor);

    assertThat(parser.parseExpression("dateFormat('yyyy/MM')").getValue(context, message, String.class), is(nowYYYYMM));
    assertThat(parser.parseExpression("dateFormat('yyyy/MM', headers[timestamp])").getValue(context, message, String.class), is(nowYYYYMM));
    assertThat(parser.parseExpression("dateFormat('yyyy/MM', timestamp)").getValue(context, message, String.class), is(nowYYYYMM));
    assertThat(parser.parseExpression("dateFormat('yyyy/MM', T(java.lang.System).currentTimeMillis())").getValue(context, message, String.class), is(nowYYYYMM));
    assertThat(parser.parseExpression("path(dateFormat('yyyy'),dateFormat('MM'))").getValue(context, message, String.class), is(nowYYYYMM));
    assertThat(parser.parseExpression("path('yyyy', 'MM')").getValue(context, message, String.class), is("yyyy/MM"));
    assertThat(parser.parseExpression("path('yyyy', 'MM', payload.substring(0,3))").getValue(context, message, String.class), is("yyyy/MM/jee"));
    assertThat(parser.parseExpression("dateFormat('yyyy') + '/' + dateFormat('MM')").getValue(context, message, String.class), is(nowYYYYMM));
    assertThat(parser.parseExpression("headerkey").getValue(context, message, String.class), is("headervalue"));
    assertThat(parser.parseExpression("path(dateFormat('yyyy'), headerkey)").getValue(context, message, String.class), is(nowYYYY + "/headervalue"));
    assertThat(parser.parseExpression("headers.timestamp").getValue(context, message, Long.class), greaterThan(0l));
    assertThat(parser.parseExpression("headers[timestamp]").getValue(context, message, Long.class), greaterThan(0l));
    assertThat(parser.parseExpression("payload").getValue(context, message, String.class), is("jee"));
  }
View Full Code Here

    String customDateFormat = "yyyy-MM-dd";
    String stringDateCustomFormat = new SimpleDateFormat(customDateFormat).format(new Date());

    Message<String> dateMessage = MessageBuilder.withPayload(new SimpleDateFormat(defaultFormat).format(new Date())).build();

    ExpressionParser parser = new SpelExpressionParser();

    MessageExpressionMethods methods = new MessageExpressionMethods();
    assertThat(methods.getValue(parser.parseExpression("dateFormat('yyyy/MM')"), message, String.class), is(nowYYYYMM));
    assertThat(methods.getValue(parser.parseExpression("dateFormat('yyyy/MM', headers[timestamp])"), message, String.class), is(nowYYYYMM));
    assertThat(methods.getValue(parser.parseExpression("dateFormat('yyyy/MM', timestamp)"), message, String.class), is(nowYYYYMM));
    assertThat(methods.getValue(parser.parseExpression("dateFormat('yyyy/MM', T(java.lang.System).currentTimeMillis())"), message, String.class), is(nowYYYYMM));
    assertThat(methods.getValue(parser.parseExpression("path(dateFormat('yyyy'),dateFormat('MM'))"), message, String.class), is(nowYYYYMM));
    assertThat(methods.getValue(parser.parseExpression("path('yyyy', 'MM')"), message, String.class), is("yyyy/MM"));
    assertThat(methods.getValue(parser.parseExpression("path('yyyy', 'MM', payload.substring(0,3))"), message, String.class), is("yyyy/MM/jee"));
    assertThat(methods.getValue(parser.parseExpression("dateFormat('yyyy') + '/' + dateFormat('MM')"), message, String.class), is(nowYYYYMM));
    assertThat(methods.getValue(parser.parseExpression("headerkey"), message, String.class), is("headervalue"));
    assertThat(methods.getValue(parser.parseExpression("path(dateFormat('yyyy'), headerkey)"), message, String.class), is(nowYYYY + "/headervalue"));
    assertThat(methods.getValue(parser.parseExpression("headers.timestamp"), message, Long.class), greaterThan(0l));
    assertThat(methods.getValue(parser.parseExpression("headers[timestamp]"), message, Long.class), greaterThan(0l));
    assertThat(methods.getValue(parser.parseExpression("payload"), message, String.class), is("jee"));
    assertThat(methods.getValue(parser.parseExpression("dateFormat('yyyy/MM', '" + stringDateDefaultFormat + "')"), message, String.class), is(nowYYYYMM));
    assertThat(methods.getValue(parser.parseExpression("dateFormat('yyyy/MM', '" + stringDateCustomFormat + "', '" + customDateFormat + "')"), message, String.class), is(nowYYYYMM));
    assertThat(methods.getValue(parser.parseExpression("dateFormat('yyyy/MM', payload.substring(0,10))"), dateMessage, String.class), is(nowYYYYMM));
  }
View Full Code Here

  private Object evaluateExpression(String expression, Object[] args) {

    DefaultParameters parameters = new DefaultParameters(method);
    EvaluationContext evaluationContext = provider.getEvaluationContext(parameters, args);
    return new SpelExpressionParser().parseExpression(expression).getValue(evaluationContext);
  }
View Full Code Here

TOP

Related Classes of org.springframework.expression.spel.standard.SpelExpressionParser

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.