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 "qxsdschema_p.h"
|
---|
43 |
|
---|
44 | #include <QtCore/QReadLocker>
|
---|
45 | #include <QtCore/QWriteLocker>
|
---|
46 |
|
---|
47 | QT_BEGIN_NAMESPACE
|
---|
48 |
|
---|
49 | using namespace QPatternist;
|
---|
50 |
|
---|
51 | XsdSchema::XsdSchema(const NamePool::Ptr &namePool)
|
---|
52 | : m_namePool(namePool)
|
---|
53 | {
|
---|
54 | }
|
---|
55 |
|
---|
56 | XsdSchema::~XsdSchema()
|
---|
57 | {
|
---|
58 | }
|
---|
59 |
|
---|
60 | NamePool::Ptr XsdSchema::namePool() const
|
---|
61 | {
|
---|
62 | return m_namePool;
|
---|
63 | }
|
---|
64 |
|
---|
65 | void XsdSchema::setTargetNamespace(const QString &targetNamespace)
|
---|
66 | {
|
---|
67 | m_targetNamespace = targetNamespace;
|
---|
68 | }
|
---|
69 |
|
---|
70 | QString XsdSchema::targetNamespace() const
|
---|
71 | {
|
---|
72 | return m_targetNamespace;
|
---|
73 | }
|
---|
74 |
|
---|
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 |
|
---|
82 | XsdElement::Ptr XsdSchema::element(const QXmlName &name) const
|
---|
83 | {
|
---|
84 | const QReadLocker locker(&m_lock);
|
---|
85 |
|
---|
86 | return m_elements.value(name);
|
---|
87 | }
|
---|
88 |
|
---|
89 | XsdElement::List XsdSchema::elements() const
|
---|
90 | {
|
---|
91 | const QReadLocker locker(&m_lock);
|
---|
92 |
|
---|
93 | return m_elements.values();
|
---|
94 | }
|
---|
95 |
|
---|
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 |
|
---|
103 | XsdAttribute::Ptr XsdSchema::attribute(const QXmlName &name) const
|
---|
104 | {
|
---|
105 | const QReadLocker locker(&m_lock);
|
---|
106 |
|
---|
107 | return m_attributes.value(name);
|
---|
108 | }
|
---|
109 |
|
---|
110 | XsdAttribute::List XsdSchema::attributes() const
|
---|
111 | {
|
---|
112 | const QReadLocker locker(&m_lock);
|
---|
113 |
|
---|
114 | return m_attributes.values();
|
---|
115 | }
|
---|
116 |
|
---|
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 |
|
---|
124 | SchemaType::Ptr XsdSchema::type(const QXmlName &name) const
|
---|
125 | {
|
---|
126 | const QReadLocker locker(&m_lock);
|
---|
127 |
|
---|
128 | return m_types.value(name);
|
---|
129 | }
|
---|
130 |
|
---|
131 | SchemaType::List XsdSchema::types() const
|
---|
132 | {
|
---|
133 | const QReadLocker locker(&m_lock);
|
---|
134 |
|
---|
135 | return m_types.values();
|
---|
136 | }
|
---|
137 |
|
---|
138 | 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 |
|
---|
153 | 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 |
|
---|
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 |
|
---|
181 | SchemaType::List XsdSchema::anonymousTypes() const
|
---|
182 | {
|
---|
183 | const QReadLocker locker(&m_lock);
|
---|
184 |
|
---|
185 | return m_anonymousTypes.values();
|
---|
186 | }
|
---|
187 |
|
---|
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 |
|
---|
195 | XsdAttributeGroup::Ptr XsdSchema::attributeGroup(const QXmlName name) const
|
---|
196 | {
|
---|
197 | const QReadLocker locker(&m_lock);
|
---|
198 |
|
---|
199 | return m_attributeGroups.value(name);
|
---|
200 | }
|
---|
201 |
|
---|
202 | XsdAttributeGroup::List XsdSchema::attributeGroups() const
|
---|
203 | {
|
---|
204 | const QReadLocker locker(&m_lock);
|
---|
205 |
|
---|
206 | return m_attributeGroups.values();
|
---|
207 | }
|
---|
208 |
|
---|
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 |
|
---|
216 | XsdModelGroup::Ptr XsdSchema::elementGroup(const QXmlName &name) const
|
---|
217 | {
|
---|
218 | const QReadLocker locker(&m_lock);
|
---|
219 |
|
---|
220 | return m_elementGroups.value(name);
|
---|
221 | }
|
---|
222 |
|
---|
223 | XsdModelGroup::List XsdSchema::elementGroups() const
|
---|
224 | {
|
---|
225 | const QReadLocker locker(&m_lock);
|
---|
226 |
|
---|
227 | return m_elementGroups.values();
|
---|
228 | }
|
---|
229 |
|
---|
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 |
|
---|
237 | XsdNotation::Ptr XsdSchema::notation(const QXmlName &name) const
|
---|
238 | {
|
---|
239 | const QReadLocker locker(&m_lock);
|
---|
240 |
|
---|
241 | return m_notations.value(name);
|
---|
242 | }
|
---|
243 |
|
---|
244 | XsdNotation::List XsdSchema::notations() const
|
---|
245 | {
|
---|
246 | const QReadLocker locker(&m_lock);
|
---|
247 |
|
---|
248 | return m_notations.values();
|
---|
249 | }
|
---|
250 |
|
---|
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 |
|
---|
258 | XsdIdentityConstraint::Ptr XsdSchema::identityConstraint(const QXmlName &name) const
|
---|
259 | {
|
---|
260 | const QReadLocker locker(&m_lock);
|
---|
261 |
|
---|
262 | return m_identityConstraints.value(name);
|
---|
263 | }
|
---|
264 |
|
---|
265 | XsdIdentityConstraint::List XsdSchema::identityConstraints() const
|
---|
266 | {
|
---|
267 | const QReadLocker locker(&m_lock);
|
---|
268 |
|
---|
269 | return m_identityConstraints.values();
|
---|
270 | }
|
---|
271 |
|
---|
272 | QT_END_NAMESPACE
|
---|