Qt 4.8
qxsdschema.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qxsdschema_p.h"
43 
44 #include <QtCore/QReadLocker>
45 #include <QtCore/QWriteLocker>
46 
48 
49 using namespace QPatternist;
50 
52  : m_namePool(namePool)
53 {
54 }
55 
57 {
58 }
59 
61 {
62  return m_namePool;
63 }
64 
66 {
68 }
69 
71 {
72  return m_targetNamespace;
73 }
74 
76 {
77  const QWriteLocker locker(&m_lock);
78 
79  m_elements.insert(element->name(m_namePool), element);
80 }
81 
83 {
84  const QReadLocker locker(&m_lock);
85 
86  return m_elements.value(name);
87 }
88 
90 {
91  const QReadLocker locker(&m_lock);
92 
93  return m_elements.values();
94 }
95 
97 {
98  const QWriteLocker locker(&m_lock);
99 
100  m_attributes.insert(attribute->name(m_namePool), attribute);
101 }
102 
104 {
105  const QReadLocker locker(&m_lock);
106 
107  return m_attributes.value(name);
108 }
109 
111 {
112  const QReadLocker locker(&m_lock);
113 
114  return m_attributes.values();
115 }
116 
118 {
119  const QWriteLocker locker(&m_lock);
120 
121  m_types.insert(type->name(m_namePool), type);
122 }
123 
125 {
126  const QReadLocker locker(&m_lock);
127 
128  return m_types.value(name);
129 }
130 
132 {
133  const QReadLocker locker(&m_lock);
134 
135  return m_types.values();
136 }
137 
139 {
140  QReadLocker locker(&m_lock);
141 
142  XsdSimpleType::List retval;
143 
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 
154 {
155  QReadLocker locker(&m_lock);
156 
157  XsdComplexType::List retval;
158 
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 
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 
182 {
183  const QReadLocker locker(&m_lock);
184 
185  return m_anonymousTypes.values();
186 }
187 
189 {
190  const QWriteLocker locker(&m_lock);
191 
192  m_attributeGroups.insert(group->name(m_namePool), group);
193 }
194 
196 {
197  const QReadLocker locker(&m_lock);
198 
199  return m_attributeGroups.value(name);
200 }
201 
203 {
204  const QReadLocker locker(&m_lock);
205 
206  return m_attributeGroups.values();
207 }
208 
210 {
211  const QWriteLocker locker(&m_lock);
212 
213  m_elementGroups.insert(group->name(m_namePool), group);
214 }
215 
217 {
218  const QReadLocker locker(&m_lock);
219 
220  return m_elementGroups.value(name);
221 }
222 
224 {
225  const QReadLocker locker(&m_lock);
226 
227  return m_elementGroups.values();
228 }
229 
231 {
232  const QWriteLocker locker(&m_lock);
233 
234  m_notations.insert(notation->name(m_namePool), notation);
235 }
236 
238 {
239  const QReadLocker locker(&m_lock);
240 
241  return m_notations.value(name);
242 }
243 
245 {
246  const QReadLocker locker(&m_lock);
247 
248  return m_notations.values();
249 }
250 
252 {
253  const QWriteLocker locker(&m_lock);
254 
255  m_identityConstraints.insert(constraint->name(m_namePool), constraint);
256 }
257 
259 {
260  const QReadLocker locker(&m_lock);
261 
262  return m_identityConstraints.value(name);
263 }
264 
266 {
267  const QReadLocker locker(&m_lock);
268 
269  return m_identityConstraints.values();
270 }
271 
const QString & stringForLocalName(const QXmlName::LocalNameCode code) const
Definition: qnamepool_p.h:168
void addElement(const XsdElement::Ptr &element)
Definition: qxsdschema.cpp:75
QHash< QXmlName, XsdIdentityConstraint::Ptr > m_identityConstraints
Definition: qxsdschema_p.h:292
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
XsdElement::Ptr element(const QXmlName &name) const
Definition: qxsdschema.cpp:82
XsdAttributeGroup::Ptr attributeGroup(const QXmlName name) const
Definition: qxsdschema.cpp:195
virtual bool isSimpleType() const
Definition: qschematype.cpp:56
XsdIdentityConstraint::Ptr identityConstraint(const QXmlName &name) const
Definition: qxsdschema.cpp:258
void addAttributeGroup(const XsdAttributeGroup::Ptr &group)
Definition: qxsdschema.cpp:188
QHash< QXmlName, XsdAttributeGroup::Ptr > m_attributeGroups
Definition: qxsdschema_p.h:289
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
SchemaType::List anonymousTypes() const
Definition: qxsdschema.cpp:181
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
XsdSimpleType::List simpleTypes() const
Definition: qxsdschema.cpp:138
The QString class provides a Unicode character string.
Definition: qstring.h:83
XsdModelGroup::List elementGroups() const
Definition: qxsdschema.cpp:223
QHash< QXmlName, XsdModelGroup::Ptr > m_elementGroups
Definition: qxsdschema_p.h:290
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
QHash< QXmlName, XsdNotation::Ptr > m_notations
Definition: qxsdschema_p.h:291
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void addIdentityConstraint(const XsdIdentityConstraint::Ptr &constraint)
Definition: qxsdschema.cpp:251
QHash< QXmlName, XsdElement::Ptr > m_elements
Definition: qxsdschema_p.h:285
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void addNotation(const XsdNotation::Ptr &notation)
Definition: qxsdschema.cpp:230
NamePool::Ptr m_namePool
Definition: qxsdschema_p.h:283
const char * typeName
Definition: qmetatype.cpp:239
virtual bool isComplexType() const
Definition: qschematype.cpp:70
const char * name
XsdIdentityConstraint::List identityConstraints() const
Definition: qxsdschema.cpp:265
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
XsdModelGroup::Ptr elementGroup(const QXmlName &name) const
Definition: qxsdschema.cpp:216
XsdNotation::Ptr notation(const QXmlName &name) const
Definition: qxsdschema.cpp:237
The namespace for the internal API of QtXmlPatterns.
QHash< QXmlName, SchemaType::Ptr > m_types
Definition: qxsdschema_p.h:287
XsdNotation::List notations() const
Definition: qxsdschema.cpp:244
QHash< QXmlName, XsdAttribute::Ptr > m_attributes
Definition: qxsdschema_p.h:286
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
XsdComplexType::List complexTypes() const
Definition: qxsdschema.cpp:153
SchemaType::Ptr type(const QXmlName &name) const
Definition: qxsdschema.cpp:124
virtual QXmlName name(const NamePool::Ptr &namePool) const
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
QString localName(const QXmlNamePool &query) const
Returns the local name.
Definition: qxmlname.cpp:387
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
QList< T > values() const
Returns a list containing all the values in the hash, in an arbitrary order.
Definition: qhash.h:693
void addAnonymousType(const SchemaType::Ptr &type)
Definition: qxsdschema.cpp:168
QXmlName allocateQName(const QString &uri, const QString &localName, const QString &prefix=QString())
Definition: qnamepool.cpp:251
XsdAttribute::List attributes() const
Definition: qxsdschema.cpp:110
QHash< QXmlName, SchemaType::Ptr > m_anonymousTypes
Definition: qxsdschema_p.h:288
XsdSchema(const NamePool::Ptr &namePool)
Definition: qxsdschema.cpp:51
void setTargetNamespace(const QString &targetNamespace)
Definition: qxsdschema.cpp:65
XsdAttribute::Ptr attribute(const QXmlName &name) const
Definition: qxsdschema.cpp:103
void addElementGroup(const XsdModelGroup::Ptr &group)
Definition: qxsdschema.cpp:209
XsdAttributeGroup::List attributeGroups() const
Definition: qxsdschema.cpp:202
QString targetNamespace() const
Definition: qxsdschema.cpp:70
void addType(const SchemaType::Ptr &type)
Definition: qxsdschema.cpp:117
virtual bool isDefinedBySchema() const
Definition: qschematype.cpp:75
SchemaType::List types() const
Definition: qxsdschema.cpp:131
virtual QXmlName name(const NamePool::Ptr &np) const =0
Returns the name of the type.
XsdElement::List elements() const
Definition: qxsdschema.cpp:89
void addAttribute(const XsdAttribute::Ptr &attribute)
Definition: qxsdschema.cpp:96
NamePool::Ptr namePool() const
Definition: qxsdschema.cpp:60
QReadWriteLock m_lock
Definition: qxsdschema_p.h:293