| 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.parser; |
| 9 | |
| 10 | import net.sf.saxon.expr.Expression; |
| 11 | import net.sf.saxon.type.AnyItemType; |
| 12 | import net.sf.saxon.type.ErrorType; |
| 13 | import net.sf.saxon.type.ItemType; |
| 14 | import net.sf.saxon.type.UType; |
| 15 | |
| 16 | /** |
| 17 | * A data structure that represents the required type of the context item, together |
| 18 | * with information about whether it is known to be present or absent or whether it |
| 19 | * is not known statically whether it is present or absent. |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | public class ContextItemStaticInfo { |
| 24 | |
| 25 | |
| 26 | private ItemType itemType; |
| 27 | private boolean contextMaybeUndefined; |
| 28 | private Expression contextSettingExpression; |
| 29 | |
| 30 | /** |
| 31 | * Create a ContextItemStaticInfo |
| 32 | * @param itemType the item type of the context item. If the context item is absent, set this to |
| 33 | * {@link net.sf.saxon.type.ErrorType#getInstance()}. |
| 34 | * @param maybeUndefined set to true if it is possible (or certain) that the context item will be absent. |
| 35 | */ |
| 36 | |
| 37 | public ContextItemStaticInfo(ItemType itemType, boolean maybeUndefined) { |
| 38 | this.itemType = itemType; |
| 39 | this.contextMaybeUndefined = maybeUndefined; |
| 40 | } |
| 41 | |
| 42 | public void setContextSettingExpression(Expression setter) { |
| 43 | contextSettingExpression = setter; |
| 44 | } |
| 45 | |
| 46 | public Expression getContextSettingExpression() { |
| 47 | return contextSettingExpression; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Get the static type of the context item. If the context item is known to be undefined, the |
| 52 | * returned value is |
| 53 | * @return the static context item type |
| 54 | */ |
| 55 | |
| 56 | public ItemType getItemType() { |
| 57 | return itemType; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Get the static type of the context item as a UType |
| 62 | * @return the static context item type |
| 63 | */ |
| 64 | |
| 65 | public UType getContextItemUType() { |
| 66 | return itemType.getUType(); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Ask whether it is possible that the context item is absent |
| 71 | * @return true if the context item might be absent |
| 72 | */ |
| 73 | |
| 74 | public boolean isPossiblyAbsent() { |
| 75 | return contextMaybeUndefined; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Set streaming posture. The Saxon-HE version of this method has no effect. |
| 80 | */ |
| 81 | |
| 82 | public void setContextPostureStriding() { |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Set streaming posture. The Saxon-HE version of this method has no effect. |
| 87 | */ |
| 88 | |
| 89 | public void setContextPostureGrounded() { |
| 90 | } |
| 91 | |
| 92 | public boolean isStrictStreamabilityRules() { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Default information when nothing else is known |
| 98 | */ |
| 99 | |
| 100 | public final static ContextItemStaticInfo DEFAULT = |
| 101 | new ContextItemStaticInfo(AnyItemType.getInstance(), true); |
| 102 | |
| 103 | public final static ContextItemStaticInfo ABSENT = |
| 104 | new ContextItemStaticInfo(ErrorType.getInstance(), true); |
| 105 | |
| 106 | } |