1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qxsdschema_p.h"
43
44 #include <QtCore/QReadLocker>
45 #include <QtCore/QWriteLocker>
46
47 QT_BEGIN_NAMESPACE
48
49 using namespace QPatternist;
50
XsdSchema(const NamePool::Ptr & namePool)51 XsdSchema::XsdSchema(const NamePool::Ptr &namePool)
52 : m_namePool(namePool)
53 {
54 }
55
~XsdSchema()56 XsdSchema::~XsdSchema()
57 {
58 }
59
namePool() const60 NamePool::Ptr XsdSchema::namePool() const
61 {
62 return m_namePool;
63 }
64
setTargetNamespace(const QString & targetNamespace)65 void XsdSchema::setTargetNamespace(const QString &targetNamespace)
66 {
67 m_targetNamespace = targetNamespace;
68 }
69
targetNamespace() const70 QString XsdSchema::targetNamespace() const
71 {
72 return m_targetNamespace;
73 }
74
addElement(const XsdElement::Ptr & element)75 void XsdSchema::addElement(const XsdElement::Ptr &element)
76 {
77 const QWriteLocker locker(&m_lock);
78
79 m_elements.insert(element->name(m_namePool), element);
80 }
81
element(const QXmlName & name) const82 XsdElement::Ptr XsdSchema::element(const QXmlName &name) const
83 {
84 const QReadLocker locker(&m_lock);
85
86 return m_elements.value(name);
87 }
88
elements() const89 XsdElement::List XsdSchema::elements() const
90 {
91 const QReadLocker locker(&m_lock);
92
93 return m_elements.values();
94 }
95
addAttribute(const XsdAttribute::Ptr & attribute)96 void XsdSchema::addAttribute(const XsdAttribute::Ptr &attribute)
97 {
98 const QWriteLocker locker(&m_lock);
99
100 m_attributes.insert(attribute->name(m_namePool), attribute);
101 }
102
attribute(const QXmlName & name) const103 XsdAttribute::Ptr XsdSchema::attribute(const QXmlName &name) const
104 {
105 const QReadLocker locker(&m_lock);
106
107 return m_attributes.value(name);
108 }
109
attributes() const110 XsdAttribute::List XsdSchema::attributes() const
111 {
112 const QReadLocker locker(&m_lock);
113
114 return m_attributes.values();
115 }
116
addType(const SchemaType::Ptr & type)117 void XsdSchema::addType(const SchemaType::Ptr &type)
118 {
119 const QWriteLocker locker(&m_lock);
120
121 m_types.insert(type->name(m_namePool), type);
122 }
123
type(const QXmlName & name) const124 SchemaType::Ptr XsdSchema::type(const QXmlName &name) const
125 {
126 const QReadLocker locker(&m_lock);
127
128 return m_types.value(name);
129 }
130
types() const131 SchemaType::List XsdSchema::types() const
132 {
133 const QReadLocker locker(&m_lock);
134
135 return m_types.values();
136 }
137
simpleTypes() const138 XsdSimpleType::List XsdSchema::simpleTypes() const
139 {
140 QReadLocker locker(&m_lock);
141
142 XsdSimpleType::List retval;
143
144 const SchemaType::List types = m_types.values();
145 for (int i = 0; i < types.count(); ++i) {
146 if (types.at(i)->isSimpleType() && types.at(i)->isDefinedBySchema())
147 retval.append(types.at(i));
148 }
149
150 return retval;
151 }
152
complexTypes() const153 XsdComplexType::List XsdSchema::complexTypes() const
154 {
155 QReadLocker locker(&m_lock);
156
157 XsdComplexType::List retval;
158
159 const SchemaType::List types = m_types.values();
160 for (int i = 0; i < types.count(); ++i) {
161 if (types.at(i)->isComplexType() && types.at(i)->isDefinedBySchema())
162 retval.append(types.at(i));
163 }
164
165 return retval;
166 }
167
addAnonymousType(const SchemaType::Ptr & type)168 void XsdSchema::addAnonymousType(const SchemaType::Ptr &type)
169 {
170 const QWriteLocker locker(&m_lock);
171
172 // search for not used anonymous type name
173 QXmlName typeName = type->name(m_namePool);
174 while (m_anonymousTypes.contains(typeName)) {
175 typeName = m_namePool->allocateQName(QString(), QLatin1String("merged_") + m_namePool->stringForLocalName(typeName.localName()), QString());
176 }
177
178 m_anonymousTypes.insert(typeName, type);
179 }
180
anonymousTypes() const181 SchemaType::List XsdSchema::anonymousTypes() const
182 {
183 const QReadLocker locker(&m_lock);
184
185 return m_anonymousTypes.values();
186 }
187
addAttributeGroup(const XsdAttributeGroup::Ptr & group)188 void XsdSchema::addAttributeGroup(const XsdAttributeGroup::Ptr &group)
189 {
190 const QWriteLocker locker(&m_lock);
191
192 m_attributeGroups.insert(group->name(m_namePool), group);
193 }
194
attributeGroup(const QXmlName name) const195 XsdAttributeGroup::Ptr XsdSchema::attributeGroup(const QXmlName name) const
196 {
197 const QReadLocker locker(&m_lock);
198
199 return m_attributeGroups.value(name);
200 }
201
attributeGroups() const202 XsdAttributeGroup::List XsdSchema::attributeGroups() const
203 {
204 const QReadLocker locker(&m_lock);
205
206 return m_attributeGroups.values();
207 }
208
addElementGroup(const XsdModelGroup::Ptr & group)209 void XsdSchema::addElementGroup(const XsdModelGroup::Ptr &group)
210 {
211 const QWriteLocker locker(&m_lock);
212
213 m_elementGroups.insert(group->name(m_namePool), group);
214 }
215
elementGroup(const QXmlName & name) const216 XsdModelGroup::Ptr XsdSchema::elementGroup(const QXmlName &name) const
217 {
218 const QReadLocker locker(&m_lock);
219
220 return m_elementGroups.value(name);
221 }
222
elementGroups() const223 XsdModelGroup::List XsdSchema::elementGroups() const
224 {
225 const QReadLocker locker(&m_lock);
226
227 return m_elementGroups.values();
228 }
229
addNotation(const XsdNotation::Ptr & notation)230 void XsdSchema::addNotation(const XsdNotation::Ptr ¬ation)
231 {
232 const QWriteLocker locker(&m_lock);
233
234 m_notations.insert(notation->name(m_namePool), notation);
235 }
236
notation(const QXmlName & name) const237 XsdNotation::Ptr XsdSchema::notation(const QXmlName &name) const
238 {
239 const QReadLocker locker(&m_lock);
240
241 return m_notations.value(name);
242 }
243
notations() const244 XsdNotation::List XsdSchema::notations() const
245 {
246 const QReadLocker locker(&m_lock);
247
248 return m_notations.values();
249 }
250
addIdentityConstraint(const XsdIdentityConstraint::Ptr & constraint)251 void XsdSchema::addIdentityConstraint(const XsdIdentityConstraint::Ptr &constraint)
252 {
253 const QWriteLocker locker(&m_lock);
254
255 m_identityConstraints.insert(constraint->name(m_namePool), constraint);
256 }
257
identityConstraint(const QXmlName & name) const258 XsdIdentityConstraint::Ptr XsdSchema::identityConstraint(const QXmlName &name) const
259 {
260 const QReadLocker locker(&m_lock);
261
262 return m_identityConstraints.value(name);
263 }
264
identityConstraints() const265 XsdIdentityConstraint::List XsdSchema::identityConstraints() const
266 {
267 const QReadLocker locker(&m_lock);
268
269 return m_identityConstraints.values();
270 }
271
272 QT_END_NAMESPACE
273