1 /****************************************************************************
3 ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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();