| 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.style; |
| 9 | |
| 10 | import net.sf.saxon.om.StandardNames; |
| 11 | import net.sf.saxon.om.StructuredQName; |
| 12 | import net.sf.saxon.trace.LocationKind; |
| 13 | import net.sf.saxon.trans.XPathException; |
| 14 | |
| 15 | /** |
| 16 | * This class defines common behaviour across xsl:variable, xsl:param, and xsl:with-param |
| 17 | */ |
| 18 | |
| 19 | public abstract class XSLGeneralVariable extends StyleElement { |
| 20 | |
| 21 | protected SourceBinding sourceBinding = new SourceBinding(this); |
| 22 | |
| 23 | /** |
| 24 | * Get the source binding object that holds information about the declared variable. |
| 25 | */ |
| 26 | |
| 27 | public SourceBinding getSourceBinding() { |
| 28 | return sourceBinding; |
| 29 | } |
| 30 | |
| 31 | public StructuredQName getVariableQName() { |
| 32 | return sourceBinding.getVariableQName(); |
| 33 | } |
| 34 | |
| 35 | public StructuredQName getObjectName() { |
| 36 | return sourceBinding.getVariableQName(); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Determine whether this type of element is allowed to contain a template-body |
| 41 | * |
| 42 | * @return true: yes, it may contain a template-body |
| 43 | */ |
| 44 | |
| 45 | public boolean mayContainSequenceConstructor() { |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Test whether this is a global variable or parameter |
| 51 | * |
| 52 | * @return true if this is global |
| 53 | */ |
| 54 | |
| 55 | public boolean isGlobal() { |
| 56 | return isTopLevel(); |
| 57 | // might be called before the "global" field is initialized |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Check that the variable is not already declared, and allocate a slot number |
| 62 | * |
| 63 | * @param decl the declaration being validated. A single XSLVariableDeclaration object may represent |
| 64 | * multiple declarations if it appears in a stylesheet module that is included/imported more than once |
| 65 | */ |
| 66 | |
| 67 | public void validate(ComponentDeclaration decl) throws XPathException { |
| 68 | sourceBinding.validate(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Hook to allow additional validation of a parent element immediately after its |
| 73 | * children have been validated. |
| 74 | */ |
| 75 | |
| 76 | public void postValidate() throws XPathException { |
| 77 | sourceBinding.postValidate(); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Get the type of construct. This will be a constant in |
| 82 | * class {@link LocationKind}. This method is part of the |
| 83 | * {@link net.sf.saxon.trace.InstructionInfo} interface |
| 84 | */ |
| 85 | |
| 86 | public int getConstructType() { |
| 87 | return StandardNames.XSL_VARIABLE; |
| 88 | } |
| 89 | |
| 90 | |
| 91 | } |
| 92 |