summaryrefslogtreecommitdiff
path: root/src/xmlpatterns/schema/qxsdcomplextype_p.h
blob: 1e7a0275f8060e4cf3b2d8a2d151b1f84786e6e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtXmlPatterns module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.

#ifndef Patternist_XsdComplexType_H
#define Patternist_XsdComplexType_H

#include <private/qanytype_p.h>
#include <private/qxsdassertion_p.h>
#include <private/qxsdattributeuse_p.h>
#include <private/qxsdparticle_p.h>
#include <private/qxsdsimpletype_p.h>
#include <private/qxsduserschematype_p.h>
#include <private/qxsdwildcard_p.h>

#include <QtCore/QSet>

QT_BEGIN_NAMESPACE

namespace QPatternist
{
    /**
     * @short Represents a XSD complexType object.
     *
     * This class represents the <em>complexType</em> object of a XML schema as described
     * <a href="http://www.w3.org/TR/xmlschema11-1/#Complex_Type_Definitions">here</a>.
     *
     * It contains information from either a top-level complex type declaration (as child of a <em>schema</em> object)
     * or a local complex type declaration (as descendant of an <em>element</em> object).
     *
     * @see <a href="http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040309/xml-schema-api.html#Interface-XSComplexType">XML Schema API reference</a>
     * @ingroup Patternist_schema
     * @author Tobias Koenig <tobias.koenig@nokia.com>
     */
    class XsdComplexType : public XsdUserSchemaType<AnyType>
    {
        public:
            typedef QExplicitlySharedDataPointer<XsdComplexType> Ptr;

            /**
             * @short Describes the open content object of a complex type.
             *
             * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ct-open_content">Open Content Definition</a>
             */
            class OpenContent : public QSharedData, public XsdAnnotated
            {
                public:
                    typedef QExplicitlySharedDataPointer<OpenContent> Ptr;

                    /**
                     * Describes the mode of the open content.
                     *
                     * @see <a href="http://www.w3.org/TR/xmlschema11-1/#oc-mode">Mode Definition</a>
                     */
                    enum Mode
                    {
                        None,
                        Interleave,
                        Suffix
                    };

                    /**
                     * Sets the @p mode of the open content.
                     *
                     * @see <a href="http://www.w3.org/TR/xmlschema11-1/#oc-mode">Mode Definition</a>
                     */
                    void setMode(Mode mode);

                    /**
                     * Returns the mode of the open content.
                     */
                    Mode mode() const;

                    /**
                     * Sets the @p wildcard of the open content.
                     *
                     * @see <a href="http://www.w3.org/TR/xmlschema11-1/#oc-wildcard">Wildcard Definition</a>
                     */
                    void setWildcard(const XsdWildcard::Ptr &wildcard);

                    /**
                     * Returns the wildcard of the open content.
                     */
                    XsdWildcard::Ptr wildcard() const;

                private:
                    Mode             m_mode;
                    XsdWildcard::Ptr m_wildcard;
            };

            /**
             * @short Describes the content type of a complex type.
             */
            class ContentType : public QSharedData
            {
                public:
                    typedef QExplicitlySharedDataPointer<ContentType> Ptr;

                    /**
                     * Describes the variety of the content type.
                     */
                    enum Variety
                    {
                        Empty = 0,    ///< The complex type has no further content.
                        Simple,       ///< The complex type has only simple type content (e.g. text, number etc.)
                        ElementOnly,  ///< The complex type has further elements or attributes but no text as content.
                        Mixed         ///< The complex type has further elements or attributes and text as content.
                    };

                    /**
                     * Sets the @p variety of the content type.
                     *
                     * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ct-variety">Variety Definition</a>
                     */
                    void setVariety(Variety variety);

                    /**
                     * Returns the variety of the content type.
                     */
                    Variety variety() const;

                    /**
                     * Sets the @p particle object of the content type.
                     *
                     * The content type has only a particle object if
                     * its variety is ElementOnly or Mixed.
                     *
                     * @see XsdParticle
                     * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ct-particle">Particle Declaration</a>
                     */
                    void setParticle(const XsdParticle::Ptr &particle);

                    /**
                     * Returns the particle object of the content type,
                     * or an empty pointer if its variety is neither
                     * ElementOnly nor Mixed.
                     */
                    XsdParticle::Ptr particle() const;

                    /**
                     * Sets the open @p content object of the content type.
                     *
                     * The content type has only an open content object if
                     * its variety is ElementOnly or Mixed.
                     *
                     * @see OpenContent
                     * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ct-open_content">Open Content Declaration</a>
                     */
                    void setOpenContent(const OpenContent::Ptr &content);

                    /**
                     * Returns the open content object of the content type,
                     * or an empty pointer if its variety is neither
                     * ElementOnly nor Mixed.
                     */
                    OpenContent::Ptr openContent() const;

