Package org.apache.commons.jexl.parser

Examples of org.apache.commons.jexl.parser.SimpleNode


    public void testAssignment() throws Exception
    {
        JexlContext jc = JexlHelper.createContext();
        jc.getVars().put("aString", "Hello");
        Parser parser = new Parser(new StringReader(";"));
        SimpleNode tree = parser.parse(new StringReader("aString = 'World';"));
    }
View Full Code Here


     @return Script a new script
     *  @throws Exception for a variety of reasons - mostly malformed scripts
     */
    protected Script createNewScript(String scriptText) throws Exception {
        String cleanText = cleanScript(scriptText);
        SimpleNode script;
        // Parse the Expression
        synchronized (parser) {
            log.debug("Parsing script: " + cleanText);
            try {
                script = parser.parse(new StringReader(cleanText));
View Full Code Here

        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");
    }
View Full Code Here

        throws Exception {
   
        String expr = cleanExpression(expression);

        // Parse the Expression
        SimpleNode tree;
        synchronized(parser)
        {
            log.debug( "Parsing expression: " + expr );
            tree = parser.parse(new StringReader(expr));
        }

        // Must be a simple reference or expression, otherwise
        // throw an exception.
        SimpleNode node = (SimpleNode) tree.jjtGetChild(0);

        if( (node instanceof ASTReferenceExpression) ||
            (node instanceof ASTExpressionExpression) )
        {
            node = (SimpleNode) node.jjtGetChild(0);
            Expression e = new ExpressionImpl(expression, node);
       
            return e;
        }
        else
        {
            log.error( "Invalid Expression, node of type: " + node.getClass().getName() );
            throw new Exception("Invalid Expression: neither Reference nor Expression");
        }
    }
View Full Code Here

    public void testAssignment() throws Exception
    {
        JexlContext jc = JexlHelper.createContext();
        jc.getVars().put("aString", "Hello");
        Parser parser = new Parser(new StringReader(";"));
        SimpleNode tree = parser.parse(new StringReader("aString = 'World';"));
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.jexl.parser.SimpleNode

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.