Example usage for org.apache.commons.jxpath.ri.compiler ExtensionFunction getFunctionName

List of usage examples for org.apache.commons.jxpath.ri.compiler ExtensionFunction getFunctionName

Introduction

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

Prototype

public QName getFunctionName() 

Source Link

Document

Get the function name

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);/*from   www . ja v  a2s.  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) {
    //  }
}

From source file:org.xchain.framework.jxpath.JXPathValidator.java

static void validateExtensionFunction(ExtensionFunction ef, NamespaceContext xmlns) {
    QName name = ef.getFunctionName();
    String prefix = name.getPrefix();

    // validate that the prefix is mapped.
    validatePrefix(prefix, xmlns);//from w  ww .j  ava  2  s .c om

    // if the prefix is mapped to an xchain namespace uri, then validate that a function is bound that might match the function.
    // TODO: add hooks for lifecycle based validation.
}