1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
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.
52 #ifndef Patternist_XsdSchemaChecker_H
53 #define Patternist_XsdSchemaChecker_H
55 #include <private/qschematype_p.h>
56 #include <private/qxsdattribute_p.h>
57 #include <private/qxsdattributegroup_p.h>
58 #include <private/qxsdelement_p.h>
59 #include <private/qxsdmodelgroup_p.h>
60 #include <private/qxsdnotation_p.h>
61 #include <private/qxsdschema_p.h>
62 #include <private/qxsdsimpletype_p.h>
64 #include <QtCore/QExplicitlySharedDataPointer>
72 class XsdSchemaContext;
73 class XsdSchemaParserContext;
76 * @short Encapsulates the checking of schema valitity after reference resolving has finished.
78 * @ingroup Patternist_schema
79 * @author Tobias Koenig <tobias.koenig@nokia.com>
81 class XsdSchemaChecker : public QSharedData
84 typedef QExplicitlySharedDataPointer<XsdSchemaChecker> Ptr;
87 * Creates a new schema checker.
89 * @param context The context that is used for customization.
90 * @param parserContext The context that contains all the data structures.
92 XsdSchemaChecker(const QExplicitlySharedDataPointer<XsdSchemaContext> &context, const XsdSchemaParserContext *parserContext);
95 * Destroys the schema checker.
100 * Starts a basic check process.
102 * This check only validates the basic super type inheritance
103 * of simple and complex types.
108 * Starts the real check process.
113 * Checks the constraining facets of all global and anonymous simple types for validity.
115 void checkConstrainingFacets();
118 * Adds the component location hash, so the checker is able to report meaning full
121 void addComponentLocationHash(const QHash<NamedSchemaComponent::Ptr, QSourceLocation> &hash);
124 void checkSimpleRestrictionBaseType();
127 * Checks that no simple or complex type inherits itself.
129 void checkBasicCircularInheritances();
132 * Checks the advanced circular inheritance.
134 void checkCircularInheritances();
137 * Checks for inheritance restrictions given by final or finalDefault
140 void checkInheritanceRestrictions();
143 * Checks for various constraints for simple types defined by schema.
145 void checkBasicSimpleTypeConstraints();
146 void checkSimpleTypeConstraints();
149 * Checks for various constraints for complex types defined by schema.
151 void checkBasicComplexTypeConstraints();
152 void checkComplexTypeConstraints();
155 * Checks for list and union derivation restrictions given by final or finalDefault
158 void checkSimpleDerivationRestrictions();
161 * Checks the set of constraining @p facets that belongs to @p simpleType for validity.
163 void checkConstrainingFacets(const XsdFacet::Hash &facets, const XsdSimpleType::Ptr &simpleType);
166 * Checks for duplicated attribute uses (attributes with the same name) inside a complex type.
168 void checkDuplicatedAttributeUses();
171 * Check the element constraints.
173 void checkElementConstraints();
176 * Check the attribute constraints.
178 void checkAttributeConstraints();
181 * Check the attribute use constraints.
183 void checkAttributeUseConstraints();
186 * A map used to find duplicated elements inside a model group.
188 typedef QHash<QXmlName, SchemaType::Ptr> DuplicatedElementMap;
191 * A map used to find duplicated wildcards inside a model group.
193 typedef QHash<XsdWildcard::NamespaceConstraint::Variety, XsdWildcard::Ptr> DuplicatedWildcardMap;
196 * Check for duplicated elements and element wildcards in all complex type particles.
198 void checkElementDuplicates();
201 * Check for duplicated elements and element wildcards in the given @p particle.
203 * @param particle The particle to check.
204 * @param elementMap A map to find the duplicated elements.
205 * @param wildcardMap A map to find the duplicated element wildcards.
207 void checkElementDuplicates(const XsdParticle::Ptr &particle, DuplicatedElementMap &elementMap, DuplicatedWildcardMap &wildcardMap);
210 * Setup fast lookup list for allowed facets of atomic simple types.
212 void setupAllowedAtomicFacets();
215 * Returns the source location of the given schema @p component or a dummy
216 * source location if the component is not found in the component location hash.
218 QSourceLocation sourceLocation(const NamedSchemaComponent::Ptr &component) const;
221 * Returns the source location of the given schema @p type or a dummy
222 * source location if the type is not found in the component location hash.
224 QSourceLocation sourceLocationForType(const SchemaType::Ptr &type) const;
227 * Checks that the string @p value is valid according the value space of @p type
228 * for the given @p component.
230 bool isValidValue(const QString &value, const AnySimpleType::Ptr &type, QString &errorMsg) const;
233 * Returns the list of facets for the given @p type.
235 XsdFacet::Hash facetsForType(const SchemaType::Ptr &type) const;
238 * Returns whether the given @p list of attribute uses contains two (or more) attribute
239 * uses that point to attributes with the same name. @p conflictingAttribute
240 * will contain the conflicting attribute in that case.
242 bool hasDuplicatedAttributeUses(const XsdAttributeUse::List &list, XsdAttribute::Ptr &conflictingAttribute) const;
245 * Returns whether the given @p list of attribute uses contains two (or more) attribute
246 * uses that have a type inherited by xs:ID.
248 bool hasMultipleIDAttributeUses(const XsdAttributeUse::List &list) const;
251 * Returns whether the given @p list of attribute uses contains an attribute
252 * uses that has a type inherited by xs:ID with a value constraint. @p conflictingAttribute
253 * will contain the conflicting attribute in that case.
255 bool hasConstraintIDAttributeUse(const XsdAttributeUse::List &list, XsdAttribute::Ptr &conflictingAttribute) const;
258 * Checks whether the @p particle equals the @p otherParticle recursively.
260 bool particleEqualsRecursively(const XsdParticle::Ptr &particle, const XsdParticle::Ptr &otherParticle) const;
263 * Checks whether the @p extension particle is a valid extension of the @p base particle.
265 bool isValidParticleExtension(const XsdParticle::Ptr &extension, const XsdParticle::Ptr &base) const;
268 * Checks whether the @p sequence of elements is accepted by the given @p particle.
270 bool elementSequenceAccepted(const XsdModelGroup::Ptr &sequence, const XsdParticle::Ptr &particle) const;
272 QExplicitlySharedDataPointer<XsdSchemaContext> m_context;
273 NamePool::Ptr m_namePool;
274 XsdSchema::Ptr m_schema;
275 QHash<QXmlName, QSet<XsdFacet::Type> > m_allowedAtomicFacets;
276 QHash<NamedSchemaComponent::Ptr, QSourceLocation> m_componentLocationHash;