| 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.SequenceIterator; |
| 12 | import net.sf.saxon.trans.XPathException; |
| 13 | |
| 14 | /** |
| 15 | * A SequenceIterator that throws an exception as soon as its next() method is called. Used when |
| 16 | * the method that returns the iterator isn't allowed to throw a checked exception itself. |
| 17 | */ |
| 18 | public class ErrorIterator implements SequenceIterator<Item<?>> { |
| 19 | |
| 20 | private XPathException exception; |
| 21 | |
| 22 | public ErrorIterator(XPathException exception) { |
| 23 | this.exception = exception; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Get the next item in the sequence. This method changes the state of the |
| 28 | * iterator, in particular it affects the result of subsequent calls of |
| 29 | * position() and current(). |
| 30 | * |
| 31 | * @return the next item, or null if there are no more items. Once a call |
| 32 | * on next() has returned null, no further calls should be made. The preferred |
| 33 | * action for an iterator if subsequent calls on next() are made is to return |
| 34 | * null again, and all implementations within Saxon follow this rule. |
| 35 | * @throws net.sf.saxon.trans.XPathException |
| 36 | * if an error occurs retrieving the next item |
| 37 | * @since 8.4 |
| 38 | */ |
| 39 | |
| 40 | public Item next() throws XPathException { |
| 41 | throw exception; |
| 42 | } |
| 43 | |
| 44 | public void close() { |
| 45 | |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Get properties of this iterator, as a bit-significant integer. |
| 50 | * |
| 51 | * @return the properties of this iterator. This will be some combination of |
| 52 | * properties such as {@link #GROUNDED}, {@link #LAST_POSITION_FINDER}, |
| 53 | * and {@link #LOOKAHEAD}. It is always |
| 54 | * acceptable to return the value zero, indicating that there are no known special properties. |
| 55 | * It is acceptable for the properties of the iterator to change depending on its state. |
| 56 | * @since 8.6 |
| 57 | */ |
| 58 | |
| 59 | public int getProperties() { |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | } |
| 64 |