throws Exception {
String expr = cleanExpression(expression);
// Parse the Expression
SimpleNode tree;
synchronized (parser) {
log.debug("Parsing expression: " + expr);
try {
tree = parser.parse(new StringReader(expr));
} catch (TokenMgrError tme) {
throw new ParseException(tme.getMessage());
}
}
if (tree.jjtGetNumChildren() > 1 && log.isWarnEnabled()) {
log.warn("The JEXL Expression created will be a reference"
+ " to the first expression from the supplied script: \""
+ expression + "\" ");
}
// Must be a simple reference, expression, statement or if, otherwise
// throw an exception.
SimpleNode node = (SimpleNode) tree.jjtGetChild(0);
// TODO: Can we get rid of these checks?
if (node instanceof ASTReferenceExpression
|| node instanceof ASTExpressionExpression
|| node instanceof ASTStatementExpression
|| node instanceof ASTIfStatement
|| node instanceof ASTWhileStatement
|| node instanceof ASTForeachStatement
) {
return new ExpressionImpl(expression, node);
}
log.error("Invalid Expression, node of type: "
+ node.getClass().getName());
throw new Exception("Invalid Expression: not a Reference, Expression, "
+ "Statement or If");
}