summaryrefslogtreecommitdiffstats
path: root/src/xmlpatterns/schema/qxsdschemachecker_p.h
blob: 65fb87fe436adf90666c9aa35371823987bc0f94 (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
/****************************************************************************
**
** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the $MODULE$ of the Qt Toolkit.
**
** $TROLLTECH_DUAL_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_XsdSchemaChecker_H
#define Patternist_XsdSchemaChecker_H

#include "qschematype_p.h"
#include "qxsdattribute_p.h"
#include "qxsdattributegroup_p.h"
#include "qxsdelement_p.h"
#include "qxsdmodelgroup_p.h"
#include "qxsdnotation_p.h"
#include "qxsdschema_p.h"
#include "qxsdsimpletype_p.h"

#include <QtCore/QExplicitlySharedDataPointer>

QT_BEGIN_HEADER

QT_BEGIN_NAMESPACE

namespace QPatternist
{
    class XsdSchemaContext;
    class XsdSchemaParserContext;

    /**
     * @short Encapsulates the checking of schema valitity after reference resolving has finished.
     *
     * @ingroup Patternist_schema
     * @author Tobias Koenig <tobias.koenig@trolltech.com>
     */
    class XsdSchemaChecker : public QSharedData
    {
        public:
            typedef QExplicitlySharedDataPointer<XsdSchemaChecker> Ptr;

            /**
             * Creates a new schema checker.
             *
             * @param context The context that is used for customization.
             * @param parserContext The context that contains all the data structures.
             */
            XsdSchemaChecker(const QExplicitlySharedDataPointer<XsdSchemaContext> &context, const XsdSchemaParserContext *parserContext);

            /**
             * Destroys the schema checker.
             */
            ~XsdSchemaChecker();

            /**
             * Starts a basic check process.
             *
             * This check only validates the basic super type inheritance
             * of simple and complex types.
             */
            void basicCheck();

            /**
             * Starts the real check process.
             */
            void check();

            /**
             * Checks the constraining facets of all global and anonymous simple types for validity.
             */
            void checkConstrainingFacets();

            /**
             * Adds the component location hash, so the checker is able to report meaning full
             * error messages.
             */
            void addComponentLocationHash(const QHash<NamedSchemaComponent::Ptr, QSourceLocation> &hash);

        private:
            void checkSimpleRestrictionBaseType();

            /**
             * Checks that no simple or complex type inherits itself.
             */
            void checkBasicCircularInheritances();

            /**
             * Checks the advanced circular inheritance.
             */
            void checkCircularInheritances();

            /**
             * Checks for inheritance restrictions given by final or finalDefault
             * attributes.
             */
            void checkInheritanceRestrictions();

            /**
             * Checks for various constraints for simple types defined by schema.
             */
            void checkBasicSimpleTypeConstraints();
            void checkSimpleTypeConstraints();

            /**
             * Checks for various constraints for complex types defined by schema.
             */
            void checkBasicComplexTypeConstraints();
            void checkComplexTypeConstraints();

            /**
             * Checks for list and union derivation restrictions given by final or finalDefault
             * attributes.
             */
            void checkSimpleDerivationRestrictions();

            /**
             * Checks the set of constraining @p facets that belongs to @p simpleType for validity.
             */
            void checkConstrainingFacets(const XsdFacet::Hash &facets, const XsdSimpleType::Ptr &simpleType);

            /**
             * Checks for duplicated attribute uses (attributes with the same name) inside a complex type.
             */
            void checkDuplicatedAttributeUses();

            /**
             * Check the element constraints.
             */
            void checkElementConstraints();

            /**
             * Check the attribute constraints.
             */
            void checkAttributeConstraints();

            /**
             * Check the attribute use constraints.
             */
            void checkAttributeUseConstraints();

            /**
             * A map used to find duplicated elements inside a model group.
             */
            typedef QHash<QXmlName, SchemaType::Ptr> DuplicatedElementMap;

            /**
             * A map used to find duplicated wildcards inside a model group.
             */
            typedef QHash<XsdWildcard::NamespaceConstraint::Variety, XsdWildcard::Ptr> DuplicatedWildcardMap;

            /**
             * Check for duplicated elements and element wildcards in all complex type particles.
             */
            void checkElementDuplicates();

            /**
             * Check for duplicated elements and element wildcards in the given @p particle.
             *
             * @param particle The particle to check.
             * @param elementMap A map to find the duplicated elements.
             * @param wildcardMap A map to find the duplicated element wildcards.
             */
            void checkElementDuplicates(const XsdParticle::Ptr &particle, DuplicatedElementMap &elementMap, DuplicatedWildcardMap &wildcardMap);

            /**
             * Setup fast lookup list for allowed facets of atomic simple types.
             */
            void setupAllowedAtomicFacets();

            /**
             * Returns the source location of the given schema @p component or a dummy
             * source location if the component is not found in the component location hash.
             */
            QSourceLocation sourceLocation(const NamedSchemaComponent::Ptr &component) const;

            /**
             * Returns the source location of the given schema @p type or a dummy
             * source location if the type is not found in the component location hash.
             */
            QSourceLocation sourceLocationForType(const SchemaType::Ptr &type) const;

            /**
             * Checks that the string @p value is valid according the value space of @p type
             * for the given @p component.
             */
            bool isValidValue(const QString &value, const AnySimpleType::Ptr &type, QString &errorMsg) const;

            /**
             * Returns the list of facets for the given @p type.
             */
            XsdFacet::Hash facetsForType(const SchemaType::Ptr &type) const;

            /**
             * Returns whether the given @p list of attribute uses contains two (or more) attribute
             * uses that point to attributes with the same name. @p conflictingAttribute
             * will contain the conflicting attribute in that case.
             */
            bool hasDuplicatedAttributeUses(const XsdAttributeUse::List &list, XsdAttribute::Ptr &conflictingAttribute) const;

            /**
             * Returns whether the given @p list of attribute uses contains two (or more) attribute
             * uses that have a type inherited by xs:ID.
             */
            bool hasMultipleIDAttributeUses(const XsdAttributeUse::List &list) const;

            /**
             * Returns whether the given @p list of attribute uses contains an attribute
             * uses that has a type inherited by xs:ID with a value constraint. @p conflictingAttribute
             * will contain the conflicting attribute in that case.
             */
            bool hasConstraintIDAttributeUse(const XsdAttributeUse::List &list, XsdAttribute::Ptr &conflictingAttribute) const;

            /**
             * Checks whether the @p particle equals the @p otherParticle recursively.
             */
            bool particleEqualsRecursively(const XsdParticle::Ptr &particle, const XsdParticle::Ptr &otherParticle) const;

            /**
             * Checks whether the @p extension particle is a valid extension of the @p base particle.
             */
            bool isValidParticleExtension(const XsdParticle::Ptr &extension, const XsdParticle::Ptr &base) const;

            /**
             * Checks whether the @p sequence of elements is accepted by the given @p particle.
             */
            bool elementSequenceAccepted(const XsdModelGroup::Ptr &sequence, const XsdParticle::Ptr &particle) const;

            QExplicitlySharedDataPointer<XsdSchemaContext>       m_context;
            NamePool::Ptr                                        m_namePool;
            XsdSchema::Ptr                                       m_schema;
            QHash<QXmlName, QSet<XsdFacet::Type> >               m_allowedAtomicFacets;
            QHash<NamedSchemaComponent::Ptr, QSourceLocation>    m_componentLocationHash;
    };
}

QT_END_NAMESPACE

QT_END_HEADER

#endif