1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://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 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 //
43 //  W A R N I N G
44 //  -------------
45 //
46 // This file is not part of the Qt API.  It exists purely as an
47 // implementation detail.  This header file may change from version to
48 // version without notice, or even be removed.
49 //
50 // We mean it.
51 
52 #ifndef Patternist_XsdComplexType_H
53 #define Patternist_XsdComplexType_H
54 
55 #include "qanytype_p.h"
56 #include "qxsdassertion_p.h"
57 #include "qxsdattributeuse_p.h"
58 #include "qxsdparticle_p.h"
59 #include "qxsdsimpletype_p.h"
60 #include "qxsduserschematype_p.h"
61 #include "qxsdwildcard_p.h"
62 
63 #include <QtCore/QSet>
64 
65 QT_BEGIN_HEADER
66 
67 QT_BEGIN_NAMESPACE
68 
69 namespace QPatternist
70 {
71     /**
72      * @short Represents a XSD complexType object.
73      *
74      * This class represents the <em>complexType</em> object of a XML schema as described
75      * <a href="http://www.w3.org/TR/xmlschema11-1/#Complex_Type_Definitions">here</a>.
76      *
77      * It contains information from either a top-level complex type declaration (as child of a <em>schema</em> object)
78      * or a local complex type declaration (as descendant of an <em>element</em> object).
79      *
80      * @see <a href="http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040309/xml-schema-api.html#Interface-XSComplexType">XML Schema API reference</a>
81      * @ingroup Patternist_schema
82      * @author Tobias Koenig <tobias.koenig@nokia.com>
83      */
84     class XsdComplexType : public XsdUserSchemaType<AnyType>
85     {
86         public:
87             typedef QExplicitlySharedDataPointer<XsdComplexType> Ptr;
88 
89             /**
90              * @short Describes the open content object of a complex type.
91              *
92              * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ct-open_content">Open Content Definition</a>
93              */
94             class OpenContent : public QSharedData, public XsdAnnotated
95             {
96                 public:
97                     typedef QExplicitlySharedDataPointer<OpenContent> Ptr;
98 
99                     /**
100                      * Describes the mode of the open content.
101                      *
102                      * @see <a href="http://www.w3.org/TR/xmlschema11-1/#oc-mode">Mode Definition</a>
103                      */
104                     enum Mode
105                     {
106                         None,
107                         Interleave,
108                         Suffix
109                     };
110 
111                     /**
112                      * Sets the @p mode of the open content.
113                      *
114                      * @see <a href="http://www.w3.org/TR/xmlschema11-1/#oc-mode">Mode Definition</a>
115                      */
116                     void setMode(Mode mode);
117 
118                     /**
119                      * Returns the mode of the open content.
120                      */
121                     Mode mode() const;
122 
123                     /**
124                      * Sets the @p wildcard of the open content.
125                      *
126                      * @see <a href="http://www.w3.org/TR/xmlschema11-1/#oc-wildcard">Wildcard Definition</a>
127                      */
128                     void setWildcard(const XsdWildcard::Ptr &wildcard);
129 
130                     /**
131                      * Returns the wildcard of the open content.
132                      */
133                     XsdWildcard::Ptr wildcard() const;
134 
135                 private:
136                     Mode             m_mode;
137                     XsdWildcard::Ptr m_wildcard;
138             };
139 
140             /**
141              * @short Describes the content type of a complex type.
142              */
143             class ContentType : public QSharedData
144             {
145                 public:
146                     typedef QExplicitlySharedDataPointer<ContentType> Ptr;
147 
148                     /**
149                      * Describes the variety of the content type.
150                      */
151                     enum Variety
152                     {
153                         Empty = 0,    ///< The complex type has no further content.
154                         Simple,       ///< The complex type has only simple type content (e.g. text, number etc.)
155                         ElementOnly,  ///< The complex type has further elements or attributes but no text as content.
156                         Mixed         ///< The complex type has further elements or attributes and text as content.
157                     };
158 
159                     /**
160                      * Sets the @p variety of the content type.
161                      *
162                      * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ct-variety">Variety Definition</a>
163                      */
164                     void setVariety(Variety variety);
165 
166                     /**
167                      * Returns the variety of the content type.
168                      */
169                     Variety variety() const;
170 
171                     /**
172                      * Sets the @p particle object of the content type.
173                      *
174                      * The content type has only a particle object if
175                      * its variety is ElementOnly or Mixed.
176                      *
177                      * @see XsdParticle
178                      * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ct-particle">Particle Declaration</a>
179                      */
180                     void setParticle(const XsdParticle::Ptr &particle);
181 
182                     /**
183                      * Returns the particle object of the content type,
184                      * or an empty pointer if its variety is neither
185                      * ElementOnly nor Mixed.
186                      */
187                     XsdParticle::Ptr particle() const;
188 
189                     /**
190                      * Sets the open @p content object of the content type.
191                      *
192                      * The content type has only an open content object if
193                      * its variety is ElementOnly or Mixed.
194                      *
195                      * @see OpenContent
196                      * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ct-open_content">Open Content Declaration</a>
197                      */
198                     void setOpenContent(const OpenContent::Ptr &content);
199 
200                     /**
201                      * Returns the open content object of the content type,
202                      * or an empty pointer if its variety is neither
203                      * ElementOnly nor Mixed.
204                      */
205                     OpenContent::Ptr openContent() const;
206 
207                     /**
208                      * Sets the simple @p type object of the content type.
209                      *
210                      * The content type has only a simple type object if
211                      * its variety is Simple.
212                      *
213                      * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ct-simple_type_definition">Simple Type Definition</a>
214                      */
215                     void setSimpleType(const AnySimpleType::Ptr &type);
216 
217                     /**
218                      * Returns the simple type object of the content type,
219                      * or an empty pointer if its variety is not Simple.
220                      */
221                     AnySimpleType::Ptr simpleType() const;
222 
223                 private:
224                     Variety            m_variety;
225                     XsdParticle::Ptr   m_particle;
226                     OpenContent::Ptr   m_openContent;
227                     XsdSimpleType::Ptr m_simpleType;
228             };
229 
230 
231             /**
232              * Creates a complex type object with empty content.
233              */
234             XsdComplexType();
235 
236             /**
237              * Destroys the complex type object.
238              */
~XsdComplexType()239             ~XsdComplexType() {};
240 
241             /**
242              * Returns the display name of the complex type.
243              *
244              * The display name can be used to show the type name
245              * to the user.
246              *
247              * @param namePool The name pool where the type name is stored in.
248              */
249             virtual QString displayName(const NamePool::Ptr &namePool) const;
250 
251             /**
252              * Sets the base type of the complex type.
253              *
254              * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-base_type_definition">Base Type Definition</a>
255              */
256             void setWxsSuperType(const SchemaType::Ptr &type);
257 
258             /**
259              * Returns the base type of the complex type.
260              */
261             virtual SchemaType::Ptr wxsSuperType() const;
262 
263             /**
264              * Sets the context @p component of the complex type.
265              *
266              * The component is either an element declaration or a complex type definition.
267              */
268             void setContext(const NamedSchemaComponent::Ptr &component);
269 
270             /**
271              * Returns the context component of the complex type.
272              */
273             NamedSchemaComponent::Ptr context() const;
274 
275             /**
276              * Sets the derivation @p method of the complex type.
277              *
278              * The derivation method depends on whether the complex
279              * type object has an extension or restriction object as child.
280              *
281              * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-derivation_method">Derivation Method Definition</a>
282              * @see DerivationMethod
283              */
284             void setDerivationMethod(DerivationMethod method);
285 
286             /**
287              * Returns the derivation method of the complex type.
288              */
289             virtual DerivationMethod derivationMethod() const;
290 
291             /**
292              * Sets whether the complex type is @p abstract.
293              *
294              * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-abstract">Abstract Definition</a>
295              */
296             void setIsAbstract(bool abstract);
297 
298             /**
299              * Returns whether the complex type is abstract.
300              */
301             virtual bool isAbstract() const;
302 
303             /**
304              * Sets the list of all attribute @p uses of the complex type.
305              *
306              * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-attribute_uses">Attribute Uses Declaration</a>
307              */
308             void setAttributeUses(const XsdAttributeUse::List &uses);
309 
310             /**
311              * Adds a new attribute @p use to the complex type.
312              */
313             void addAttributeUse(const XsdAttributeUse::Ptr &use);
314 
315             /**
316              * Returns the list of all attribute uses of the complex type.
317              */
318             XsdAttributeUse::List attributeUses() const;
319 
320             /**
321              * Sets the attribute @p wildcard of the complex type.
322              *
323              * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-attribute_wildcard">Attribute Wildcard Declaration</a>
324              */
325             void setAttributeWildcard(const XsdWildcard::Ptr &wildcard);
326 
327             /**
328              * Returns the attribute wildcard of the complex type.
329              */
330             XsdWildcard::Ptr attributeWildcard() const;
331 
332             /**
333              * Always returns SchemaType::ComplexType
334              */
335             virtual TypeCategory category() const;
336 
337             /**
338              * Sets the content @p type of the complex type.
339              *
340              * @see ContentType
341              */
342             void setContentType(const ContentType::Ptr &type);
343 
344             /**
345              * Returns the content type of the complex type.
346              */
347             ContentType::Ptr contentType() const;
348 
349             /**
350              * Sets the prohibited @p substitutions of the complex type.
351              *
352              * Only ExtensionConstraint and RestrictionConstraint are allowed.
353              *
354              * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-prohibited_substitutions">Prohibited Substitutions Definition</a>
355              */
356             void setProhibitedSubstitutions(const BlockingConstraints &substitutions);
357 
358             /**
359              * Returns the prohibited substitutions of the complex type.
360              */
361             BlockingConstraints prohibitedSubstitutions() const;
362 
363             /**
364              * Sets the @p assertions of the complex type.
365              *
366              * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-assertions">Assertions Definition</a>
367              */
368             void setAssertions(const XsdAssertion::List &assertions);
369 
370             /**
371              * Adds an @p assertion to the complex type.
372              *
373              * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-assertions">Assertions Definition</a>
374              */
375             void addAssertion(const XsdAssertion::Ptr &assertion);
376 
377             /**
378              * Returns the assertions of the complex type.
379              */
380             XsdAssertion::List assertions() const;
381 
382             /**
383              * Always returns @c true.
384              */
385             virtual bool isDefinedBySchema() const;
386 
387         private:
388             SchemaType                *m_superType;
389             NamedSchemaComponent      *m_context;
390             DerivationMethod          m_derivationMethod;
391             bool                      m_isAbstract;
392             XsdAttributeUse::List     m_attributeUses;
393             XsdWildcard::Ptr          m_attributeWildcard;
394             ContentType::Ptr          m_contentType;
395             BlockingConstraints       m_prohibitedSubstitutions;
396             XsdAssertion::List        m_assertions;
397     };
398 }
399 
400 QT_END_NAMESPACE
401 
402 QT_END_HEADER
403 
404 #endif
405