Search in sources :

Example 1 with Operation

use of org.apache.commons.jxpath.ri.compiler.Operation in project collect by openforis.

the class ModelJXPathCompiledExpression method getFunctionNames.

public Set<String> getFunctionNames() {
    Set<String> names = new HashSet<String>();
    Deque<Expression> stack = new LinkedList<Expression>();
    stack.push(getExpression());
    while (!stack.isEmpty()) {
        Expression expression = stack.pop();
        if (expression instanceof Operation) {
            if (expression instanceof CoreFunction || expression instanceof ModelExtensionFunction) {
                String name = expression.toString().replaceAll("\\(.*\\)", "");
                names.add(name);
            }
            Expression[] arguments = ((Operation) expression).getArguments();
            if (arguments != null && arguments.length > 0) {
                for (Expression arg : arguments) {
                    stack.push(arg);
                }
            }
        }
    }
    return names;
}
Also used : CoreFunction(org.apache.commons.jxpath.ri.compiler.CoreFunction) JXPathCompiledExpression(org.apache.commons.jxpath.ri.JXPathCompiledExpression) Expression(org.apache.commons.jxpath.ri.compiler.Expression) Operation(org.apache.commons.jxpath.ri.compiler.Operation) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 2 with Operation

use of org.apache.commons.jxpath.ri.compiler.Operation in project collect by openforis.

the class ModelJXPathCompiledExpression method validateOperations.

private ExpressionValidationResult validateOperations(OperationVaildator operationValidator) {
    Deque<Expression> stack = new LinkedList<Expression>();
    stack.push(getExpression());
    while (!stack.isEmpty()) {
        Expression expression = stack.pop();
        if (expression instanceof Operation) {
            Operation op = (Operation) expression;
            ExpressionValidationResult result = operationValidator.validate(op);
            if (result.isError()) {
                return result;
            } else {
                Expression[] args = op.getArguments();
                if (args != null) {
                    stack.addAll(Arrays.asList(args));
                }
            }
        }
    }
    return new ExpressionValidationResult();
}
Also used : JXPathCompiledExpression(org.apache.commons.jxpath.ri.JXPathCompiledExpression) Expression(org.apache.commons.jxpath.ri.compiler.Expression) Operation(org.apache.commons.jxpath.ri.compiler.Operation) ExpressionValidationResult(org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)2 JXPathCompiledExpression (org.apache.commons.jxpath.ri.JXPathCompiledExpression)2 Expression (org.apache.commons.jxpath.ri.compiler.Expression)2 Operation (org.apache.commons.jxpath.ri.compiler.Operation)2 HashSet (java.util.HashSet)1 CoreFunction (org.apache.commons.jxpath.ri.compiler.CoreFunction)1 ExpressionValidationResult (org.openforis.idm.metamodel.expression.ExpressionValidator.ExpressionValidationResult)1