import org.apache.commons.jexl.Expression;
import org.apache.commons.jexl.JexlHelper;
import org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.ExpressionFactory;
/**
* Created by IntelliJ IDEA.
* User: leizhimin
* Date: 2008-8-16 19:14:39
* Apache Commons JEXL
*/
public class TestJexl {
public static void main(String[] args)
throws Exception {
testBasic();
}
public static void testBasic()
throws Exception {
Person person =
new Person(
"zhangsan",
"men", 22);
JexlContext jexlContext = JexlHelper.createContext();
jexlContext.getVars().put(
"country", person.country);
jexlContext.getVars().put(
"person", person);
/* 创建一个表达式country */ Expression expression1 = ExpressionFactory.createExpression(
"country");
/* 结合上下文对表达式求值 */ Object message1 = expression1.evaluate(jexlContext);
System.out.println(
"对表达式 country 求值结果: " + message1);
Expression expression2 = ExpressionFactory.createExpression(
"person.getName()");
Object message2 = expression2.evaluate(jexlContext);
System.out.println(
"对表达式 person.getName() 求值结果: " + message2);
Expression expression3 = ExpressionFactory.createExpression(
"person.getName().length()");
Object message3 = expression3.evaluate(jexlContext);
System.out.println(
"对表达式 person.getName().length() 求值结果: " + message3);
Expression expression4 = ExpressionFactory.createExpression(
"person.getAge()");
Object message4 = expression4.evaluate(jexlContext);
System.out.println(
"对表达式 person.getAge() 求值结果: " + message4);
}
}
--------------------next---------------------
阅读(308) | 评论(0) | 转发(0) |