1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://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 https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49
50#ifndef Patternist_XsdSchemaHelper_H
51#define Patternist_XsdSchemaHelper_H
52
53#include <private/qcomparisonfactory_p.h>
54#include <private/qschematype_p.h>
55#include <private/qxsdattributegroup_p.h>
56#include <private/qxsdelement_p.h>
57#include <private/qxsdparticle_p.h>
58#include <private/qxsdschemacontext_p.h>
59#include <private/qxsdwildcard_p.h>
60
61QT_BEGIN_NAMESPACE
62
63namespace QPatternist
64{
65
66 /**
67 * @short Contains helper methods that are used by XsdSchemaParser, XsdSchemaResolver and XsdSchemaChecker.
68 *
69 * @ingroup Patternist_schema
70 * @author Tobias Koenig <tobias.koenig@nokia.com>
71 */
72 class XsdSchemaHelper
73 {
74 public:
75 /**
76 * Checks whether the given @p particle is emptiable as defined by the
77 * algorithm in the schema spec.
78 */
79 static bool isParticleEmptiable(const XsdParticle::Ptr &particle);
80
81 /**
82 * Checks whether the given @p nameSpace is allowed by the given namespace @p constraint.
83 */
84 static bool wildcardAllowsNamespaceName(const QString &nameSpace,
85 const XsdWildcard::NamespaceConstraint::Ptr &constraint);
86
87 /**
88 * Checks whether the given @p name is allowed by the namespace constraint of the given @p wildcard.
89 */
90 static bool wildcardAllowsExpandedName(const QXmlName &name,
91 const XsdWildcard::Ptr &wildcard,
92 const NamePool::Ptr &namePool);
93
94 /**
95 * Checks whether the @p wildcard is a subset of @p otherWildcard.
96 */
97 static bool isWildcardSubset(const XsdWildcard::Ptr &wildcard, const XsdWildcard::Ptr &otherWildcard);
98
99 /**
100 * Returns the union of the given @p wildcard and @p otherWildcard.
101 */
102 static XsdWildcard::Ptr wildcardUnion(const XsdWildcard::Ptr &wildcard, const XsdWildcard::Ptr &otherWildcard);
103
104 /**
105 * Returns the intersection of the given @p wildcard and @p otherWildcard.
106 */
107 static XsdWildcard::Ptr wildcardIntersection(const XsdWildcard::Ptr &wildcard,
108 const XsdWildcard::Ptr &otherWildcard);
109
110 /**
111 * Returns whether the given @p type is validly substitutable for an @p otherType
112 * under the given @p constraints.
113 */
114 static bool isValidlySubstitutable(const SchemaType::Ptr &type,
115 const SchemaType::Ptr &otherType,
116 const SchemaType::DerivationConstraints &constraints);
117
118 /**
119 * Returns whether the simple @p derivedType can be derived from the simple @p baseType
120 * under the given @p constraints.
121 */
122 static bool isSimpleDerivationOk(const SchemaType::Ptr &derivedType,
123 const SchemaType::Ptr &baseType,
124 const SchemaType::DerivationConstraints &constraints);
125
126 /**
127 * Returns whether the complex @p derivedType can be derived from the complex @p baseType
128 * under the given @p constraints.
129 */
130 static bool isComplexDerivationOk(const SchemaType::Ptr &derivedType,
131 const SchemaType::Ptr &baseType,
132 const SchemaType::DerivationConstraints &constraints);
133
134 /**
135 * This method takes the two string based operands @p operand1 and @p operand2 and converts them to instances of type @p type.
136 * If the conversion fails, @c false is returned, otherwise the instances are compared by the given operator @p op and the
137 * result of the comparison is returned.
138 */
139 static bool constructAndCompare(const DerivedString<TypeString>::Ptr &operand1,
140 const AtomicComparator::Operator op,
141 const DerivedString<TypeString>::Ptr &operand2,
142 const SchemaType::Ptr &type,
143 const ReportContext::Ptr &context,
144 const SourceLocationReflection *const sourceLocationReflection);
145
146 /**
147 * Returns whether the process content property of the @p derivedWildcard is valid
148 * according to the process content property of its @p baseWildcard.
149 */
150 static bool checkWildcardProcessContents(const XsdWildcard::Ptr &baseWildcard,
151 const XsdWildcard::Ptr &derivedWildcard);
152
153 /**
154 * Checks whether @[ member is a member of the substitution group with the given @p head.
155 */
156 static bool foundSubstitutionGroupTransitive(const XsdElement::Ptr &head,
157 const XsdElement::Ptr &member,
158 QSet<XsdElement::Ptr> &visitedElements);
159
160 /**
161 * A helper method that iterates over the type hierarchy from @p memberType up to @p headType and collects all
162 * @p derivationSet and @p blockSet constraints that exists on the way there.
163 */
164 static void foundSubstitutionGroupTypeInheritance(const SchemaType::Ptr &headType,
165 const SchemaType::Ptr &memberType,
166 QSet<SchemaType::DerivationMethod> &derivationSet,
167 NamedSchemaComponent::BlockingConstraints &blockSet);
168
169 /**
170 * Checks if the @p member is transitive to @p head.
171 */
172 static bool substitutionGroupOkTransitive(const XsdElement::Ptr &head,
173 const XsdElement::Ptr &member,
174 const NamePool::Ptr &namePool);
175
176 /**
177 * Checks if @p derivedAttributeGroup is a valid restriction for @p attributeGroup.
178 */
179 static bool isValidAttributeGroupRestriction(const XsdAttributeGroup::Ptr &derivedAttributeGroup,
180 const XsdAttributeGroup::Ptr &attributeGroup,
181 const XsdSchemaContext::Ptr &context,
182 QString &errorMsg);
183
184 /**
185 * Checks if @p derivedAttributeUses are a valid restriction for @p attributeUses.
186 */
187 static bool isValidAttributeUsesRestriction(const XsdAttributeUse::List &derivedAttributeUses,
188 const XsdAttributeUse::List &attributeUses,
189 const XsdWildcard::Ptr &derivedWildcard,
190 const XsdWildcard::Ptr &wildcard,
191 const XsdSchemaContext::Ptr &context,
192 QString &errorMsg);
193
194 /**
195 * Checks if @p derivedAttributeUses are a valid extension for @p attributeUses.
196 */
197 static bool isValidAttributeUsesExtension(const XsdAttributeUse::List &derivedAttributeUses,
198 const XsdAttributeUse::List &attributeUses,
199 const XsdWildcard::Ptr &derivedWildcard,
200 const XsdWildcard::Ptr &wildcard,
201 const XsdSchemaContext::Ptr &context,
202 QString &errorMsg);
203
204 private:
205 Q_DISABLE_COPY(XsdSchemaHelper)
206 };
207}
208
209QT_END_NAMESPACE
210
211#endif
212

source code of qtxmlpatterns/src/xmlpatterns/schema/qxsdschemahelper_p.h