Package org.jibeframework.test

Source Code of org.jibeframework.test.SPELTest$TestBean$Inner

package org.jibeframework.test;

import java.util.Date;

import org.junit.Test;
import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.MethodExecutor;
import org.springframework.expression.MethodResolver;
import org.springframework.expression.TypedValue;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.BooleanTypedValue;
import org.springframework.expression.spel.support.StandardEvaluationContext;

public class SPELTest {
  @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));

  }

  @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());
  }

  public static class ConditionEvalMethodResolver implements MethodResolver {

    public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name,
        Class<?>[] argumentTypes) throws AccessException {
      System.out.println(argumentTypes[0]);
      return new ConditionMethodExecutor();
    }
  }

  public static class ConditionMethodExecutor implements MethodExecutor {

    public TypedValue execute(EvaluationContext context, Object target, Object... arguments) throws AccessException {
      return BooleanTypedValue.FALSE;
    }
  }

  public static class TestBean {
    String name;
    Double num;
    Date date;
    Inner inn = new Inner();

    public void setNum(Double num) {
      this.num = num;
    }

    public void setDate(Date date) {
      this.date = date;
    }

    public Date getDate() {
      return date;
    }

    public Inner getInn() {
      return inn;
    }

    public Double getNum() {
      return num;
    }

    public String getName() {
      return name;
    }

    public void setName(String name) {
      this.name = name;
    }

    public class Inner {
      int val;

      public int getVal() {
        return val;
      }

    }
  }
}
TOP

Related Classes of org.jibeframework.test.SPELTest$TestBean$Inner

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.