| 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 | |
| 11 | import net.sf.saxon.trans.SymbolicName; |
| 12 | |
| 13 | /** |
| 14 | * A ComponentBinding is a reference from one component to another; for example a variable |
| 15 | * reference or function call. ComponentBindings are held in the binding vector of the calling |
| 16 | * component, and are separate from the instruction/expression that contains the reference, to provide |
| 17 | * a level of indirection; this means that when a component is re-bound in a using package, for example |
| 18 | * to call overriding versions of templates or functions called from the component, the compiled code of |
| 19 | * the calling component does not need to be changed, only the contents of the binding vector. |
| 20 | * |
| 21 | * <p>The ComponentBinding class is immutable.</p> |
| 22 | */ |
| 23 | |
| 24 | public class ComponentBinding { |
| 25 | |
| 26 | private SymbolicName symbolicName; |
| 27 | private Component target; |
| 28 | |
| 29 | /** |
| 30 | * Create a ComponentBinding |
| 31 | * |
| 32 | * @param name the symbolic name of the component that is the target of this binding. This includes |
| 33 | * the component kind (e.g. function, template, variable), its name, and in the case of functions, its |
| 34 | * arity. |
| 35 | * @param target the target of the binding |
| 36 | */ |
| 37 | |
| 38 | public ComponentBinding(SymbolicName name, Component target) { |
| 39 | this.symbolicName = name; |
| 40 | this.target = target; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Get the symbolic name of the component binding |
| 45 | * |
| 46 | * @return the symbolic name of the component that is the target of this binding. This includes |
| 47 | * the component kind (e.g. function, template, variable), its name, and in the case of functions, its |
| 48 | * arity. |
| 49 | */ |
| 50 | |
| 51 | public SymbolicName getSymbolicName() { |
| 52 | return symbolicName; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get the target of the component binding, for example a template, function, or global variable. |
| 57 | * |
| 58 | * @return the target of the component binding |
| 59 | */ |
| 60 | |
| 61 | public Component getTarget() { |
| 62 | return target; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | } |
| 67 |