1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qxsdschema_p.h"
44 #include <QtCore/QReadLocker>
45 #include <QtCore/QWriteLocker>
49 using namespace QPatternist;
51 XsdSchema::XsdSchema(const NamePool::Ptr &namePool)
52 : m_namePool(namePool)
56 XsdSchema::~XsdSchema()
60 NamePool::Ptr XsdSchema::namePool() const
65 void XsdSchema::setTargetNamespace(const QString &targetNamespace)
67 m_targetNamespace = targetNamespace;
70 QString XsdSchema::targetNamespace() const
72 return m_targetNamespace;
75 void XsdSchema::addElement(const XsdElement::Ptr &element)
77 const QWriteLocker locker(&m_lock);
79 m_elements.insert(element->name(m_namePool), element);
82 XsdElement::Ptr XsdSchema::element(const QXmlName &name) const
84 const QReadLocker locker(&m_lock);
86 return m_elements.value(name);
89 XsdElement::List XsdSchema::elements() const
91 const QReadLocker locker(&m_lock);
93 return m_elements.values();
96 void XsdSchema::addAttribute(const XsdAttribute::Ptr &attribute)
98 const QWriteLocker locker(&m_lock);
100 m_attributes.insert(attribute->name(m_namePool), attribute);
103 XsdAttribute::Ptr XsdSchema::attribute(const QXmlName &name) const
105 const QReadLocker locker(&m_lock);
107 return m_attributes.value(name);
110 XsdAttribute::List XsdSchema::attributes() const
112 const QReadLocker locker(&m_lock);
114 return m_attributes.values();
117 void XsdSchema::addType(const SchemaType::Ptr &type)
119 const QWriteLocker locker(&m_lock);
121 m_types.insert(type->name(m_namePool), type);
124 SchemaType::Ptr XsdSchema::type(const QXmlName &name) const
126 const QReadLocker locker(&m_lock);
128 return m_types.value(name);
131 SchemaType::List XsdSchema::types() const
133 const QReadLocker locker(&m_lock);
135 return m_types.values();
138 XsdSimpleType::List XsdSchema::simpleTypes() const
140 QReadLocker locker(&m_lock);
142 XsdSimpleType::List retval;
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));
153 XsdComplexType::List XsdSchema::complexTypes() const
155 QReadLocker locker(&m_lock);
157 XsdComplexType::List retval;
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));
168 void XsdSchema::addAnonymousType(const SchemaType::Ptr &type)
170 const QWriteLocker locker(&m_lock);
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());
178 m_anonymousTypes.insert(typeName, type);
181 SchemaType::List XsdSchema::anonymousTypes() const
183 const QReadLocker locker(&m_lock);
185 return m_anonymousTypes.values();
188 void XsdSchema::addAttributeGroup(const XsdAttributeGroup::Ptr &group)
190 const QWriteLocker locker(&m_lock);
192 m_attributeGroups.insert(group->name(m_namePool), group);
195 XsdAttributeGroup::Ptr XsdSchema::attributeGroup(const QXmlName name) const
197 const QReadLocker locker(&m_lock);
199 return m_attributeGroups.value(name);
202 XsdAttributeGroup::List XsdSchema::attributeGroups() const
204 const QReadLocker locker(&m_lock);
206 return m_attributeGroups.values();
209 void XsdSchema::addElementGroup(const XsdModelGroup::Ptr &group)
211 const QWriteLocker locker(&m_lock);
213 m_elementGroups.insert(group->name(m_namePool), group);
216 XsdModelGroup::Ptr XsdSchema::elementGroup(const QXmlName &name) const
218 const QReadLocker locker(&m_lock);
220 return m_elementGroups.value(name);
223 XsdModelGroup::List XsdSchema::elementGroups() const
225 const QReadLocker locker(&m_lock);
227 return m_elementGroups.values();
230 void XsdSchema::addNotation(const XsdNotation::Ptr ¬ation)
232 const QWriteLocker locker(&m_lock);
234 m_notations.insert(notation->name(m_namePool), notation);
237 XsdNotation::Ptr XsdSchema::notation(const QXmlName &name) const
239 const QReadLocker locker(&m_lock);
241 return m_notations.value(name);
244 XsdNotation::List XsdSchema::notations() const
246 const QReadLocker locker(&m_lock);
248 return m_notations.values();
251 void XsdSchema::addIdentityConstraint(const XsdIdentityConstraint::Ptr &constraint)
253 const QWriteLocker locker(&m_lock);
255 m_identityConstraints.insert(constraint->name(m_namePool), constraint);
258 XsdIdentityConstraint::Ptr XsdSchema::identityConstraint(const QXmlName &name) const
260 const QReadLocker locker(&m_lock);
262 return m_identityConstraints.value(name);
265 XsdIdentityConstraint::List XsdSchema::identityConstraints() const
267 const QReadLocker locker(&m_lock);
269 return m_identityConstraints.values();