Example usage for javax.xml.xpath XPathFunctionResolver resolveFunction

List of usage examples for javax.xml.xpath XPathFunctionResolver resolveFunction

Introduction

In this page you can find the example usage for javax.xml.xpath XPathFunctionResolver resolveFunction.

Prototype

public XPathFunction resolveFunction(QName functionName, int arity);

Source Link

Document

Find a function in the set of available functions.

If functionName or arity is null, then a NullPointerException is thrown.

Usage

From source file:org.apache.camel.builder.xml.XPathBuilder.java

protected XPathFunctionResolver createDefaultFunctionResolver(final XPathFunctionResolver parent) {
    return new XPathFunctionResolver() {
        public XPathFunction resolveFunction(QName qName, int argumentCount) {
            XPathFunction answer = null;
            if (parent != null) {
                answer = parent.resolveFunction(qName, argumentCount);
            }//from   w  w w .  j  a va2s .co  m
            if (answer == null) {
                if (isMatchingNamespaceOrEmptyNamespace(qName.getNamespaceURI(), IN_NAMESPACE)
                        || isMatchingNamespaceOrEmptyNamespace(qName.getNamespaceURI(), DEFAULT_NAMESPACE)) {
                    String localPart = qName.getLocalPart();
                    if (localPart.equals("body") && argumentCount == 0) {
                        return getBodyFunction();
                    }
                    if (localPart.equals("header") && argumentCount == 1) {
                        return getHeaderFunction();
                    }
                }
                if (isMatchingNamespaceOrEmptyNamespace(qName.getNamespaceURI(), OUT_NAMESPACE)) {
                    String localPart = qName.getLocalPart();
                    if (localPart.equals("body") && argumentCount == 0) {
                        return getOutBodyFunction();
                    }
                    if (localPart.equals("header") && argumentCount == 1) {
                        return getOutHeaderFunction();
                    }
                }
                if (isMatchingNamespaceOrEmptyNamespace(qName.getNamespaceURI(), FUNCTION_NAMESPACE)) {
                    String localPart = qName.getLocalPart();
                    if (localPart.equals("properties") && argumentCount == 1) {
                        return getPropertiesFunction();
                    }
                    if (localPart.equals("simple") && argumentCount == 1) {
                        return getSimpleFunction();
                    }
                }
            }
            return answer;
        }
    };
}