1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 #include "qbasictypesfactory_p.h"
44 #include "qcommonnamespaces_p.h"
45 #include "qgenericdynamiccontext_p.h"
46 #include "qfunctionfactorycollection_p.h"
47 #include "qgenericnamespaceresolver_p.h"
49 #include "qgenericstaticcontext_p.h"
53 using namespace QPatternist;
55 GenericStaticContext::GenericStaticContext(const NamePool::Ptr &np,
56 QAbstractMessageHandler *const handler,
58 const FunctionFactory::Ptr &factory,
59 const QXmlQuery::QueryLanguage lang) : m_boundarySpacePolicy(BSPStrip)
60 , m_constructionMode(CMPreserve)
61 , m_functionFactory(factory)
62 , m_defaultFunctionNamespace(CommonNamespaces::XFN)
63 , m_orderingEmptySequence(Greatest)
64 , m_orderingMode(Ordered)
65 , m_defaultCollation(QUrl::fromEncoded(CommonNamespaces::UNICODE_COLLATION))
67 , m_messageHandler(handler)
68 , m_preserveMode(Preserve)
69 , m_inheritMode(Inherit)
70 , m_namespaceResolver(lang == QXmlQuery::XQuery10
71 ? GenericNamespaceResolver::defaultXQueryBindings()
72 : GenericNamespaceResolver::defaultXSLTBindings())
75 , m_queryLanguage(lang)
77 , m_compatModeEnabled(false)
79 /* We'll easily have at least this many AST nodes, that we need
80 * to track locations for. */
81 m_locations.reserve(30);
84 Q_ASSERT(!m_baseURI.isRelative());
87 NamespaceResolver::Ptr GenericStaticContext::namespaceBindings() const
89 return m_namespaceResolver;
92 FunctionFactory::Ptr GenericStaticContext::functionSignatures() const
94 return m_functionFactory;
97 DynamicContext::Ptr GenericStaticContext::dynamicContext() const
99 GenericDynamicContext::Ptr context(new GenericDynamicContext(m_namePool, m_messageHandler, sourceLocations()));
100 // TODO we have many bugs here..
101 context->setResourceLoader(m_resourceLoader);
105 SchemaTypeFactory::Ptr GenericStaticContext::schemaDefinitions() const
107 return BasicTypesFactory::self(m_namePool);
110 QUrl GenericStaticContext::baseURI() const
112 Q_ASSERT_X(!m_baseURI.isRelative(), Q_FUNC_INFO,
113 "The static base-uri must be absolute. This error is most likely caused by misuing the API.");
117 void GenericStaticContext::setBaseURI(const QUrl &uri)
119 Q_ASSERT(!uri.isRelative());
123 bool GenericStaticContext::compatModeEnabled() const
125 return m_compatModeEnabled;
128 void GenericStaticContext::setCompatModeEnabled(const bool newVal)
130 m_compatModeEnabled = newVal;
133 QUrl GenericStaticContext::defaultCollation() const
135 return m_defaultCollation;
138 QAbstractMessageHandler * GenericStaticContext::messageHandler() const
140 return m_messageHandler;
143 void GenericStaticContext::setDefaultCollation(const QUrl &uri)
145 m_defaultCollation = uri;
148 void GenericStaticContext::setNamespaceBindings(const NamespaceResolver::Ptr &resolver)
151 m_namespaceResolver = resolver;
154 StaticContext::BoundarySpacePolicy GenericStaticContext::boundarySpacePolicy() const
156 return m_boundarySpacePolicy;
159 void GenericStaticContext::setBoundarySpacePolicy(const BoundarySpacePolicy policy)
161 Q_ASSERT(policy == BSPPreserve || policy == BSPStrip);
162 m_boundarySpacePolicy = policy;
165 StaticContext::ConstructionMode GenericStaticContext::constructionMode() const
167 return m_constructionMode;
170 void GenericStaticContext::setConstructionMode(const ConstructionMode mode)
172 Q_ASSERT(mode == CMPreserve || mode == CMStrip);
173 m_constructionMode = mode;
176 StaticContext::OrderingMode GenericStaticContext::orderingMode() const
178 return m_orderingMode;
181 void GenericStaticContext::setOrderingMode(const OrderingMode mode)
183 Q_ASSERT(mode == Ordered || mode == Unordered);
184 m_orderingMode = mode;
187 StaticContext::OrderingEmptySequence GenericStaticContext::orderingEmptySequence() const
189 return m_orderingEmptySequence;
192 void GenericStaticContext::setOrderingEmptySequence(const OrderingEmptySequence ordering)
194 Q_ASSERT(ordering == Greatest || ordering == Least);
195 m_orderingEmptySequence = ordering;
198 QString GenericStaticContext::defaultFunctionNamespace() const
200 return m_defaultFunctionNamespace;
203 void GenericStaticContext::setDefaultFunctionNamespace(const QString &ns)
205 m_defaultFunctionNamespace = ns;
209 QString GenericStaticContext::defaultElementNamespace() const
211 return m_defaultElementNamespace;
214 void GenericStaticContext::setDefaultElementNamespace(const QString &ns)
216 m_defaultElementNamespace = ns;
219 StaticContext::InheritMode GenericStaticContext::inheritMode() const
221 return m_inheritMode;
224 void GenericStaticContext::setInheritMode(const InheritMode mode)
226 Q_ASSERT(mode == Inherit || mode == NoInherit);
227 m_inheritMode = mode;
230 StaticContext::PreserveMode GenericStaticContext::preserveMode() const
232 return m_preserveMode;
235 void GenericStaticContext::setPreserveMode(const PreserveMode mode)
237 Q_ASSERT(mode == Preserve || mode == NoPreserve);
238 m_preserveMode = mode;
241 ItemType::Ptr GenericStaticContext::contextItemType() const
243 return m_contextItemType;
246 ItemType::Ptr GenericStaticContext::currentItemType() const
248 return contextItemType();
251 void GenericStaticContext::setContextItemType(const ItemType::Ptr &type)
253 m_contextItemType = type;
256 StaticContext::Ptr GenericStaticContext::copy() const
258 GenericStaticContext *const retval = new GenericStaticContext(m_namePool, m_messageHandler, m_baseURI, m_functionFactory, m_queryLanguage);
259 const NamespaceResolver::Ptr newSolver(new GenericNamespaceResolver(m_namespaceResolver->bindings()));
261 retval->setNamespaceBindings(newSolver);
262 retval->setDefaultCollation(m_defaultCollation);
263 retval->setBoundarySpacePolicy(m_boundarySpacePolicy);
264 retval->setConstructionMode(m_constructionMode);
265 retval->setOrderingMode(m_orderingMode);
266 retval->setOrderingEmptySequence(m_orderingEmptySequence);
267 retval->setDefaultFunctionNamespace(m_defaultFunctionNamespace);
268 retval->setInheritMode(m_inheritMode);
269 retval->setPreserveMode(m_preserveMode);
270 retval->setExternalVariableLoader(m_externalVariableLoader);
271 retval->setResourceLoader(m_resourceLoader);
272 retval->setContextItemType(m_contextItemType);
273 retval->m_locations = m_locations;
275 return StaticContext::Ptr(retval);
278 ResourceLoader::Ptr GenericStaticContext::resourceLoader() const
280 return m_resourceLoader;
283 void GenericStaticContext::setResourceLoader(const ResourceLoader::Ptr &loader)
285 m_resourceLoader = loader;
288 ExternalVariableLoader::Ptr GenericStaticContext::externalVariableLoader() const
290 return m_externalVariableLoader;
293 void GenericStaticContext::setExternalVariableLoader(const ExternalVariableLoader::Ptr &loader)
295 m_externalVariableLoader = loader;
298 NamePool::Ptr GenericStaticContext::namePool() const
303 void GenericStaticContext::addLocation(const SourceLocationReflection *const reflection,
304 const QSourceLocation &location)
306 Q_ASSERT(!location.isNull());
307 Q_ASSERT_X(reflection, Q_FUNC_INFO,
308 "The reflection cannot be zero.");
309 m_locations.insert(reflection, location);
312 StaticContext::LocationHash GenericStaticContext::sourceLocations() const
317 QSourceLocation GenericStaticContext::locationFor(const SourceLocationReflection *const reflection) const
319 return m_locations.value(reflection->actualReflection());
322 QAbstractUriResolver *GenericStaticContext::uriResolver() const
324 return m_uriResolver;
327 VariableSlotID GenericStaticContext::currentRangeSlot() const
332 VariableSlotID GenericStaticContext::allocateRangeSlot()