Example usage for org.apache.commons.jxpath.ri.compiler Expression toString

List of usage examples for org.apache.commons.jxpath.ri.compiler Expression toString

Introduction

In this page you can find the example usage for org.apache.commons.jxpath.ri.compiler Expression toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:org.chiba.xml.xpath.impl.JXPathReferenceFinderImpl.java

private void addExpressionReferences(Map references, Expression context, Expression expression) {
    // handle location pathes like "../relative/path" or "//absolute/path"
    if (expression instanceof LocationPath) {
        // put location path in context and add as reference
        LocationPath locationPath = (LocationPath) expression;
        Path path = addLocationPath(context, (LocationPath) expression);
        references.put(path.toString(), path);

        // pass empty location path when there is no context
        Expression contextExpression = (Expression) (context == null
                ? this.compiler.locationPath(locationPath.isAbsolute(), null)
                : context);/* w  w  w  .ja v a2  s. com*/
        // add references of step predicates
        addStepReferences(references, contextExpression, locationPath.getSteps());
        return;
    }
    // handle expression pathes like "instance('id')/path" or "ext:function()[predicate]/path"
    if (expression instanceof ExpressionPath) {
        // add expression path as reference
        ExpressionPath expressionPath = (ExpressionPath) expression;
        references.put(expressionPath.toString(), expressionPath);

        // add references in expression predicates
        Expression[] predicates = expressionPath.getPredicates();
        for (int i = 0; predicates != null && i < predicates.length; i++) {
            addExpressionReferences(references, expressionPath.getExpression(), predicates[i]);
        }

        // add references in step predicates
        addStepReferences(references, expressionPath.getExpression(), expressionPath.getSteps());
        return;
    }
    // handle standalone instance() function
    if (expression instanceof ExtensionFunction) {
        ExtensionFunction function = (ExtensionFunction) expression;
        // todo: how to handle all functions returning a nodeset ?
        if (function.getFunctionName().getName().equals("instance")) {
            references.put(expression.toString(), expression);
            return;
        }
    }
    // handle all other operations like "black + white" or "count(../apples and /oranges)"
    if (expression instanceof Operation) {
        Operation operation = (Operation) expression;
        Expression[] arguments = operation.getArguments();

        // add references in function arguments
        for (int i = 0; arguments != null && i < arguments.length; i++) {
            addExpressionReferences(references, context, arguments[i]);
        }
    }
    // don't handle constants
    // if (expression instanceof Constant) {
    // }
    // don't handle variable references (maybe needed someday)
    // if (expression instanceof VariableReference) {
    //  }
}