                    /**
                     * Sets the simple @p type object of the content type.
                     *
                     * The content type has only a simple type object if
                     * its variety is Simple.
                     *
                     * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ct-simple_type_definition">Simple Type Definition</a>
                     */
                    void setSimpleType(const AnySimpleType::Ptr &type);

                    /**
                     * Returns the simple type object of the content type,
                     * or an empty pointer if its variety is not Simple.
                     */
                    AnySimpleType::Ptr simpleType() const;

                private:
                    Variety            m_variety;
                    XsdParticle::Ptr   m_particle;
                    OpenContent::Ptr   m_openContent;
                    XsdSimpleType::Ptr m_simpleType;
            };


            /**
             * Creates a complex type object with empty content.
             */
            XsdComplexType();

            /**
             * Destroys the complex type object.
             */
            ~XsdComplexType() {};

            /**
             * Returns the display name of the complex type.
             *
             * The display name can be used to show the type name
             * to the user.
             *
             * @param namePool The name pool where the type name is stored in.
             */
            virtual QString displayName(const NamePool::Ptr &namePool) const;

            /**
             * Sets the base type of the complex type.
             *
             * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-base_type_definition">Base Type Definition</a>
             */
            void setWxsSuperType(const SchemaType::Ptr &type);

            /**
             * Returns the base type of the complex type.
             */
            virtual SchemaType::Ptr wxsSuperType() const;

            /**
             * Sets the context @p component of the complex type.
             *
             * The component is either an element declaration or a complex type definition.
             */
            void setContext(const NamedSchemaComponent::Ptr &component);

            /**
             * Returns the context component of the complex type.
             */
            NamedSchemaComponent::Ptr context() const;

            /**
             * Sets the derivation @p method of the complex type.
             *
             * The derivation method depends on whether the complex
             * type object has an extension or restriction object as child.
             *
             * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-derivation_method">Derivation Method Definition</a>
             * @see DerivationMethod
             */
            void setDerivationMethod(DerivationMethod method);

            /**
             * Returns the derivation method of the complex type.
             */
            virtual DerivationMethod derivationMethod() const;

            /**
             * Sets whether the complex type is @p abstract.
             *
             * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-abstract">Abstract Definition</a>
             */
            void setIsAbstract(bool abstract);

            /**
             * Returns whether the complex type is abstract.
             */
            virtual bool isAbstract() const;

            /**
             * Sets the list of all attribute @p uses of the complex type.
             *
             * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-attribute_uses">Attribute Uses Declaration</a>
             */
            void setAttributeUses(const XsdAttributeUse::List &uses);

            /**
             * Adds a new attribute @p use to the complex type.
             */
            void addAttributeUse(const XsdAttributeUse::Ptr &use);

            /**
             * Returns the list of all attribute uses of the complex type.
             */
            XsdAttributeUse::List attributeUses() const;

            /**
             * Sets the attribute @p wildcard of the complex type.
             *
             * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-attribute_wildcard">Attribute Wildcard Declaration</a>
             */
            void setAttributeWildcard(const XsdWildcard::Ptr &wildcard);

            /**
             * Returns the attribute wildcard of the complex type.
             */
            XsdWildcard::Ptr attributeWildcard() const;

            /**
             * Always returns SchemaType::ComplexType
             */
            virtual TypeCategory category() const;

            /**
             * Sets the content @p type of the complex type.
             *
             * @see ContentType
             */
            void setContentType(const ContentType::Ptr &type);

            /**
             * Returns the content type of the complex type.
             */
            ContentType::Ptr contentType() const;

            /**
             * Sets the prohibited @p substitutions of the complex type.
             *
             * Only ExtensionConstraint and RestrictionConstraint are allowed.
             *
             * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-prohibited_substitutions">Prohibited Substitutions Definition</a>
             */
            void setProhibitedSubstitutions(const BlockingConstraints &substitutions);

            /**
             * Returns the prohibited substitutions of the complex type.
             */
            BlockingConstraints prohibitedSubstitutions() const;

            /**
             * Sets the @p assertions of the complex type.
             *
             * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-assertions">Assertions Definition</a>
             */
            void setAssertions(const XsdAssertion::List &assertions);

            /**
             * Adds an @p assertion to the complex type.
             *
             * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ctd-assertions">Assertions Definition</a>
             */
            void addAssertion(const XsdAssertion::Ptr &assertion);

            /**
             * Returns the assertions of the complex type.
             */
            XsdAssertion::List assertions() const;

            /**
             * Always returns @c true.
             */
            virtual bool isDefinedBySchema() const;

        private:
            SchemaType::Ptr           m_superType;
            NamedSchemaComponent::Ptr m_context;
            DerivationMethod          m_derivationMethod;
            bool                      m_isAbstract;
            XsdAttributeUse::List     m_attributeUses;
            XsdWildcard::Ptr          m_attributeWildcard;
            ContentType::Ptr          m_contentType;
            BlockingConstraints       m_prohibitedSubstitutions;
            XsdAssertion::List        m_assertions;
    };
}

QT_END_NAMESPACE

#endif