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