Package org.apache.commons.jexl2.parser

Examples of org.apache.commons.jexl2.parser.JexlNode


    /** {@inheritDoc} */
    public Object visit(ASTBlock node, Object data) {
        builder.append("{ ");
        int num = node.jjtGetNumChildren();
        for (int i = 0; i < num; ++i) {
            JexlNode child = node.jjtGetChild(i);
            acceptStatement(child, data);
        }
        builder.append(" }");
        return data;
    }
View Full Code Here


    /** {@inheritDoc} */
    public Object visit(ASTJexlScript node, Object data) {
        int num = node.jjtGetNumChildren();
        for (int i = 0; i < num; ++i) {
            JexlNode child = node.jjtGetChild(i);
            acceptStatement(child, data);
        }
        return data;
    }
View Full Code Here

        for (int s = 0; context.has(r0); ++s) {
            r0 = r0 + s;
        }
        expr = r0 + (expr.charAt(0) == '[' ? "" : ".") + expr + ";";
        try {
            JexlNode tree = parse(expr, null);
            JexlNode node = tree.jjtGetChild(0);
            Interpreter interpreter = createInterpreter(context);
            // ensure 4 objects in register array
            Object[] r = {r0, bean, r0, bean};
            interpreter.setRegisters(r);
            return node.jjtAccept(interpreter, null);
        } catch (JexlException xjexl) {
            if (silent) {
                logger.warn(xjexl.getMessage(), xjexl.getCause());
                return null;
            }
View Full Code Here

            r1 = r1 + s;
        }
        // synthetize expr
        expr = r0 + (expr.charAt(0) == '[' ? "" : ".") + expr + "=" + r1 + ";";
        try {
            JexlNode tree = parse(expr, null);
            JexlNode node = tree.jjtGetChild(0);
            Interpreter interpreter = createInterpreter(context);
            // set the registers
            Object[] r = {r0, bean, r1, value};
            interpreter.setRegisters(r);
            node.jjtAccept(interpreter, null);
        } catch (JexlException xjexl) {
            if (silent) {
                logger.warn(xjexl.getMessage(), xjexl.getCause());
                return;
            }
View Full Code Here

         */
        Object left = node.jjtGetChild(0).jjtAccept(this, data);
        for(int c = 2, size = node.jjtGetNumChildren(); c < size; c += 2) {
            Object right = node.jjtGetChild(c).jjtAccept(this, data);
            try {
                JexlNode op = node.jjtGetChild(c - 1);
                if (op instanceof ASTAdditiveOperator) {
                    String which = ((ASTAdditiveOperator) op).image;
                    if ("+".equals(which)) {
                        left = arithmetic.add(left, right);
                        continue;
                    }
                    if ("-".equals(which)) {
                        left = arithmetic.subtract(left, right);
                        continue;
                    }
                    throw new UnsupportedOperationException("unknown operator " + which);
                }
                throw new IllegalArgumentException("unknown operator " + op);
            } catch (RuntimeException xrt) {
                JexlNode xnode = findNullOperand(xrt, node, left, right);
                throw new JexlException(xnode, "+/- error", xrt);
            }
        }
        return left;
    }
View Full Code Here

        Object object = node.jjtGetChild(0).jjtAccept(this, data);
        // can have multiple nodes - either an expression, integer literal or
        // reference
        int numChildren = node.jjtGetNumChildren();
        for (int i = 1; i < numChildren; i++) {
            JexlNode nindex = node.jjtGetChild(i);
            Object index = nindex.jjtAccept(this, null);
            object = getAttribute(object, index, nindex);
        }

        return object;
    }
View Full Code Here

    }
   
    /** {@inheritDoc} */
    public Object visit(ASTAssignment node, Object data) {
        // left contains the reference to assign to
        JexlNode left = node.jjtGetChild(0);
        if (!(left instanceof ASTReference)) {
            throw new JexlException(left, "illegal assignment form");
        }
        // right is the value expression to assign
        Object right = node.jjtGetChild(1).jjtAccept(this, data);

        // determine initial object & property:
        JexlNode objectNode = null;
        Object object = null;
        JexlNode propertyNode = null;
        Object property = null;
        boolean isVariable = true;
        int v = 0;
        StringBuilder variableName = null;
        // 1: follow children till penultimate
View Full Code Here

            return arithmetic.divide(left, right);
        } catch (RuntimeException xrt) {
            if (!strict && xrt instanceof ArithmeticException) {
                return new Double(0.0);
            }
            JexlNode xnode = findNullOperand(xrt, node, left, right);
            throw new JexlException(xnode, "divide error", xrt);
        }
    }
View Full Code Here

        /* second objectNode is the variable to iterate */
        Object iterableValue = node.jjtGetChild(1).jjtAccept(this, data);
        // make sure there is a value to iterate on and a statement to execute
        if (iterableValue != null && node.jjtGetNumChildren() >= 3) {
            /* third objectNode is the statement to execute */
            JexlNode statement = node.jjtGetChild(2);
            // get an iterator for the collection/array etc via the
            // introspector.
            Iterator<?> itemsIterator = getUberspect().getIterator(iterableValue, node);
            if (itemsIterator != null) {
                while (itemsIterator.hasNext()) {
                    // set loopVariable to value of iterator
                    Object value = itemsIterator.next();
                    context.set(loopVariable.image, value);
                    // execute statement
                    result = statement.jjtAccept(this, data);
                }
            }
        }
        return result;
    }
View Full Code Here

    /** {@inheritDoc} */
    public Object visit(ASTJexlScript node, Object data) {
        int numChildren = node.jjtGetNumChildren();
        Object result = null;
        for (int i = 0; i < numChildren; i++) {
            JexlNode child = node.jjtGetChild(i);
            result = child.jjtAccept(this, data);
        }
        return result;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.jexl2.parser.JexlNode

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.