1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://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 https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qxsdschema_p.h"
41
42#include <QtCore/QReadLocker>
43#include <QtCore/QWriteLocker>
44
45QT_BEGIN_NAMESPACE
46
47using namespace QPatternist;
48
49XsdSchema::XsdSchema(const NamePool::Ptr &namePool)
50 : m_namePool(namePool)
51{
52}
53
54XsdSchema::~XsdSchema()
55{
56}
57
58NamePool::Ptr XsdSchema::namePool() const
59{
60 return m_namePool;
61}
62
63void XsdSchema::setTargetNamespace(const QString &targetNamespace)
64{
65 m_targetNamespace = targetNamespace;
66}
67
68QString XsdSchema::targetNamespace() const
69{
70 return m_targetNamespace;
71}
72
73void XsdSchema::addElement(const XsdElement::Ptr &element)
74{
75 const QWriteLocker locker(&m_lock);
76
77 m_elements.insert(akey: element->name(namePool: m_namePool), avalue: element);
78}
79
80XsdElement::Ptr XsdSchema::element(const QXmlName &name) const
81{
82 const QReadLocker locker(&m_lock);
83
84 return m_elements.value(akey: name);
85}
86
87XsdElement::List XsdSchema::elements() const
88{
89 const QReadLocker locker(&m_lock);
90
91 return m_elements.values();
92}
93
94void XsdSchema::addAttribute(const XsdAttribute::Ptr &attribute)
95{
96 const QWriteLocker locker(&m_lock);
97
98 m_attributes.insert(akey: attribute->name(namePool: m_namePool), avalue: attribute);
99}
100
101XsdAttribute::Ptr XsdSchema::attribute(const QXmlName &name) const
102{
103 const QReadLocker locker(&m_lock);
104
105 return m_attributes.value(akey: name);
106}
107
108XsdAttribute::List XsdSchema::attributes() const
109{
110 const QReadLocker locker(&m_lock);
111
112 return m_attributes.values();
113}
114
115void XsdSchema::addType(const SchemaType::Ptr &type)
116{
117 const QWriteLocker locker(&m_lock);
118
119 m_types.insert(akey: type->name(np: m_namePool), avalue: type);
120}
121
122SchemaType::Ptr XsdSchema::type(const QXmlName &name) const
123{
124 const QReadLocker locker(&m_lock);
125
126 return m_types.value(akey: name);
127}
128
129SchemaType::List XsdSchema::types() const
130{
131 const QReadLocker locker(&m_lock);
132
133 return m_types.values();
134}
135
136XsdSimpleType::List XsdSchema::simpleTypes() const
137{
138 QReadLocker locker(&m_lock);
139
140 XsdSimpleType::List retval;
141
142 const SchemaType::List types = m_types.values();
143 for (int i = 0; i < types.count(); ++i) {
144 if (types.at(i)->isSimpleType() && types.at(i)->isDefinedBySchema())
145 retval.append(t: types.at(i));
146 }
147
148 return retval;
149}
150
151XsdComplexType::List XsdSchema::complexTypes() const
152{
153 QReadLocker locker(&m_lock);
154
155 XsdComplexType::List retval;
156
157 const SchemaType::List types = m_types.values();
158 for (int i = 0; i < types.count(); ++i) {
159 if (types.at(i)->isComplexType() && types.at(i)->isDefinedBySchema())
160 retval.append(t: types.at(i));
161 }
162
163 return retval;
164}
165
166void XsdSchema::addAnonymousType(const SchemaType::Ptr &type)
167{
168 const QWriteLocker locker(&m_lock);
169
170 // search for not used anonymous type name
171 QXmlName typeName = type->name(np: m_namePool);
172 while (m_anonymousTypes.contains(akey: typeName)) {
173 typeName = m_namePool->allocateQName(uri: QString(), localName: QLatin1String("merged_") + m_namePool->stringForLocalName(code: typeName.localName()), prefix: QString());
174 }
175
176 m_anonymousTypes.insert(akey: typeName, avalue: type);
177}
178
179SchemaType::List XsdSchema::anonymousTypes() const
180{
181 const QReadLocker locker(&m_lock);
182
183 return m_anonymousTypes.values();
184}
185
186void XsdSchema::addAttributeGroup(const XsdAttributeGroup::Ptr &group)
187{
188 const QWriteLocker locker(&m_lock);
189
190 m_attributeGroups.insert(akey: group->name(namePool: m_namePool), avalue: group);
191}
192
193XsdAttributeGroup::Ptr XsdSchema::attributeGroup(const QXmlName name) const
194{
195 const QReadLocker locker(&m_lock);
196
197 return m_attributeGroups.value(akey: name);
198}
199
200XsdAttributeGroup::List XsdSchema::attributeGroups() const
201{
202 const QReadLocker locker(&m_lock);
203
204 return m_attributeGroups.values();
205}
206
207void XsdSchema::addElementGroup(const XsdModelGroup::Ptr &group)
208{
209 const QWriteLocker locker(&m_lock);
210
211 m_elementGroups.insert(akey: group->name(namePool: m_namePool), avalue: group);
212}
213
214XsdModelGroup::Ptr XsdSchema::elementGroup(const QXmlName &name) const
215{
216 const QReadLocker locker(&m_lock);
217
218 return m_elementGroups.value(akey: name);
219}
220
221XsdModelGroup::List XsdSchema::elementGroups() const
222{
223 const QReadLocker locker(&m_lock);
224
225 return m_elementGroups.values();
226}
227
228void XsdSchema::addNotation(const XsdNotation::Ptr &notation)
229{
230 const QWriteLocker locker(&m_lock);
231
232 m_notations.insert(akey: notation->name(namePool: m_namePool), avalue: notation);
233}
234
235XsdNotation::Ptr XsdSchema::notation(const QXmlName &name) const
236{
237 const QReadLocker locker(&m_lock);
238
239 return m_notations.value(akey: name);
240}
241
242XsdNotation::List XsdSchema::notations() const
243{
244 const QReadLocker locker(&m_lock);
245
246 return m_notations.values();
247}
248
249void XsdSchema::addIdentityConstraint(const XsdIdentityConstraint::Ptr &constraint)
250{
251 const QWriteLocker locker(&m_lock);
252
253 m_identityConstraints.insert(akey: constraint->name(namePool: m_namePool), avalue: constraint);
254}
255
256XsdIdentityConstraint::Ptr XsdSchema::identityConstraint(const QXmlName &name) const
257{
258 const QReadLocker locker(&m_lock);
259
260 return m_identityConstraints.value(akey: name);
261}
262
263XsdIdentityConstraint::List XsdSchema::identityConstraints() const
264{
265 const QReadLocker locker(&m_lock);
266
267 return m_identityConstraints.values();
268}
269
270QT_END_NAMESPACE
271

source code of qtxmlpatterns/src/xmlpatterns/schema/qxsdschema.cpp