| 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.expr; |
| 9 | |
| 10 | import net.sf.saxon.om.Item; |
| 11 | import net.sf.saxon.om.Sequence; |
| 12 | import net.sf.saxon.om.StructuredQName; |
| 13 | import net.sf.saxon.trans.XPathException; |
| 14 | import net.sf.saxon.value.IntegerValue; |
| 15 | import net.sf.saxon.value.SequenceType; |
| 16 | |
| 17 | /** |
| 18 | * Binding is a interface used to represent the run-time properties and methods |
| 19 | * associated with a variable: specifically, a method to get the value |
| 20 | * of the variable. |
| 21 | */ |
| 22 | |
| 23 | public interface Binding { |
| 24 | |
| 25 | /** |
| 26 | * Get the declared type of the variable |
| 27 | * |
| 28 | * @return the declared type |
| 29 | */ |
| 30 | |
| 31 | SequenceType getRequiredType(); |
| 32 | |
| 33 | /** |
| 34 | * If the variable is bound to an integer, get the minimum and maximum possible values. |
| 35 | * Return null if unknown or not applicable |
| 36 | * |
| 37 | * @return a pair of integers containing the minimum and maximum values for the integer value; |
| 38 | * or null if the value is not an integer or the range is unknown |
| 39 | */ |
| 40 | |
| 41 | /*@Nullable*/ |
| 42 | IntegerValue[] getIntegerBoundsForVariable(); |
| 43 | |
| 44 | /** |
| 45 | * Evaluate the variable |
| 46 | * |
| 47 | * @param context the XPath dynamic evaluation context |
| 48 | * @return the result of evaluating the variable |
| 49 | * @throws net.sf.saxon.trans.XPathException |
| 50 | * if an error occurs while evaluating |
| 51 | * the variable |
| 52 | */ |
| 53 | |
| 54 | Sequence<?> evaluateVariable(XPathContext context) throws XPathException; |
| 55 | |
| 56 | /** |
| 57 | * Indicate whether the binding is local or global. A global binding is one that has a fixed |
| 58 | * value for the life of a query or transformation; any other binding is local. |
| 59 | * |
| 60 | * @return true if the binding is global |
| 61 | */ |
| 62 | |
| 63 | boolean isGlobal(); |
| 64 | |
| 65 | /** |
| 66 | * Test whether it is permitted to assign to the variable using the saxon:assign |
| 67 | * extension element. This will only be for an XSLT global variable where the extra |
| 68 | * attribute saxon:assignable="yes" is present. |
| 69 | * |
| 70 | * @return true if the binding is assignable |
| 71 | */ |
| 72 | |
| 73 | boolean isAssignable(); |
| 74 | |
| 75 | /** |
| 76 | * Get the name of the variable |
| 77 | * |
| 78 | * @return the name of the variable, as a structured QName |
| 79 | */ |
| 80 | |
| 81 | StructuredQName getVariableQName(); |
| 82 | |
| 83 | /** |
| 84 | * Register a variable reference that refers to the variable bound in this expression |
| 85 | * |
| 86 | * @param ref the variable reference |
| 87 | * @param isLoopingReference - true if the reference occurs within a loop, such as the predicate |
| 88 | * of a filter expression |
| 89 | */ |
| 90 | |
| 91 | void addReference(VariableReference ref, boolean isLoopingReference); |
| 92 | |
| 93 | } |
| 94 |