[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at qt-info@nokia.com.
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | /* Patternist */
|
---|
| 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"
|
---|
| 48 |
|
---|
| 49 | #include "qgenericstaticcontext_p.h"
|
---|
| 50 |
|
---|
| 51 | QT_BEGIN_NAMESPACE
|
---|
| 52 |
|
---|
| 53 | using namespace QPatternist;
|
---|
| 54 |
|
---|
| 55 | GenericStaticContext::GenericStaticContext(const NamePool::Ptr &np,
|
---|
| 56 | QAbstractMessageHandler *const handler,
|
---|
| 57 | const QUrl &aBaseURI,
|
---|
| 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))
|
---|
| 66 | , m_baseURI(aBaseURI)
|
---|
| 67 | , m_messageHandler(handler)
|
---|
| 68 | , m_preserveMode(Preserve)
|
---|
| 69 | , m_inheritMode(Inherit)
|
---|
| 70 | , m_namespaceResolver(lang == QXmlQuery::XQuery10
|
---|
| 71 | ? GenericNamespaceResolver::defaultXQueryBindings()
|
---|
| 72 | : GenericNamespaceResolver::defaultXSLTBindings())
|
---|
| 73 | , m_namePool(np)
|
---|
| 74 | , m_uriResolver(0)
|
---|
| 75 | , m_queryLanguage(lang)
|
---|
| 76 | , m_rangeSlot(-1)
|
---|
| 77 | , m_compatModeEnabled(false)
|
---|
| 78 | {
|
---|
| 79 | /* We'll easily have at least this many AST nodes, that we need
|
---|
| 80 | * to track locations for. */
|
---|
| 81 | m_locations.reserve(30);
|
---|
| 82 |
|
---|
| 83 | Q_ASSERT(np);
|
---|
| 84 | Q_ASSERT(!m_baseURI.isRelative());
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | NamespaceResolver::Ptr GenericStaticContext::namespaceBindings() const
|
---|
| 88 | {
|
---|
| 89 | return m_namespaceResolver;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | FunctionFactory::Ptr GenericStaticContext::functionSignatures() const
|
---|
| 93 | {
|
---|
| 94 | return m_functionFactory;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | DynamicContext::Ptr GenericStaticContext::dynamicContext() const
|
---|
| 98 | {
|
---|
| 99 | GenericDynamicContext::Ptr context(new GenericDynamicContext(m_namePool, m_messageHandler, sourceLocations()));
|
---|
| 100 | // TODO we have many bugs here..
|
---|
| 101 | context->setResourceLoader(m_resourceLoader);
|
---|
| 102 | return context;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | SchemaTypeFactory::Ptr GenericStaticContext::schemaDefinitions() const
|
---|
| 106 | {
|
---|
| 107 | return BasicTypesFactory::self(m_namePool);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | QUrl GenericStaticContext::baseURI() const
|
---|
| 111 | {
|
---|
| 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.");
|
---|
| 114 | return m_baseURI;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | void GenericStaticContext::setBaseURI(const QUrl &uri)
|
---|
| 118 | {
|
---|
| 119 | Q_ASSERT(!uri.isRelative());
|
---|
| 120 | m_baseURI = uri;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | bool GenericStaticContext::compatModeEnabled() const
|
---|
| 124 | {
|
---|
| 125 | return m_compatModeEnabled;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | void GenericStaticContext::setCompatModeEnabled(const bool newVal)
|
---|
| 129 | {
|
---|
| 130 | m_compatModeEnabled = newVal;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | QUrl GenericStaticContext::defaultCollation() const
|
---|
| 134 | {
|
---|
| 135 | return m_defaultCollation;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | QAbstractMessageHandler * GenericStaticContext::messageHandler() const
|
---|
| 139 | {
|
---|
| 140 | return m_messageHandler;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | void GenericStaticContext::setDefaultCollation(const QUrl &uri)
|
---|
| 144 | {
|
---|
| 145 | m_defaultCollation = uri;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | void GenericStaticContext::setNamespaceBindings(const NamespaceResolver::Ptr &resolver)
|
---|
| 149 | {
|
---|
| 150 | Q_ASSERT(resolver);
|
---|
| 151 | m_namespaceResolver = resolver;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | StaticContext::BoundarySpacePolicy GenericStaticContext::boundarySpacePolicy() const
|
---|
| 155 | {
|
---|
| 156 | return m_boundarySpacePolicy;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | void GenericStaticContext::setBoundarySpacePolicy(const BoundarySpacePolicy policy)
|
---|
| 160 | {
|
---|
| 161 | Q_ASSERT(policy == BSPPreserve || policy == BSPStrip);
|
---|
| 162 | m_boundarySpacePolicy = policy;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 | StaticContext::ConstructionMode GenericStaticContext::constructionMode() const
|
---|
| 166 | {
|
---|
| 167 | return m_constructionMode;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | void GenericStaticContext::setConstructionMode(const ConstructionMode mode)
|
---|
| 171 | {
|
---|
| 172 | Q_ASSERT(mode == CMPreserve || mode == CMStrip);
|
---|
| 173 | m_constructionMode = mode;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | StaticContext::OrderingMode GenericStaticContext::orderingMode() const
|
---|
| 177 | {
|
---|
| 178 | return m_orderingMode;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | void GenericStaticContext::setOrderingMode(const OrderingMode mode)
|
---|
| 182 | {
|
---|
| 183 | Q_ASSERT(mode == Ordered || mode == Unordered);
|
---|
| 184 | m_orderingMode = mode;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | StaticContext::OrderingEmptySequence GenericStaticContext::orderingEmptySequence() const
|
---|
| 188 | {
|
---|
| 189 | return m_orderingEmptySequence;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | void GenericStaticContext::setOrderingEmptySequence(const OrderingEmptySequence ordering)
|
---|
| 193 | {
|
---|
| 194 | Q_ASSERT(ordering == Greatest || ordering == Least);
|
---|
| 195 | m_orderingEmptySequence = ordering;
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | QString GenericStaticContext::defaultFunctionNamespace() const
|
---|
| 199 | {
|
---|
| 200 | return m_defaultFunctionNamespace;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | void GenericStaticContext::setDefaultFunctionNamespace(const QString &ns)
|
---|
| 204 | {
|
---|
| 205 | m_defaultFunctionNamespace = ns;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 |
|
---|
| 209 | QString GenericStaticContext::defaultElementNamespace() const
|
---|
| 210 | {
|
---|
| 211 | return m_defaultElementNamespace;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | void GenericStaticContext::setDefaultElementNamespace(const QString &ns)
|
---|
| 215 | {
|
---|
| 216 | m_defaultElementNamespace = ns;
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | StaticContext::InheritMode GenericStaticContext::inheritMode() const
|
---|
| 220 | {
|
---|
| 221 | return m_inheritMode;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 | void GenericStaticContext::setInheritMode(const InheritMode mode)
|
---|
| 225 | {
|
---|
| 226 | Q_ASSERT(mode == Inherit || mode == NoInherit);
|
---|
| 227 | m_inheritMode = mode;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | StaticContext::PreserveMode GenericStaticContext::preserveMode() const
|
---|
| 231 | {
|
---|
| 232 | return m_preserveMode;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | void GenericStaticContext::setPreserveMode(const PreserveMode mode)
|
---|
| 236 | {
|
---|
| 237 | Q_ASSERT(mode == Preserve || mode == NoPreserve);
|
---|
| 238 | m_preserveMode = mode;
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 | ItemType::Ptr GenericStaticContext::contextItemType() const
|
---|
| 242 | {
|
---|
| 243 | return m_contextItemType;
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 | ItemType::Ptr GenericStaticContext::currentItemType() const
|
---|
| 247 | {
|
---|
| 248 | return contextItemType();
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | void GenericStaticContext::setContextItemType(const ItemType::Ptr &type)
|
---|
| 252 | {
|
---|
| 253 | m_contextItemType = type;
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | StaticContext::Ptr GenericStaticContext::copy() const
|
---|
| 257 | {
|
---|
| 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()));
|
---|
| 260 |
|
---|
| 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;
|
---|
| 274 |
|
---|
| 275 | return StaticContext::Ptr(retval);
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | ResourceLoader::Ptr GenericStaticContext::resourceLoader() const
|
---|
| 279 | {
|
---|
| 280 | return m_resourceLoader;
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | void GenericStaticContext::setResourceLoader(const ResourceLoader::Ptr &loader)
|
---|
| 284 | {
|
---|
| 285 | m_resourceLoader = loader;
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | ExternalVariableLoader::Ptr GenericStaticContext::externalVariableLoader() const
|
---|
| 289 | {
|
---|
| 290 | return m_externalVariableLoader;
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | void GenericStaticContext::setExternalVariableLoader(const ExternalVariableLoader::Ptr &loader)
|
---|
| 294 | {
|
---|
| 295 | m_externalVariableLoader = loader;
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | NamePool::Ptr GenericStaticContext::namePool() const
|
---|
| 299 | {
|
---|
| 300 | return m_namePool;
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | void GenericStaticContext::addLocation(const SourceLocationReflection *const reflection,
|
---|
| 304 | const QSourceLocation &location)
|
---|
| 305 | {
|
---|
| 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);
|
---|
| 310 | }
|
---|
| 311 |
|
---|
| 312 | StaticContext::LocationHash GenericStaticContext::sourceLocations() const
|
---|
| 313 | {
|
---|
| 314 | return m_locations;
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | QSourceLocation GenericStaticContext::locationFor(const SourceLocationReflection *const reflection) const
|
---|
| 318 | {
|
---|
| 319 | return m_locations.value(reflection->actualReflection());
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | QAbstractUriResolver *GenericStaticContext::uriResolver() const
|
---|
| 323 | {
|
---|
| 324 | return m_uriResolver;
|
---|
| 325 | }
|
---|
| 326 |
|
---|
| 327 | VariableSlotID GenericStaticContext::currentRangeSlot() const
|
---|
| 328 | {
|
---|
| 329 | return m_rangeSlot;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | VariableSlotID GenericStaticContext::allocateRangeSlot()
|
---|
| 333 | {
|
---|
| 334 | ++m_rangeSlot;
|
---|
| 335 | return m_rangeSlot;
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | QT_END_NAMESPACE
|
---|