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 | // |
41 | // W A R N I N G |
42 | // ------------- |
43 | // |
44 | // This file is not part of the Qt API. It exists purely as an |
45 | // implementation detail. This header file may change from version to |
46 | // version without notice, or even be removed. |
47 | // |
48 | // We mean it. |
49 | |
50 | #ifndef Patternist_XsdSchema_H |
51 | #define Patternist_XsdSchema_H |
52 | |
53 | #include <private/qschematype_p.h> |
54 | #include <private/qxsdannotated_p.h> |
55 | #include <private/qxsdattribute_p.h> |
56 | #include <private/qxsdattributegroup_p.h> |
57 | #include <private/qxsdcomplextype_p.h> |
58 | #include <private/qxsdelement_p.h> |
59 | #include <private/qxsdidentityconstraint_p.h> |
60 | #include <private/qxsdmodelgroup_p.h> |
61 | #include <private/qxsdnotation_p.h> |
62 | #include <private/qxsdsimpletype_p.h> |
63 | |
64 | #include <QtCore/QHash> |
65 | #include <QtCore/QReadWriteLock> |
66 | |
67 | /** |
68 | * @defgroup Patternist_schema XML Schema Processing |
69 | */ |
70 | |
71 | QT_BEGIN_NAMESPACE |
72 | |
73 | namespace QPatternist |
74 | { |
75 | /** |
76 | * @short Represents a XSD schema object. |
77 | * |
78 | * The class provides access to all components of a parsed XSD. |
79 | * |
80 | * @note In the documentation of this class objects, which are direct |
81 | * children of the <em>schema</em> object, are called top-level objects. |
82 | * |
83 | * @see <a href="http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040309/xml-schema-api.html#Interface-XSModel">XML Schema API reference</a> |
84 | * @ingroup Patternist_schema |
85 | * @author Tobias Koenig <tobias.koenig@nokia.com> |
86 | */ |
87 | class XsdSchema : public QSharedData, public XsdAnnotated |
88 | { |
89 | public: |
90 | typedef QExplicitlySharedDataPointer<XsdSchema> Ptr; |
91 | typedef QList<XsdSchema::Ptr> List; |
92 | |
93 | /** |
94 | * Creates a new schema object. |
95 | * |
96 | * @param namePool The namepool that should be used for names of |
97 | * all schema components. |
98 | */ |
99 | XsdSchema(const NamePool::Ptr &namePool); |
100 | |
101 | /** |
102 | * Destroys the schema object. |
103 | */ |
104 | ~XsdSchema(); |
105 | |
106 | /** |
107 | * Returns the namepool that is used for names of |
108 | * all schema components. |
109 | */ |
110 | NamePool::Ptr namePool() const; |
111 | |
112 | /** |
113 | * Sets the @p targetNamespace of the schema. |
114 | */ |
115 | void setTargetNamespace(const QString &targetNamespace); |
116 | |
117 | /** |
118 | * Returns the target namespace of the schema. |
119 | */ |
120 | QString targetNamespace() const; |
121 | |
122 | /** |
123 | * Adds a new top-level @p element to the schema. |
124 | * |
125 | * @param element The new element. |
126 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#declare-element">Element Declaration</a> |
127 | */ |
128 | void addElement(const XsdElement::Ptr &element); |
129 | |
130 | /** |
131 | * Returns the top-level element of the schema with |
132 | * the given @p name or an empty pointer if none exist. |
133 | */ |
134 | XsdElement::Ptr element(const QXmlName &name) const; |
135 | |
136 | /** |
137 | * Returns the list of all top-level elements. |
138 | */ |
139 | XsdElement::List elements() const; |
140 | |
141 | /** |
142 | * Adds a new top-level @p attribute to the schema. |
143 | * |
144 | * @param attribute The new attribute. |
145 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#declare-attribute">Attribute Declaration</a> |
146 | */ |
147 | void addAttribute(const XsdAttribute::Ptr &attribute); |
148 | |
149 | /** |
150 | * Returns the top-level attribute of the schema with |
151 | * the given @p name or an empty pointer if none exist. |
152 | */ |
153 | XsdAttribute::Ptr attribute(const QXmlName &name) const; |
154 | |
155 | /** |
156 | * Returns the list of all top-level attributes. |
157 | */ |
158 | XsdAttribute::List attributes() const; |
159 | |
160 | /** |
161 | * Adds a new top-level @p type to the schema. |
162 | * That can be a simple or a complex type. |
163 | * |
164 | * @param type The new type. |
165 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#declare-datatype">Simple Type Declaration</a> |
166 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#declare-type">Complex Type Declaration</a> |
167 | */ |
168 | void addType(const SchemaType::Ptr &type); |
169 | |
170 | /** |
171 | * Returns the top-level type of the schema with |
172 | * the given @p name or an empty pointer if none exist. |
173 | */ |
174 | SchemaType::Ptr type(const QXmlName &name) const; |
175 | |
176 | /** |
177 | * Returns the list of all top-level types. |
178 | */ |
179 | SchemaType::List types() const; |
180 | |
181 | /** |
182 | * Returns the list of all top-level simple types. |
183 | */ |
184 | XsdSimpleType::List simpleTypes() const; |
185 | |
186 | /** |
187 | * Returns the list of all top-level complex types. |
188 | */ |
189 | XsdComplexType::List complexTypes() const; |
190 | |
191 | /** |
192 | * Adds an anonymous @p type to the schema. |
193 | * Anonymous types have no name and are declared |
194 | * locally inside an element object. |
195 | * |
196 | * @param type The new anonymous type. |
197 | */ |
198 | void addAnonymousType(const SchemaType::Ptr &type); |
199 | |
200 | /** |
201 | * Returns the list of all anonymous types. |
202 | */ |
203 | SchemaType::List anonymousTypes() const; |
204 | |
205 | /** |
206 | * Adds a new top-level attribute @p group to the schema. |
207 | * |
208 | * @param group The new attribute group. |
209 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#declare-attributeGroup">Attribute Group Declaration</a> |
210 | */ |
211 | void addAttributeGroup(const XsdAttributeGroup::Ptr &group); |
212 | |
213 | /** |
214 | * Returns the top-level attribute group of the schema with |
215 | * the given @p name or an empty pointer if none exist. |
216 | */ |
217 | XsdAttributeGroup::Ptr attributeGroup(const QXmlName name) const; |
218 | |
219 | /** |
220 | * Returns the list of all top-level attribute groups. |
221 | */ |
222 | XsdAttributeGroup::List attributeGroups() const; |
223 | |
224 | /** |
225 | * Adds a new top-level element @p group to the schema. |
226 | * |
227 | * @param group The new element group. |
228 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#declare-namedModelGroup">Element Group Declaration</a> |
229 | */ |
230 | void addElementGroup(const XsdModelGroup::Ptr &group); |
231 | |
232 | /** |
233 | * Returns the top-level element group of the schema with |
234 | * the given @p name or an empty pointer if none exist. |
235 | */ |
236 | XsdModelGroup::Ptr elementGroup(const QXmlName &name) const; |
237 | |
238 | /** |
239 | * Returns the list of all top-level element groups. |
240 | */ |
241 | XsdModelGroup::List elementGroups() const; |
242 | |
243 | /** |
244 | * Adds a new top-level @p notation to the schema. |
245 | * |
246 | * @param notation The new notation. |
247 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#declare-notation">Notation Declaration</a> |
248 | */ |
249 | void addNotation(const XsdNotation::Ptr ¬ation); |
250 | |
251 | /** |
252 | * Returns the top-level notation of the schema with |
253 | * the given @p name or an empty pointer if none exist. |
254 | */ |
255 | XsdNotation::Ptr notation(const QXmlName &name) const; |
256 | |
257 | /** |
258 | * Returns the list of all top-level notations. |
259 | */ |
260 | XsdNotation::List notations() const; |
261 | |
262 | /** |
263 | * Adds a new identity @p constraint to the schema. |
264 | */ |
265 | void addIdentityConstraint(const XsdIdentityConstraint::Ptr &constraint); |
266 | |
267 | /** |
268 | * Returns the identity constraint with the given @p name |
269 | * or an empty pointer if none exist. |
270 | */ |
271 | XsdIdentityConstraint::Ptr identityConstraint(const QXmlName &name) const; |
272 | |
273 | /** |
274 | * Returns the list of all identity constraints in this schema. |
275 | */ |
276 | XsdIdentityConstraint::List identityConstraints() const; |
277 | |
278 | private: |
279 | NamePool::Ptr m_namePool; |
280 | QString m_targetNamespace; |
281 | QHash<QXmlName, XsdElement::Ptr> m_elements; |
282 | QHash<QXmlName, XsdAttribute::Ptr> m_attributes; |
283 | QHash<QXmlName, SchemaType::Ptr> m_types; |
284 | QHash<QXmlName, SchemaType::Ptr> m_anonymousTypes; |
285 | QHash<QXmlName, XsdAttributeGroup::Ptr> m_attributeGroups; |
286 | QHash<QXmlName, XsdModelGroup::Ptr> m_elementGroups; |
287 | QHash<QXmlName, XsdNotation::Ptr> m_notations; |
288 | QHash<QXmlName, XsdIdentityConstraint::Ptr> m_identityConstraints; |
289 | mutable QReadWriteLock m_lock; |
290 | }; |
291 | } |
292 | |
293 | QT_END_NAMESPACE |
294 | |
295 | #endif |
296 | |