1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2008 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 | #include "qxsdschemacontext_p.h"
|
---|
43 |
|
---|
44 | #include "qderivedinteger_p.h"
|
---|
45 | #include "qderivedstring_p.h"
|
---|
46 | #include "qxsdschematypesfactory_p.h"
|
---|
47 |
|
---|
48 | QT_BEGIN_NAMESPACE
|
---|
49 |
|
---|
50 | using namespace QPatternist;
|
---|
51 |
|
---|
52 | XsdSchemaContext::XsdSchemaContext(const NamePool::Ptr &namePool)
|
---|
53 | : m_namePool(namePool)
|
---|
54 | , m_networkAccessManager(0)
|
---|
55 | , m_uriResolver(0)
|
---|
56 | , m_messageHandler(0)
|
---|
57 | {
|
---|
58 | }
|
---|
59 |
|
---|
60 | NamePool::Ptr XsdSchemaContext::namePool() const
|
---|
61 | {
|
---|
62 | return m_namePool;
|
---|
63 | }
|
---|
64 |
|
---|
65 | QUrl XsdSchemaContext::baseURI() const
|
---|
66 | {
|
---|
67 | return m_baseURI;
|
---|
68 | }
|
---|
69 |
|
---|
70 | void XsdSchemaContext::setBaseURI(const QUrl &uri)
|
---|
71 | {
|
---|
72 | m_baseURI = uri;
|
---|
73 | }
|
---|
74 |
|
---|
75 | void XsdSchemaContext::setNetworkAccessManager(QNetworkAccessManager *accessManager)
|
---|
76 | {
|
---|
77 | m_networkAccessManager = accessManager;
|
---|
78 | }
|
---|
79 |
|
---|
80 | QNetworkAccessManager* XsdSchemaContext::networkAccessManager() const
|
---|
81 | {
|
---|
82 | return m_networkAccessManager;
|
---|
83 | }
|
---|
84 |
|
---|
85 | void XsdSchemaContext::setMessageHandler(QAbstractMessageHandler *handler)
|
---|
86 | {
|
---|
87 | m_messageHandler = handler;
|
---|
88 | }
|
---|
89 |
|
---|
90 | QAbstractMessageHandler* XsdSchemaContext::messageHandler() const
|
---|
91 | {
|
---|
92 | return m_messageHandler;
|
---|
93 | }
|
---|
94 |
|
---|
95 | QSourceLocation XsdSchemaContext::locationFor(const SourceLocationReflection *const) const
|
---|
96 | {
|
---|
97 | return QSourceLocation();
|
---|
98 | }
|
---|
99 |
|
---|
100 | void XsdSchemaContext::setUriResolver(const QAbstractUriResolver *uriResolver)
|
---|
101 | {
|
---|
102 | m_uriResolver = uriResolver;
|
---|
103 | }
|
---|
104 |
|
---|
105 | const QAbstractUriResolver* XsdSchemaContext::uriResolver() const
|
---|
106 | {
|
---|
107 | return m_uriResolver;
|
---|
108 | }
|
---|
109 |
|
---|
110 | XsdFacet::Hash XsdSchemaContext::facetsForType(const AnySimpleType::Ptr &type) const
|
---|
111 | {
|
---|
112 | if (type->isDefinedBySchema())
|
---|
113 | return XsdSimpleType::Ptr(type)->facets();
|
---|
114 | else {
|
---|
115 | if (m_builtinTypesFacetList.isEmpty())
|
---|
116 | m_builtinTypesFacetList = setupBuiltinTypesFacetList();
|
---|
117 |
|
---|
118 | return m_builtinTypesFacetList.value(type);
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | SchemaTypeFactory::Ptr XsdSchemaContext::schemaTypeFactory() const
|
---|
123 | {
|
---|
124 | if (!m_schemaTypeFactory)
|
---|
125 | m_schemaTypeFactory = SchemaTypeFactory::Ptr(new XsdSchemaTypesFactory(m_namePool));
|
---|
126 |
|
---|
127 | return m_schemaTypeFactory;
|
---|
128 | }
|
---|
129 |
|
---|
130 | QHash<SchemaType::Ptr, XsdFacet::Hash> XsdSchemaContext::setupBuiltinTypesFacetList() const
|
---|
131 | {
|
---|
132 | QHash<SchemaType::Ptr, XsdFacet::Hash> hash;
|
---|
133 |
|
---|
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);
|
---|
138 |
|
---|
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);
|
---|
143 |
|
---|
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);
|
---|
148 |
|
---|
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);
|
---|
153 |
|
---|
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);
|
---|
158 |
|
---|
159 | {
|
---|
160 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsString];
|
---|
161 | facets.insert(preserveWhiteSpace->type(), preserveWhiteSpace);
|
---|
162 | }
|
---|
163 |
|
---|
164 | {
|
---|
165 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsBoolean];
|
---|
166 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
167 | }
|
---|
168 |
|
---|
169 | {
|
---|
170 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsDecimal];
|
---|
171 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
172 | }
|
---|
173 |
|
---|
174 | {
|
---|
175 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsFloat];
|
---|
176 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
177 | }
|
---|
178 |
|
---|
179 | {
|
---|
180 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsDouble];
|
---|
181 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
182 | }
|
---|
183 |
|
---|
184 | {
|
---|
185 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsDuration];
|
---|
186 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
187 | }
|
---|
188 |
|
---|
189 | {
|
---|
190 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsDateTime];
|
---|
191 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
192 | }
|
---|
193 |
|
---|
194 | {
|
---|
195 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsTime];
|
---|
196 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
197 | }
|
---|
198 |
|
---|
199 | {
|
---|
200 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsDate];
|
---|
201 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
202 | }
|
---|
203 |
|
---|
204 | {
|
---|
205 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsGYearMonth];
|
---|
206 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
207 | }
|
---|
208 |
|
---|
209 | {
|
---|
210 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsGYear];
|
---|
211 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
212 | }
|
---|
213 |
|
---|
214 | {
|
---|
215 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsGMonthDay];
|
---|
216 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
217 | }
|
---|
218 |
|
---|
219 | {
|
---|
220 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsGDay];
|
---|
221 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
222 | }
|
---|
223 |
|
---|
224 | {
|
---|
225 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsGMonth];
|
---|
226 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
227 | }
|
---|
228 |
|
---|
229 | {
|
---|
230 | XsdFacet::Hash &facets = hash[BuiltinTypes::xsHexBinary];
|
---|
231 | facets.insert(fixedCollapseWhiteSpace->type(), fixedCollapseWhiteSpace);
|
---|
232 | }
|
---|
233 |
|
---|
|
---|