| 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.tree.wrapper; |
| 9 | |
| 10 | import net.sf.saxon.om.Item; |
| 11 | import net.sf.saxon.om.NodeInfo; |
| 12 | import net.sf.saxon.tree.iter.AxisIterator; |
| 13 | |
| 14 | /** |
| 15 | * A WrappingIterator delivers wrappers for the nodes delivered |
| 16 | * by its underlying iterator. It is used when no whitespace stripping |
| 17 | * is actually needed, e.g. for the attribute axis. But we still need to |
| 18 | * create wrappers, so that further iteration remains in the virtual layer |
| 19 | * rather than switching to the real nodes. |
| 20 | */ |
| 21 | |
| 22 | public class WrappingIterator implements AxisIterator { |
| 23 | |
| 24 | AxisIterator base; |
| 25 | VirtualNode parent; |
| 26 | /*@Nullable*/ NodeInfo current; |
| 27 | boolean atomizing = false; |
| 28 | WrappingFunction wrappingFunction; |
| 29 | |
| 30 | /** |
| 31 | * Create a WrappingIterator |
| 32 | * |
| 33 | * @param base The underlying iterator |
| 34 | * @param parent If all the nodes to be wrapped have the same parent, |
| 35 | * it can be specified here. Otherwise specify null. |
| 36 | */ |
| 37 | |
| 38 | public WrappingIterator(AxisIterator base, WrappingFunction function, VirtualNode parent) { |
| 39 | this.base = base; |
| 40 | this.wrappingFunction = function; |
| 41 | this.parent = parent; |
| 42 | } |
| 43 | |
| 44 | |
| 45 | /*@Nullable*/ |
| 46 | public NodeInfo next() { |
| 47 | Item n = base.next(); |
| 48 | if (n instanceof NodeInfo && !atomizing) { |
| 49 | current = wrappingFunction.makeWrapper((NodeInfo) n, parent); |
| 50 | } else { |
| 51 | current = (NodeInfo) n; |
| 52 | } |
| 53 | return current; |
| 54 | } |
| 55 | |
| 56 | /*@Nullable*/ |
| 57 | public NodeInfo current() { |
| 58 | return current; |
| 59 | } |
| 60 | |
| 61 | public void close() { |
| 62 | base.close(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Get properties of this iterator, as a bit-significant integer. |
| 67 | * |
| 68 | * @return the properties of this iterator. This will be some combination of |
| 69 | * properties such as {@link #GROUNDED}, {@link #LAST_POSITION_FINDER}, |
| 70 | * and {@link #LOOKAHEAD}. It is always |
| 71 | * acceptable to return the value zero, indicating that there are no known special properties. |
| 72 | * It is acceptable for the properties of the iterator to change depending on its state. |
| 73 | */ |
| 74 | |
| 75 | public int getProperties() { |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | } |
| 81 |