1 /****************************************************************************
3 ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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_XsdSchemaHelper_H
53 #define Patternist_XsdSchemaHelper_H
55 #include <private/qcomparisonfactory_p.h>
56 #include <private/qschematype_p.h>
57 #include <private/qxsdattributegroup_p.h>
58 #include <private/qxsdelement_p.h>
59 #include <private/qxsdparticle_p.h>
60 #include <private/qxsdschemacontext_p.h>
61 #include <private/qxsdwildcard_p.h>
71 * @short Contains helper methods that are used by XsdSchemaParser, XsdSchemaResolver and XsdSchemaChecker.
73 * @ingroup Patternist_schema
74 * @author Tobias Koenig <tobias.koenig@nokia.com>
80 * Checks whether the given @p particle is emptiable as defined by the
81 * algorithm in the schema spec.
83 static bool isParticleEmptiable(const XsdParticle::Ptr &particle);
86 * Checks whether the given @p nameSpace is allowed by the given namespace @p constraint.
88 static bool wildcardAllowsNamespaceName(const QString &nameSpace,
89 const XsdWildcard::NamespaceConstraint::Ptr &constraint);
92 * Checks whether the given @p name is allowed by the namespace constraint of the given @p wildcard.
94 static bool wildcardAllowsExpandedName(const QXmlName &name,
95 const XsdWildcard::Ptr &wildcard,
96 const NamePool::Ptr &namePool);
99 * Checks whether the @p wildcard is a subset of @p otherWildcard.
101 static bool isWildcardSubset(const XsdWildcard::Ptr &wildcard, const XsdWildcard::Ptr &otherWildcard);
104 * Returns the union of the given @p wildcard and @p otherWildcard.
106 static XsdWildcard::Ptr wildcardUnion(const XsdWildcard::Ptr &wildcard, const XsdWildcard::Ptr &otherWildcard);
109 * Returns the intersection of the given @p wildcard and @p otherWildcard.
111 static XsdWildcard::Ptr wildcardIntersection(const XsdWildcard::Ptr &wildcard,
112 const XsdWildcard::Ptr &otherWildcard);
115 * Returns whether the given @p type is validly substitutable for an @p otherType
116 * under the given @p constraints.
118 static bool isValidlySubstitutable(const SchemaType::Ptr &type,
119 const SchemaType::Ptr &otherType,
120 const SchemaType::DerivationConstraints &constraints);
123 * Returns whether the simple @p derivedType can be derived from the simple @p baseType
124 * under the given @p constraints.
126 static bool isSimpleDerivationOk(const SchemaType::Ptr &derivedType,
127 const SchemaType::Ptr &baseType,
128 const SchemaType::DerivationConstraints &constraints);
131 * Returns whether the complex @p derivedType can be derived from the complex @p baseType
132 * under the given @p constraints.
134 static bool isComplexDerivationOk(const SchemaType::Ptr &derivedType,
135 const SchemaType::Ptr &baseType,
136 const SchemaType::DerivationConstraints &constraints);
139 * This method takes the two string based operands @p operand1 and @p operand2 and converts them to instances of type @p type.
140 * If the conversion fails, @c false is returned, otherwise the instances are compared by the given operator @p op and the
141 * result of the comparison is returned.
143 static bool constructAndCompare(const DerivedString<TypeString>::Ptr &operand1,
144 const AtomicComparator::Operator op,
145 const DerivedString<TypeString>::Ptr &operand2,
146 const SchemaType::Ptr &type,
147 const ReportContext::Ptr &context,
148 const SourceLocationReflection *const sourceLocationReflection);
151 * Returns whether the process content property of the @p derivedWildcard is valid
152 * according to the process content property of its @p baseWildcard.
154 static bool checkWildcardProcessContents(const XsdWildcard::Ptr &baseWildcard,
155 const XsdWildcard::Ptr &derivedWildcard);
158 * Checks whether @[ member is a member of the substitution group with the given @p head.
160 static bool foundSubstitutionGroupTransitive(const XsdElement::Ptr &head,
161 const XsdElement::Ptr &member,
162 QSet<XsdElement::Ptr> &visitedElements);
165 * A helper method that iterates over the type hierarchy from @p memberType up to @p headType and collects all
166 * @p derivationSet and @p blockSet constraints that exists on the way there.
168 static void foundSubstitutionGroupTypeInheritance(const SchemaType::Ptr &headType,
169 const SchemaType::Ptr &memberType,
170 QSet<SchemaType::DerivationMethod> &derivationSet,
171 NamedSchemaComponent::BlockingConstraints &blockSet);
174 * Checks if the @p member is transitive to @p head.
176 static bool substitutionGroupOkTransitive(const XsdElement::Ptr &head,
177 const XsdElement::Ptr &member,
178 const NamePool::Ptr &namePool);
181 * Checks if @p derivedAttributeGroup is a valid restriction for @p attributeGroup.
183 static bool isValidAttributeGroupRestriction(const XsdAttributeGroup::Ptr &derivedAttributeGroup,
184 const XsdAttributeGroup::Ptr &attributeGroup,
185 const XsdSchemaContext::Ptr &context,
189 * Checks if @p derivedAttributeUses are a valid restriction for @p attributeUses.
191 static bool isValidAttributeUsesRestriction(const XsdAttributeUse::List &derivedAttributeUses,
192 const XsdAttributeUse::List &attributeUses,
193 const XsdWildcard::Ptr &derivedWildcard,
194 const XsdWildcard::Ptr &wildcard,
195 const XsdSchemaContext::Ptr &context,
199 * Checks if @p derivedAttributeUses are a valid extension for @p attributeUses.
201 static bool isValidAttributeUsesExtension(const XsdAttributeUse::List &derivedAttributeUses,
202 const XsdAttributeUse::List &attributeUses,
203 const XsdWildcard::Ptr &derivedWildcard,
204 const XsdWildcard::Ptr &wildcard,
205 const XsdSchemaContext::Ptr &context,
209 Q_DISABLE_COPY(XsdSchemaHelper)