Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
[qt-netbsd.git] / src / xmlpatterns / schema / qxsdschemacontext.cpp
blob8e226325e762aeef117a8b1b5402ea0b2dc3a80b
1 /****************************************************************************
2 **
3 ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #include "qxsdschemacontext_p.h"
44 #include "qderivedinteger_p.h"
45 #include "qderivedstring_p.h"
46 #include "qxsdschematypesfactory_p.h"
48 QT_BEGIN_NAMESPACE
50 using namespace QPatternist;
52 XsdSchemaContext::XsdSchemaContext(const NamePool::Ptr &namePool)
53 : m_namePool(namePool)
54 , m_networkAccessManager(0)
55 , m_uriResolver(0)
56 , m_messageHandler(0)
60 NamePool::Ptr XsdSchemaContext::namePool() const
62 return m_namePool;
65 QUrl XsdSchemaContext::baseURI() const
67 return m_baseURI;
70 void XsdSchemaContext::setBaseURI(const QUrl &uri)
72 m_baseURI = uri;
75 void XsdSchemaContext::setNetworkAccessManager(QNetworkAccessManager *accessManager)
77 m_networkAccessManager = accessManager;
80 QNetworkAccessManager* XsdSchemaContext::networkAccessManager() const
82 return m_networkAccessManager;
85 void XsdSchemaContext::setMessageHandler(QAbstractMessageHandler *handler)
87 m_messageHandler = handler;
90 QAbstractMessageHandler* XsdSchemaContext::messageHandler() const
92 return m_messageHandler;
95 QSourceLocation XsdSchemaContext::locationFor(const SourceLocationReflection *const) const
97 return QSourceLocation();
100 void XsdSchemaContext::setUriResolver(const QAbstractUriResolver *uriResolver)
102 m_uriResolver = uriResolver;
105 const QAbstractUriResolver* XsdSchemaContext::uriResolver() const
107 return m_uriResolver;
110 XsdFacet::Hash XsdSchemaContext::facetsForType(const AnySimpleType::Ptr &type) const
112 if (type->isDefinedBySchema())
113 return XsdSimpleType::Ptr(type)->facets();
114 else {
115 if (m_builtinTypesFacetList.isEmpty())
116 m_builtinTypesFacetList = setupBuiltinTypesFacetList();
118 return m_builtinTypesFacetList.value(type);
122 SchemaTypeFactory::Ptr XsdSchemaContext::schemaTypeFactory() const
124 if (!m_schemaTypeFactory)
125 m_schemaTypeFactory = SchemaTypeFactory::Ptr(new XsdSchemaTypesFactory(m_namePool));
127 return m_schemaTypeFactory;
130 QHash<SchemaType::Ptr, XsdFacet::Hash> XsdSchemaContext::setupBuiltinTypesFacetList() const
132 QHash<SchemaType::Ptr, XsdFacet::Hash> hash;
134 const XsdFacet::Ptr fixedCollapseWhiteSpace(new XsdFacet());
135 fixedCollapseWhiteSpace->setType(XsdFacet::WhiteSpace);
136 fixedCollapseWhiteSpace->setValue(DerivedString<TypeString>::fromLexical(m_namePool, XsdSchemaToken::toString(XsdSchemaToken::Collapse)));
137 fixedCollapseWhiteSpace->setFixed(true);
139 const XsdFacet::Ptr collapseWhiteSpace(new XsdFacet());
140 collapseWhiteSpace->setType(XsdFacet::WhiteSpace);
141 collapseWhiteSpace->setValue(DerivedString<TypeString>::fromLexical(m_namePool, XsdSchemaToken::toString(XsdSchemaToken::Collapse)));
142 collapseWhiteSpace->setFixed(false);
144 const XsdFacet::Ptr preserveWhiteSpace(new XsdFacet());
145 preserveWhiteSpace->setType(XsdFacet::WhiteSpace);
146 preserveWhiteSpace->setValue(DerivedString<TypeString>::fromLexical(m_namePool, XsdSchemaToken::toString(XsdSchemaToken::Preserve)));
147 preserveWhiteSpace->setFixed(false);
149 const XsdFacet::Ptr replaceWhiteSpace(new XsdFacet());
150 replaceWhiteSpace->setType(XsdFacet::WhiteSpace);
151 replaceWhiteSpace->setValue(DerivedString<TypeString>::fromLexical(m_namePool, XsdSchemaToken::toString(XsdSchemaToken::Replace)));
152 replaceWhiteSpace->setFixed(false);
154 const XsdFacet::Ptr fixedZeroFractionDigits(new XsdFacet());
155 fixedZeroFractionDigits->setType(XsdFacet::FractionDigits);
156 fixedZeroFractionDigits->setValue(DerivedInteger<TypeNonNegativeInteger>::fromValue(m_namePool, 0));
157 fixedZeroFractionDigits->setFixed(true);
160 XsdFacet::Hash &facets = hash[BuiltinTypes::xsString];
161 facets.insert(preserveWhiteSpace->type(), preserveWhiteSpace);
165 XsdFacet::Hash &facets = hash[BuiltinTypes::xsBoolean];
166 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
170 XsdFacet::Hash &facets = hash[BuiltinTypes::xsDecimal];
171 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
175 XsdFacet::Hash &facets = hash[BuiltinTypes::xsFloat];
176 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
180 XsdFacet::Hash &facets = hash[BuiltinTypes::xsDouble];
181 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
185 XsdFacet::Hash &facets = hash[BuiltinTypes::xsDuration];
186 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
190 XsdFacet::Hash &facets = hash[BuiltinTypes::xsDateTime];
191 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
195 XsdFacet::Hash &facets = hash[BuiltinTypes::xsTime];
196 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
200 XsdFacet::Hash &facets = hash[BuiltinTypes::xsDate];
201 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
205 XsdFacet::Hash &facets = hash[BuiltinTypes::xsGYearMonth];
206 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
210 XsdFacet::Hash &facets = hash[BuiltinTypes::xsGYear];
211 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
215 XsdFacet::Hash &facets = hash[BuiltinTypes::xsGMonthDay];
216 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
220 XsdFacet::Hash &facets = hash[BuiltinTypes::xsGDay];
221 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
225 XsdFacet::Hash &facets = hash[BuiltinTypes::xsGMonth];
226 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
230 XsdFacet::Hash &facets = hash[BuiltinTypes::xsHexBinary];
231 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
235 XsdFacet::Hash &facets = hash[BuiltinTypes::xsBase64Binary];
236 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
240 XsdFacet::Hash &facets = hash[BuiltinTypes::xsAnyURI];
241 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
245 XsdFacet::Hash &facets = hash[BuiltinTypes::xsQName];
246 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
250 XsdFacet::Hash &facets = hash[BuiltinTypes::xsNOTATION];
251 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
255 XsdFacet::Hash &facets = hash[BuiltinTypes::xsNormalizedString];
256 facets.insert(replaceWhiteSpace->type(), replaceWhiteSpace);
260 XsdFacet::Hash &facets = hash[BuiltinTypes::xsToken];
261 facets.insert(collapseWhiteSpace->type(), collapseWhiteSpace);
265 XsdFacet::Hash &facets = hash[BuiltinTypes::xsLanguage];
266 facets.insert(collapseWhiteSpace->type(), collapseWhiteSpace);
268 const XsdFacet::Ptr pattern(new XsdFacet());
269 pattern->setType(XsdFacet::Pattern);
270 pattern->setMultiValue(AtomicValue::List() << DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*")));
271 facets.insert(pattern->type(), pattern);
275 XsdFacet::Hash &facets = hash[BuiltinTypes::xsNMTOKEN];
276 facets.insert(collapseWhiteSpace->type(), collapseWhiteSpace);
278 const XsdFacet::Ptr pattern(new XsdFacet());
279 pattern->setType(XsdFacet::Pattern);
280 pattern->setMultiValue(AtomicValue::List() << DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("\\c+")));
281 facets.insert(pattern->type(), pattern);
285 XsdFacet::Hash &facets = hash[BuiltinTypes::xsName];
286 facets.insert(collapseWhiteSpace->type(), collapseWhiteSpace);
288 const XsdFacet::Ptr pattern(new XsdFacet());
289 pattern->setType(XsdFacet::Pattern);
290 pattern->setMultiValue(AtomicValue::List() << DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("\\i\\c*")));
291 facets.insert(pattern->type(), pattern);
294 const XsdFacet::Ptr ncNamePattern(new XsdFacet());
296 ncNamePattern->setType(XsdFacet::Pattern);
297 AtomicValue::List patterns;
298 patterns << DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("\\i\\c*"));
299 patterns << DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("[\\i-[:]][\\c-[:]]*"));
300 ncNamePattern->setMultiValue(patterns);
304 XsdFacet::Hash &facets = hash[BuiltinTypes::xsNCName];
305 facets.insert(collapseWhiteSpace->type(), collapseWhiteSpace);
306 facets.insert(ncNamePattern->type(), ncNamePattern);
310 XsdFacet::Hash &facets = hash[BuiltinTypes::xsID];
311 facets.insert(collapseWhiteSpace->type(), collapseWhiteSpace);
312 facets.insert(ncNamePattern->type(), ncNamePattern);
316 XsdFacet::Hash &facets = hash[BuiltinTypes::xsIDREF];
317 facets.insert(collapseWhiteSpace->type(), collapseWhiteSpace);
318 facets.insert(ncNamePattern->type(), ncNamePattern);
322 XsdFacet::Hash &facets = hash[BuiltinTypes::xsENTITY];
323 facets.insert(collapseWhiteSpace->type(), collapseWhiteSpace);
324 facets.insert(ncNamePattern->type(), ncNamePattern);
327 const XsdFacet::Ptr integerPattern(new XsdFacet());
328 integerPattern->setType(XsdFacet::Pattern);
329 integerPattern->setMultiValue(AtomicValue::List() << DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("[\\-+]?[0-9]+")));
332 XsdFacet::Hash &facets = hash[BuiltinTypes::xsInteger];
333 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
334 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
335 facets.insert(integerPattern->type(), integerPattern);
339 XsdFacet::Hash &facets = hash[BuiltinTypes::xsNonPositiveInteger];
340 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
341 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
342 facets.insert(integerPattern->type(), integerPattern);
344 const XsdFacet::Ptr maxInclusive(new XsdFacet());
345 maxInclusive->setType(XsdFacet::MaximumInclusive);
346 maxInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("0")));
347 facets.insert(maxInclusive->type(), maxInclusive);
351 XsdFacet::Hash &facets = hash[BuiltinTypes::xsNegativeInteger];
352 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
353 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
354 facets.insert(integerPattern->type(), integerPattern);
356 const XsdFacet::Ptr maxInclusive(new XsdFacet());
357 maxInclusive->setType(XsdFacet::MaximumInclusive);
358 maxInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("-1")));
359 facets.insert(maxInclusive->type(), maxInclusive);
363 XsdFacet::Hash &facets = hash[BuiltinTypes::xsLong];
364 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
365 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
366 facets.insert(integerPattern->type(), integerPattern);
368 const XsdFacet::Ptr maxInclusive(new XsdFacet());
369 maxInclusive->setType(XsdFacet::MaximumInclusive);
370 maxInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("9223372036854775807")));
371 facets.insert(maxInclusive->type(), maxInclusive);
373 const XsdFacet::Ptr minInclusive(new XsdFacet());
374 minInclusive->setType(XsdFacet::MinimumInclusive);
375 minInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("-9223372036854775808")));
376 facets.insert(minInclusive->type(), minInclusive);
380 XsdFacet::Hash &facets = hash[BuiltinTypes::xsInt];
381 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
382 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
383 facets.insert(integerPattern->type(), integerPattern);
385 const XsdFacet::Ptr maxInclusive(new XsdFacet());
386 maxInclusive->setType(XsdFacet::MaximumInclusive);
387 maxInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("2147483647")));
388 facets.insert(maxInclusive->type(), maxInclusive);
390 const XsdFacet::Ptr minInclusive(new XsdFacet());
391 minInclusive->setType(XsdFacet::MinimumInclusive);
392 minInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("-2147483648")));
393 facets.insert(minInclusive->type(), minInclusive);
397 XsdFacet::Hash &facets = hash[BuiltinTypes::xsShort];
398 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
399 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
400 facets.insert(integerPattern->type(), integerPattern);
402 const XsdFacet::Ptr maxInclusive(new XsdFacet());
403 maxInclusive->setType(XsdFacet::MaximumInclusive);
404 maxInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("32767")));
405 facets.insert(maxInclusive->type(), maxInclusive);
407 const XsdFacet::Ptr minInclusive(new XsdFacet());
408 minInclusive->setType(XsdFacet::MinimumInclusive);
409 minInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("-32768")));
410 facets.insert(minInclusive->type(), minInclusive);
414 XsdFacet::Hash &facets = hash[BuiltinTypes::xsByte];
415 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
416 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
417 facets.insert(integerPattern->type(), integerPattern);
419 const XsdFacet::Ptr maxInclusive(new XsdFacet());
420 maxInclusive->setType(XsdFacet::MaximumInclusive);
421 maxInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("127")));
422 facets.insert(maxInclusive->type(), maxInclusive);
424 const XsdFacet::Ptr minInclusive(new XsdFacet());
425 minInclusive->setType(XsdFacet::MinimumInclusive);
426 minInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("-128")));
427 facets.insert(minInclusive->type(), minInclusive);
430 const XsdFacet::Ptr unsignedMinInclusive(new XsdFacet());
431 unsignedMinInclusive->setType(XsdFacet::MinimumInclusive);
432 unsignedMinInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("0")));
435 XsdFacet::Hash &facets = hash[BuiltinTypes::xsNonNegativeInteger];
436 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
437 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
438 facets.insert(integerPattern->type(), integerPattern);
439 facets.insert(unsignedMinInclusive->type(), unsignedMinInclusive);
443 XsdFacet::Hash &facets = hash[BuiltinTypes::xsUnsignedLong];
444 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
445 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
446 facets.insert(integerPattern->type(), integerPattern);
447 facets.insert(unsignedMinInclusive->type(), unsignedMinInclusive);
449 const XsdFacet::Ptr maxInclusive(new XsdFacet());
450 maxInclusive->setType(XsdFacet::MaximumInclusive);
451 maxInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("18446744073709551615")));
452 facets.insert(maxInclusive->type(), maxInclusive);
456 XsdFacet::Hash &facets = hash[BuiltinTypes::xsUnsignedInt];
457 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
458 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
459 facets.insert(integerPattern->type(), integerPattern);
460 facets.insert(unsignedMinInclusive->type(), unsignedMinInclusive);
462 const XsdFacet::Ptr maxInclusive(new XsdFacet());
463 maxInclusive->setType(XsdFacet::MaximumInclusive);
464 maxInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("4294967295")));
465 facets.insert(maxInclusive->type(), maxInclusive);
469 XsdFacet::Hash &facets = hash[BuiltinTypes::xsUnsignedShort];
470 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
471 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
472 facets.insert(integerPattern->type(), integerPattern);
473 facets.insert(unsignedMinInclusive->type(), unsignedMinInclusive);
475 const XsdFacet::Ptr maxInclusive(new XsdFacet());
476 maxInclusive->setType(XsdFacet::MaximumInclusive);
477 maxInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("65535")));
478 facets.insert(maxInclusive->type(), maxInclusive);
482 XsdFacet::Hash &facets = hash[BuiltinTypes::xsUnsignedByte];
483 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
484 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
485 facets.insert(integerPattern->type(), integerPattern);
486 facets.insert(unsignedMinInclusive->type(), unsignedMinInclusive);
488 const XsdFacet::Ptr maxInclusive(new XsdFacet());
489 maxInclusive->setType(XsdFacet::MaximumInclusive);
490 maxInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("255")));
491 facets.insert(maxInclusive->type(), maxInclusive);
495 XsdFacet::Hash &facets = hash[BuiltinTypes::xsPositiveInteger];
496 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
497 facets.insert(fixedZeroFractionDigits->type(), fixedZeroFractionDigits);
499 const XsdFacet::Ptr minInclusive(new XsdFacet());
500 minInclusive->setType(XsdFacet::MinimumInclusive);
501 minInclusive->setValue(DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("1")));
502 facets.insert(minInclusive->type(), minInclusive);
506 XsdFacet::Hash &facets = hash[BuiltinTypes::xsYearMonthDuration];
507 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
509 const XsdFacet::Ptr pattern(new XsdFacet());
510 pattern->setType(XsdFacet::Pattern);
511 pattern->setMultiValue(AtomicValue::List() << DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("[^DT]*")));
512 facets.insert(pattern->type(), pattern);
516 XsdFacet::Hash &facets = hash[BuiltinTypes::xsDayTimeDuration];
517 facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
519 const XsdFacet::Ptr pattern(new XsdFacet());
520 pattern->setType(XsdFacet::Pattern);
521 pattern->setMultiValue(AtomicValue::List() << DerivedString<TypeString>::fromLexical(m_namePool, QString::fromLatin1("[^YM]*(T.*)?")));
522 facets.insert(pattern->type(), pattern);
525 return hash;
528 QT_END_NAMESPACE