3800ca718b45e37ab96f748b22086da16dd91ea5
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / schema / qxsdschemahelper_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8 **
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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 //
43 //  W A R N I N G
44 //  -------------
45 //
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.
49 //
50 // We mean it.
51
52 #ifndef Patternist_XsdSchemaHelper_H
53 #define Patternist_XsdSchemaHelper_H
54
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>
62
63 QT_BEGIN_HEADER
64
65 QT_BEGIN_NAMESPACE
66
67 namespace QPatternist
68 {
69
70     /**
71      * @short Contains helper methods that are used by XsdSchemaParser, XsdSchemaResolver and XsdSchemaChecker.
72      *
73      * @ingroup Patternist_schema
74      * @author Tobias Koenig <tobias.koenig@nokia.com>
75      */
76     class XsdSchemaHelper
77     {
78         public:
79             /**
80              * Checks whether the given @p particle is emptiable as defined by the
81              * algorithm in the schema spec.
82              */
83             static bool isParticleEmptiable(const XsdParticle::Ptr &particle);
84
85             /**
86              * Checks whether the given @p nameSpace is allowed by the given namespace @p constraint.
87              */
88             static bool wildcardAllowsNamespaceName(const QString &nameSpace,
89                                                     const XsdWildcard::NamespaceConstraint::Ptr &constraint);
90
91             /**
92              * Checks whether the given @p name is allowed by the namespace constraint of the given @p wildcard.
93              */
94             static bool wildcardAllowsExpandedName(const QXmlName &name,
95                                                    const XsdWildcard::Ptr &wildcard,
96                                                    const NamePool::Ptr &namePool);
97
98             /**
99              * Checks whether the @p wildcard is a subset of @p otherWildcard.
100              */
101             static bool isWildcardSubset(const XsdWildcard::Ptr &wildcard, const XsdWildcard::Ptr &otherWildcard);
102
103             /**
104              * Returns the union of the given @p wildcard and @p otherWildcard.
105              */
106             static XsdWildcard::Ptr wildcardUnion(const XsdWildcard::Ptr &wildcard, const XsdWildcard::Ptr &otherWildcard);
107
108             /**
109              * Returns the intersection of the given @p wildcard and @p otherWildcard.
110              */
111             static XsdWildcard::Ptr wildcardIntersection(const XsdWildcard::Ptr &wildcard,
112                                                          const XsdWildcard::Ptr &otherWildcard);
113
114             /**
115              * Returns whether the given @p type is validly substitutable for an @p otherType
116              * under the given @p constraints.
117              */
118             static bool isValidlySubstitutable(const SchemaType::Ptr &type,
119                                                const SchemaType::Ptr &otherType,
120                                                const SchemaType::DerivationConstraints &constraints);
121
122             /**
123              * Returns whether the simple @p derivedType can be derived from the simple @p baseType
124              * under the given @p constraints.
125              */
126             static bool isSimpleDerivationOk(const SchemaType::Ptr &derivedType,
127                                              const SchemaType::Ptr &baseType,
128                                              const SchemaType::DerivationConstraints &constraints);
129
130             /**
131              * Returns whether the complex @p derivedType can be derived from the complex @p baseType
132              * under the given @p constraints.
133              */
134             static bool isComplexDerivationOk(const SchemaType::Ptr &derivedType,
135                                               const SchemaType::Ptr &baseType,
136                                               const SchemaType::DerivationConstraints &constraints);
137
138             /**
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.
142              */
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);
149
150             /**
151              * Returns whether the process content property of the @p derivedWildcard is valid
152              * according to the process content property of its @p baseWildcard.
153              */
154             static bool checkWildcardProcessContents(const XsdWildcard::Ptr &baseWildcard,
155                                                      const XsdWildcard::Ptr &derivedWildcard);
156
157             /**
158              * Checks whether @[ member is a member of the substitution group with the given @p head.
159              */
160             static bool foundSubstitutionGroupTransitive(const XsdElement::Ptr &head,
161                                                          const XsdElement::Ptr &member,
162                                                          QSet<XsdElement::Ptr> &visitedElements);
163
164             /**
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.
167              */
168             static void foundSubstitutionGroupTypeInheritance(const SchemaType::Ptr &headType,
169                                                               const SchemaType::Ptr &memberType,
170                                                               QSet<SchemaType::DerivationMethod> &derivationSet,
171                                                               NamedSchemaComponent::BlockingConstraints &blockSet);
172
173             /**
174              * Checks if the @p member is transitive to @p head.
175              */
176             static bool substitutionGroupOkTransitive(const XsdElement::Ptr &head,
177                                                       const XsdElement::Ptr &member,
178                                                       const NamePool::Ptr &namePool);
179
180             /**
181              * Checks if @p derivedAttributeGroup is a valid restriction for @p attributeGroup.
182              */
183             static bool isValidAttributeGroupRestriction(const XsdAttributeGroup::Ptr &derivedAttributeGroup,
184                                                          const XsdAttributeGroup::Ptr &attributeGroup,
185                                                          const XsdSchemaContext::Ptr &context,
186                                                          QString &errorMsg);
187
188             /**
189              * Checks if @p derivedAttributeUses are a valid restriction for @p attributeUses.
190              */
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,
196                                                         QString &errorMsg);
197
198             /**
199              * Checks if @p derivedAttributeUses are a valid extension for @p attributeUses.
200              */
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,
206                                                       QString &errorMsg);
207
208         private:
209             Q_DISABLE_COPY(XsdSchemaHelper)
210     };
211 }
212
213 QT_END_NAMESPACE
214
215 QT_END_HEADER
216
217 #endif