source: trunk/src/xmlpatterns/environment/qgenericstaticcontext.cpp

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 11.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
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**
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.
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 have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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
51QT_BEGIN_NAMESPACE
52
53using namespace QPatternist;
54
55GenericStaticContext::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
87NamespaceResolver::Ptr GenericStaticContext::namespaceBindings() const
88{
89 return m_namespaceResolver;
90}
91
92FunctionFactory::Ptr GenericStaticContext::functionSignatures() const
93{
94 return m_functionFactory;
95}
96
97DynamicContext::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
105SchemaTypeFactory::Ptr GenericStaticContext::schemaDefinitions() const
106{
107 return BasicTypesFactory::self(m_namePool);
108}
109
110QUrl 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
117void GenericStaticContext::setBaseURI(const QUrl &uri)
118{
119 Q_ASSERT(!uri.isRelative());
120 m_baseURI = uri;
121}
122
123bool GenericStaticContext::compatModeEnabled() const
124{
125 return m_compatModeEnabled;
126}
127
128void GenericStaticContext::setCompatModeEnabled(const bool newVal)
129{
130 m_compatModeEnabled = newVal;
131}
132
133QUrl GenericStaticContext::defaultCollation() const
134{
135 return m_defaultCollation;
136}
137
138QAbstractMessageHandler * GenericStaticContext::messageHandler() const
139{
140 return m_messageHandler;
141}
142
143void GenericStaticContext::setDefaultCollation(const QUrl &uri)
144{
145 m_defaultCollation = uri;
146}
147
148void GenericStaticContext::setNamespaceBindings(const NamespaceResolver::Ptr &resolver)
149{
150 Q_ASSERT(resolver);
151 m_namespaceResolver = resolver;
152}
153
154StaticContext::BoundarySpacePolicy GenericStaticContext::boundarySpacePolicy() const
155{
156 return m_boundarySpacePolicy;
157}
158
159void GenericStaticContext::setBoundarySpacePolicy(const BoundarySpacePolicy policy)
160{
161 Q_ASSERT(policy == BSPPreserve || policy == BSPStrip);
162 m_boundarySpacePolicy = policy;
163}
164
165StaticContext::ConstructionMode GenericStaticContext::constructionMode() const
166{
167 return m_constructionMode;
168}
169
170void GenericStaticContext::setConstructionMode(const ConstructionMode mode)
171{
172 Q_ASSERT(mode == CMPreserve || mode == CMStrip);
173 m_constructionMode = mode;
174}
175
176StaticContext::OrderingMode GenericStaticContext::orderingMode() const
177{
178 return m_orderingMode;
179}
180
181void GenericStaticContext::setOrderingMode(const OrderingMode mode)
182{
183 Q_ASSERT(mode == Ordered || mode == Unordered);
184 m_orderingMode = mode;
185}
186
187StaticContext::OrderingEmptySequence GenericStaticContext::orderingEmptySequence() const
188{
189 return m_orderingEmptySequence;
190}
191
192void GenericStaticContext::setOrderingEmptySequence(const OrderingEmptySequence ordering)
193{
194 Q_ASSERT(ordering == Greatest || ordering == Least);
195 m_orderingEmptySequence = ordering;
196}
197
198QString GenericStaticContext::defaultFunctionNamespace() const
199{
200 return m_defaultFunctionNamespace;
201}
202
203void GenericStaticContext::setDefaultFunctionNamespace(const QString &ns)
204{
205 m_defaultFunctionNamespace = ns;
206}
207
208
209QString GenericStaticContext::defaultElementNamespace() const
210{
211 return m_defaultElementNamespace;
212}
213
214void GenericStaticContext::setDefaultElementNamespace(const QString &ns)
215{
216 m_defaultElementNamespace = ns;
217}
218
219StaticContext::InheritMode GenericStaticContext::inheritMode() const
220{
221 return m_inheritMode;
222}
223
224void GenericStaticContext::setInheritMode(const InheritMode mode)
225{
226 Q_ASSERT(mode == Inherit || mode == NoInherit);
227 m_inheritMode = mode;
228}
229
230StaticContext::PreserveMode GenericStaticContext::preserveMode() const
231{
232 return m_preserveMode;
233}
234
235void GenericStaticContext::setPreserveMode(const PreserveMode mode)
236{
237 Q_ASSERT(mode == Preserve || mode == NoPreserve);
238 m_preserveMode = mode;
239}
240
241ItemType::Ptr GenericStaticContext::contextItemType() const
242{
243 return m_contextItemType;
244}
245
246ItemType::Ptr GenericStaticContext::currentItemType() const
247{
248 return contextItemType();
249}
250
251void GenericStaticContext::setContextItemType(const ItemType::Ptr &type)
252{
253 m_contextItemType = type;
254}
255
256StaticContext::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
278ResourceLoader::Ptr GenericStaticContext::resourceLoader() const
279{
280 return m_resourceLoader;
281}
282
283void GenericStaticContext::setResourceLoader(const ResourceLoader::Ptr &loader)
284{
285 m_resourceLoader = loader;
286}
287
288ExternalVariableLoader::Ptr GenericStaticContext::externalVariableLoader() const
289{
290 return m_externalVariableLoader;
291}
292
293void GenericStaticContext::setExternalVariableLoader(const ExternalVariableLoader::Ptr &loader)
294{
295 m_externalVariableLoader = loader;
296}
297
298NamePool::Ptr GenericStaticContext::namePool() const
299{
300 return m_namePool;
301}
302
303void 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
312StaticContext::LocationHash GenericStaticContext::sourceLocations() const
313{
314 return m_locations;
315}
316
317QSourceLocation GenericStaticContext::locationFor(const SourceLocationReflection *const reflection) const
318{
319 return m_locations.value(reflection->actualReflection());
320}
321
322QAbstractUriResolver *GenericStaticContext::uriResolver() const
323{
324 return m_uriResolver;
325}
326
327VariableSlotID GenericStaticContext::currentRangeSlot() const
328{
329 return m_rangeSlot;
330}
331
332VariableSlotID GenericStaticContext::allocateRangeSlot()
333{
334 ++m_rangeSlot;
335 return m_rangeSlot;
336}
337
338QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.