| 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_XsdSchemaParserContext_H |
| 51 | #define Patternist_XsdSchemaParserContext_H |
| 52 | |
| 53 | #include <private/qmaintainingreader_p.h> // for definition of ElementDescription |
| 54 | #include <private/qxsdschematoken_p.h> |
| 55 | #include <private/qxsdschema_p.h> |
| 56 | #include <private/qxsdschemachecker_p.h> |
| 57 | #include <private/qxsdschemacontext_p.h> |
| 58 | #include <private/qxsdschemaresolver_p.h> |
| 59 | |
| 60 | #include <QtCore/QSharedData> |
| 61 | |
| 62 | QT_BEGIN_NAMESPACE |
| 63 | |
| 64 | namespace QPatternist |
| 65 | { |
| 66 | /** |
| 67 | * @short A namespace class that contains identifiers for the different |
| 68 | * scopes a tag from the xml schema spec can appear in. |
| 69 | */ |
| 70 | class XsdTagScope |
| 71 | { |
| 72 | public: |
| 73 | enum Type |
| 74 | { |
| 75 | Schema, |
| 76 | Include, |
| 77 | Import, |
| 78 | Redefine, |
| 79 | Annotation, |
| 80 | AppInfo, |
| 81 | Documentation, |
| 82 | GlobalSimpleType, |
| 83 | LocalSimpleType, |
| 84 | SimpleRestriction, |
| 85 | List, |
| 86 | Union, |
| 87 | MinExclusiveFacet, |
| 88 | MinInclusiveFacet, |
| 89 | MaxExclusiveFacet, |
| 90 | MaxInclusiveFacet, |
| 91 | TotalDigitsFacet, |
| 92 | FractionDigitsFacet, |
| 93 | LengthFacet, |
| 94 | MinLengthFacet, |
| 95 | MaxLengthFacet, |
| 96 | EnumerationFacet, |
| 97 | WhiteSpaceFacet, |
| 98 | PatternFacet, |
| 99 | GlobalComplexType, |
| 100 | LocalComplexType, |
| 101 | SimpleContent, |
| 102 | SimpleContentRestriction, |
| 103 | SimpleContentExtension, |
| 104 | ComplexContent, |
| 105 | ComplexContentRestriction, |
| 106 | ComplexContentExtension, |
| 107 | NamedGroup, |
| 108 | ReferredGroup, |
| 109 | All, |
| 110 | LocalAll, |
| 111 | Choice, |
| 112 | LocalChoice, |
| 113 | Sequence, |
| 114 | LocalSequence, |
| 115 | GlobalAttribute, |
| 116 | LocalAttribute, |
| 117 | NamedAttributeGroup, |
| 118 | ReferredAttributeGroup, |
| 119 | GlobalElement, |
| 120 | LocalElement, |
| 121 | Unique, |
| 122 | Key, |
| 123 | KeyRef, |
| 124 | Selector, |
| 125 | Field, |
| 126 | Notation, |
| 127 | Any, |
| 128 | AnyAttribute, |
| 129 | Alternative, |
| 130 | Assert, |
| 131 | Assertion, |
| 132 | OpenContent, |
| 133 | DefaultOpenContent, |
| 134 | Override |
| 135 | }; |
| 136 | }; |
| 137 | |
| 138 | /** |
| 139 | * A hash that keeps the mapping between the single components that can appear |
| 140 | * in a schema document (e.g. elements, attributes, type definitions) and their |
| 141 | * source locations inside the document. |
| 142 | */ |
| 143 | typedef QHash<NamedSchemaComponent::Ptr, QSourceLocation> ComponentLocationHash; |
| 144 | |
| 145 | /** |
| 146 | * @short A context for schema parsing. |
| 147 | * |
| 148 | * This class provides a context for all components that are |
| 149 | * nedded for parsing and compiling the XML schema. |
| 150 | * |
| 151 | * @ingroup Patternist_schema |
| 152 | * @author Tobias Koenig <tobias.koenig@nokia.com> |
| 153 | */ |
| 154 | class XsdSchemaParserContext : public QSharedData |
| 155 | { |
| 156 | public: |
| 157 | /** |
| 158 | * A smart pointer wrapping XsdSchemaParserContext instances. |
| 159 | */ |
| 160 | typedef QExplicitlySharedDataPointer<XsdSchemaParserContext> Ptr; |
| 161 | |
| 162 | /** |
| 163 | * Creates a new schema parser context object. |
| 164 | * |
| 165 | * @param namePool The name pool where all names of the schema will be stored in. |
| 166 | * @param context The schema context to use for error reporting etc. |
| 167 | */ |
| 168 | XsdSchemaParserContext(const NamePool::Ptr &namePool, const XsdSchemaContext::Ptr &context); |
| 169 | |
| 170 | /** |
| 171 | * Returns the name pool of the schema parser context. |
| 172 | */ |
| 173 | NamePool::Ptr namePool() const; |
| 174 | |
| 175 | /** |
| 176 | * Returns the schema resolver of the schema context. |
| 177 | */ |
| 178 | XsdSchemaResolver::Ptr resolver() const; |
| 179 | |
| 180 | /** |
| 181 | * Returns the schema resolver of the schema context. |
| 182 | */ |
| 183 | XsdSchemaChecker::Ptr checker() const; |
| 184 | |
| 185 | /** |
| 186 | * Returns the schema object of the schema context. |
| 187 | */ |
| 188 | XsdSchema::Ptr schema() const; |
| 189 | |
| 190 | /** |
| 191 | * Returns the element descriptions for the schema parser. |
| 192 | * |
| 193 | * The element descriptions are a fast lookup table for |
| 194 | * verifying whether certain attributes are allowed for |
| 195 | * a given element type. |
| 196 | */ |
| 197 | ElementDescription<XsdSchemaToken, XsdTagScope::Type>::Hash elementDescriptions() const; |
| 198 | |
| 199 | /** |
| 200 | * Returns an unique name that is used by the schema parser |
| 201 | * for anonymous types. |
| 202 | * |
| 203 | * @param targetNamespace The namespace of the name. |
| 204 | */ |
| 205 | QXmlName createAnonymousName(const QString &targetNamespace) const; |
| 206 | |
| 207 | private: |
| 208 | /** |
| 209 | * Fills the element description hash with the required and prohibited |
| 210 | * attributes. |
| 211 | */ |
| 212 | static ElementDescription<XsdSchemaToken, XsdTagScope::Type>::Hash setupElementDescriptions(); |
| 213 | |
| 214 | NamePool::Ptr m_namePool; |
| 215 | XsdSchema::Ptr m_schema; |
| 216 | XsdSchemaChecker::Ptr m_checker; |
| 217 | XsdSchemaResolver::Ptr m_resolver; |
| 218 | const ElementDescription<XsdSchemaToken, XsdTagScope::Type>::Hash m_elementDescriptions; |
| 219 | mutable QAtomicInt m_anonymousNameCounter; |
| 220 | }; |
| 221 | } |
| 222 | |
| 223 | QT_END_NAMESPACE |
| 224 | |
| 225 | #endif |
| 226 | |