| 1 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 2 | // Copyright (c) 2018 Saxonica Limited. |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. |
| 4 | // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. |
| 6 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 7 | |
| 8 | package net.sf.saxon.functions; |
| 9 | |
| 10 | import net.sf.saxon.expr.XPathContext; |
| 11 | import net.sf.saxon.om.Function; |
| 12 | import net.sf.saxon.om.Sequence; |
| 13 | import net.sf.saxon.trans.XPathException; |
| 14 | |
| 15 | /** |
| 16 | * A ContextAccessorFunction is a function that is dependent on the dynamic context. In the case |
| 17 | * of dynamic function calls, the context is bound at the point where the function is created, |
| 18 | * not at the point where the function is called. |
| 19 | */ |
| 20 | |
| 21 | public abstract class ContextAccessorFunction extends SystemFunction { |
| 22 | |
| 23 | /** |
| 24 | * Bind a context item to appear as part of the function's closure. If this method |
| 25 | * has been called, the supplied context item will be used in preference to the |
| 26 | * context item at the point where the function is actually called. |
| 27 | * @param context the context to which the function applies. Must not be null. |
| 28 | */ |
| 29 | |
| 30 | public abstract Function bindContext(XPathContext context) throws XPathException; |
| 31 | |
| 32 | |
| 33 | /** |
| 34 | * Evaluate the expression |
| 35 | * |
| 36 | * @param context the dynamic evaluation context |
| 37 | * @param arguments the values of the arguments, supplied as Sequences |
| 38 | * @return the result of the evaluation, in the form of a Sequence |
| 39 | * @throws net.sf.saxon.trans.XPathException if a dynamic error occurs during the evaluation of the expression |
| 40 | */ |
| 41 | public Sequence<?> call(XPathContext context, Sequence[] arguments) throws XPathException { |
| 42 | return bindContext(context).call(context, arguments); |
| 43 | } |
| 44 | |
| 45 | } |
| 46 |