1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49
50#ifndef Patternist_ExternalVariableLoader_H
51#define Patternist_ExternalVariableLoader_H
52
53#include <private/qitem_p.h>
54#include <private/qsequencetype_p.h>
55#include <QXmlName>
56
57QT_BEGIN_NAMESPACE
58
59namespace QPatternist
60{
61 class DynamicContext;
62
63 /**
64 * @short Responsible for loading and declaring available external variables.
65 *
66 * An external variable in XQuery is a global variable that has been declared to receive
67 * its value from the XQuery implementation, as opposed to an initializing expression. Here
68 * is an example of a query with an external variable declaration, followed by a ordinary
69 * global variable:
70 *
71 * <tt> declare variable $theName external;
72 * declare variable $theName := "the value";
73 * "And here's the query body(a string literal)"</tt>
74 *
75 * An external variable declaration can also specify a sequence type:
76 *
77 * <tt>declare variable $theName as xs:integer external;</tt>
78 *
79 * This class allows the user to supply the values to external variables. When
80 * an external variable declaration occur in the query,
81 * announceExternalVariable() is called.
82 *
83 * @ingroup Patternist_xdm
84 * @author Frans Englich <frans.englich@nokia.com>
85 */
86 class Q_AUTOTEST_EXPORT ExternalVariableLoader : public QSharedData
87 {
88 public:
89 typedef QExplicitlySharedDataPointer<ExternalVariableLoader> Ptr;
90 inline ExternalVariableLoader() {}
91
92 virtual ~ExternalVariableLoader();
93
94 /**
95 * Called when Patternist encounters an external variable in the query. It is guaranteed
96 * to be called once for each external variable appearing in a query module.
97 *
98 * @param name the name of the variable. Quaranteed to never be @c null.
99 * @param declaredType the type that the user declared the variable to be of. Whether
100 * this type matches the actual value of the variable or not is irrelevant. Patternist
101 * will do the necessary error handling based on the sequence type that is returned from
102 * this function. If the user didn't declare a type, the type is <tt>item()*</tt>(zero or
103 * more items). Quaranteed to never be @c null.
104 * @returns the sequence type of the value this ExternalVariableLoader actually supplies. However,
105 * if the ExternalVariableLoader knows it cannot supply a variable by this name, @c null should be
106 * returned.
107 */
108 virtual SequenceType::Ptr announceExternalVariable(const QXmlName name,
109 const SequenceType::Ptr &declaredType);
110
111 /**
112 * This function is called at runtime when the external variable by name @p name needs
113 * to be evaluated. It is not defined how many times this function will be called. It
114 * depends on aspects such as how the query was optimized.
115 *
116 * @param name the name of the variable. Quaranteed to never be @c null.
117 * @param context the DynamicContext.
118 * @returns the value of the variable. Remember that this value must match the
119 * sequence type returned from announceExternalVariable() for the same name.
120 */
121 virtual Item::Iterator::Ptr evaluateSequence(const QXmlName name,
122 const QExplicitlySharedDataPointer<DynamicContext> &context);
123
124 virtual Item evaluateSingleton(const QXmlName name,
125 const QExplicitlySharedDataPointer<DynamicContext> &context);
126 virtual bool evaluateEBV(const QXmlName name,
127 const QExplicitlySharedDataPointer<DynamicContext> &context);
128 };
129}
130
131QT_END_NAMESPACE
132
133#endif
134

source code of qtxmlpatterns/src/xmlpatterns/expr/qexternalvariableloader_p.h