All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.saxon.xpath.XPathFunctionCall Maven / Gradle / Ivy

There is a newer version: 10.5
Show newest version
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2013 Saxonica Limited.
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package net.sf.saxon.xpath;

import net.sf.saxon.Configuration;
import net.sf.saxon.expr.*;
import net.sf.saxon.expr.parser.ExpressionVisitor;
import net.sf.saxon.expr.parser.PathMap;
import net.sf.saxon.om.*;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.type.ItemType;
import net.sf.saxon.type.Type;
import net.sf.saxon.type.TypeHierarchy;
import net.sf.saxon.value.EmptySequence;

import javax.xml.xpath.XPathFunction;
import javax.xml.xpath.XPathFunctionException;
import java.util.ArrayList;
import java.util.List;



/**
* This class is an expression that calls an external function supplied using the
 * JAXP XPathFunction interface
*/

public class XPathFunctionCall extends FunctionCall implements Callable {

    private XPathFunction function;
    /**
     * Default constructor
     */

    public XPathFunctionCall(XPathFunction function) {
        this.function = function;
    }

    /**
    * preEvaluate: this method suppresses compile-time evaluation by doing nothing
    * (because the external function might have side-effects and might use the context)
     * @param visitor an expression visitor
     */

    /*@NotNull*/ public Expression preEvaluate(ExpressionVisitor visitor) {
        return this;
    }


    /**
    * Method called by the expression parser when all arguments have been supplied
    */

    public void checkArguments(/*@NotNull*/ ExpressionVisitor visitor) throws XPathException {
    }


    /**
     * Determine which aspects of the context the expression depends on. XPath external
     * functions are given no access to context information so they cannot have any
     * dependencies on it.
    */

    public int getIntrinsicDependencies() {
        return 0;
    }


    /**
     * Copy an expression. This makes a deep copy.
     *
     * @return the copy of the original expression
     */

    /*@NotNull*/ public Expression copy() {
        throw new UnsupportedOperationException("XPathFunctionCall.copy()");
    }


    /**
     * Add a representation of this expression to a PathMap. The PathMap captures a map of the nodes visited
     * by an expression in a source tree.
     * 

*

The default implementation of this method assumes that an expression does no navigation other than * the navigation done by evaluating its subexpressions, and that the subexpressions are evaluated in the * same context as the containing expression. The method must be overridden for any expression * where these assumptions do not hold. For example, implementations exist for AxisExpression, ParentExpression, * and RootExpression (because they perform navigation), and for the doc(), document(), and collection() * functions because they create a new navigation root. Implementations also exist for PathExpression and * FilterExpression because they have subexpressions that are evaluated in a different context from the * calling expression.

* * @param pathMap the PathMap to which the expression should be added * @param pathMapNodeSet * @return the pathMapNode representing the focus established by this expression, in the case where this * expression is the first operand of a path expression or filter expression. For an expression that does * navigation, it represents the end of the arc in the path map that describes the navigation route. For other * expressions, it is the same as the input pathMapNode. */ /*@NotNull*/ public PathMap.PathMapNodeSet addToPathMap(/*@NotNull*/ PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet) { return addExternalFunctionCallToPathMap(pathMap, pathMapNodeSet); } /** * Evaluate the function.
* @param context The context in which the function is to be evaluated * @return a Value representing the result of the function. * @throws XPathException if the function cannot be evaluated. */ /*@NotNull*/ public SequenceIterator iterate(/*@NotNull*/ XPathContext context) throws XPathException { Sequence[] argValues = new Sequence[argument.length]; for (int i=0; iThis method will always return a result, though it may be the best approximation * that is available at the time.

* * @return the item type * @param th the type hierarchy cache */ /*@NotNull*/ public ItemType getItemType(TypeHierarchy th) { return Type.ITEM_TYPE; } /** * Determine the cardinality of the result * @return ZERO_OR_MORE (we don't know) */ public int computeCardinality() { return StaticProperty.ALLOWS_ZERO_OR_MORE; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy