|
| 1 | +/* |
| 2 | + * Copyright (C) 2014, Evolved Binary Ltd |
| 3 | + * |
| 4 | + * This file was originally ported from FusionDB to eXist-db by |
| 5 | + * Evolved Binary, for the benefit of the eXist-db Open Source community. |
| 6 | + * Only the ported code as it appears in this file, at the time that |
| 7 | + * it was contributed to eXist-db, was re-licensed under The GNU |
| 8 | + * Lesser General Public License v2.1 only for use in eXist-db. |
| 9 | + * |
| 10 | + * This license grant applies only to a snapshot of the code as it |
| 11 | + * appeared when ported, it does not offer or infer any rights to either |
| 12 | + * updates of this source code or access to the original source code. |
| 13 | + * |
| 14 | + * The GNU Lesser General Public License v2.1 only license follows. |
| 15 | + * |
| 16 | + * --------------------------------------------------------------------- |
| 17 | + * |
| 18 | + * Copyright (C) 2014, Evolved Binary Ltd |
| 19 | + * |
| 20 | + * This library is free software; you can redistribute it and/or |
| 21 | + * modify it under the terms of the GNU Lesser General Public |
| 22 | + * License as published by the Free Software Foundation; version 2.1. |
| 23 | + * |
| 24 | + * This library is distributed in the hope that it will be useful, |
| 25 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 27 | + * Lesser General Public License for more details. |
| 28 | + * |
| 29 | + * You should have received a copy of the GNU Lesser General Public |
| 30 | + * License along with this library; if not, write to the Free Software |
| 31 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 32 | + */ |
| 33 | +package org.exist.xquery; |
| 34 | + |
| 35 | +import org.exist.xquery.value.Item; |
| 36 | +import org.exist.xquery.value.Sequence; |
| 37 | + |
| 38 | +import javax.annotation.Nullable; |
| 39 | + |
| 40 | +/** |
| 41 | + * Marks an expression as being Materializable as per the |
| 42 | + * Materialization query execution model. |
| 43 | + * |
| 44 | + * @author <a href="mailto:[email protected]">Adam Retter</a> |
| 45 | + */ |
| 46 | +public interface Materializable { |
| 47 | + |
| 48 | + /** |
| 49 | + * Materialize the result. |
| 50 | + * |
| 51 | + * Depending on the context in which this expression is executed, |
| 52 | + * either the context sequence, the context item or both of them may |
| 53 | + * be set. An implementing class should know how to handle this. |
| 54 | + * |
| 55 | + * The general contract is as follows: if the {@link Dependency#CONTEXT_ITEM} |
| 56 | + * bit is set in the bit field returned by {@link Expression#getDependencies()}, the eval method will |
| 57 | + * be called once for every item in the context sequence. The <b>contextItem</b> |
| 58 | + * parameter will be set to the current item. Otherwise, the eval method will only be called |
| 59 | + * once for the whole context sequence and <b>contextItem</b> will be null. |
| 60 | + * |
| 61 | + * eXist-db tries to process the entire context set in one, single step whenever |
| 62 | + * possible. Thus, most classes only expect context to contain a list of |
| 63 | + * nodes which represents the current context of the expression. |
| 64 | + * |
| 65 | + * The position() function in XPath is an example for an expression, |
| 66 | + * which requires both, context sequence and context item to be set. |
| 67 | + * |
| 68 | + * The context sequence might be a node set, a sequence of atomic values or a single |
| 69 | + * node or atomic value. |
| 70 | + * |
| 71 | + * @param contextSequence the current context sequence, or null if there is no context sequence. |
| 72 | + * @param contextItem a single item, taken from context, or null if there is no context item. |
| 73 | + * This defines the item, the expression should work on. |
| 74 | + * |
| 75 | + * @return the result sequence. |
| 76 | + * |
| 77 | + * @throws XPathException if an error occurs during evaluation. |
| 78 | + */ |
| 79 | + Sequence eval(@Nullable Sequence contextSequence, @Nullable Item contextItem) throws XPathException; |
| 80 | +} |
0 commit comments