1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://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 http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://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 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 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_XsdSchemaParserContext_H 53 #define Patternist_XsdSchemaParserContext_H 54 55 #include "qmaintainingreader_p.h" // for definition of ElementDescription 56 #include "qxsdschematoken_p.h" 57 #include "qxsdschema_p.h" 58 #include "qxsdschemachecker_p.h" 59 #include "qxsdschemacontext_p.h" 60 #include "qxsdschemaresolver_p.h" 61 62 #include <QtCore/QSharedData> 63 64 QT_BEGIN_HEADER 65 66 QT_BEGIN_NAMESPACE 67 68 namespace QPatternist 69 { 70 /** 71 * @short A namespace class that contains identifiers for the different 72 * scopes a tag from the xml schema spec can appear in. 73 */ 74 class XsdTagScope 75 { 76 public: 77 enum Type 78 { 79 Schema, 80 Include, 81 Import, 82 Redefine, 83 Annotation, 84 AppInfo, 85 Documentation, 86 GlobalSimpleType, 87 LocalSimpleType, 88 SimpleRestriction, 89 List, 90 Union, 91 MinExclusiveFacet, 92 MinInclusiveFacet, 93 MaxExclusiveFacet, 94 MaxInclusiveFacet, 95 TotalDigitsFacet, 96 FractionDigitsFacet, 97 LengthFacet, 98 MinLengthFacet, 99 MaxLengthFacet, 100 EnumerationFacet, 101 WhiteSpaceFacet, 102 PatternFacet, 103 GlobalComplexType, 104 LocalComplexType, 105 SimpleContent, 106 SimpleContentRestriction, 107 SimpleContentExtension, 108 ComplexContent, 109 ComplexContentRestriction, 110 ComplexContentExtension, 111 NamedGroup, 112 ReferredGroup, 113 All, 114 LocalAll, 115 Choice, 116 LocalChoice, 117 Sequence, 118 LocalSequence, 119 GlobalAttribute, 120 LocalAttribute, 121 NamedAttributeGroup, 122 ReferredAttributeGroup, 123 GlobalElement, 124 LocalElement, 125 Unique, 126 Key, 127 KeyRef, 128 Selector, 129 Field, 130 Notation, 131 Any, 132 AnyAttribute, 133 Alternative, 134 Assert, 135 Assertion, 136 OpenContent, 137 DefaultOpenContent, 138 Override 139 }; 140 }; 141 142 /** 143 * A hash that keeps the mapping between the single components that can appear 144 * in a schema document (e.g. elements, attributes, type definitions) and their 145 * source locations inside the document. 146 */ 147 typedef QHash<NamedSchemaComponent::Ptr, QSourceLocation> ComponentLocationHash; 148 149 /** 150 * @short A context for schema parsing. 151 * 152 * This class provides a context for all components that are 153 * nedded for parsing and compiling the XML schema. 154 * 155 * @ingroup Patternist_schema 156 * @author Tobias Koenig <tobias.koenig@nokia.com> 157 */ 158 class XsdSchemaParserContext : public QSharedData 159 { 160 public: 161 /** 162 * A smart pointer wrapping XsdSchemaParserContext instances. 163 */ 164 typedef QExplicitlySharedDataPointer<XsdSchemaParserContext> Ptr; 165 166 /** 167 * Creates a new schema parser context object. 168 * 169 * @param namePool The name pool where all names of the schema will be stored in. 170 * @param context The schema context to use for error reporting etc. 171 */ 172 XsdSchemaParserContext(const NamePool::Ptr &namePool, const XsdSchemaContext::Ptr &context); 173 174 /** 175 * Returns the name pool of the schema parser context. 176 */ 177 NamePool::Ptr namePool() const; 178 179 /** 180 * Returns the schema resolver of the schema context. 181 */ 182 XsdSchemaResolver::Ptr resolver() const; 183 184 /** 185 * Returns the schema resolver of the schema context. 186 */ 187 XsdSchemaChecker::Ptr checker() const; 188 189 /** 190 * Returns the schema object of the schema context. 191 */ 192 XsdSchema::Ptr schema() const; 193 194 /** 195 * Returns the element descriptions for the schema parser. 196 * 197 * The element descriptions are a fast lookup table for 198 * verifying whether certain attributes are allowed for 199 * a given element type. 200 */ 201 ElementDescription<XsdSchemaToken, XsdTagScope::Type>::Hash elementDescriptions() const; 202 203 /** 204 * Returns an unique name that is used by the schema parser 205 * for anonymous types. 206 * 207 * @param targetNamespace The namespace of the name. 208 */ 209 QXmlName createAnonymousName(const QString &targetNamespace) const; 210 211 private: 212 /** 213 * Fills the element description hash with the required and prohibited 214 * attributes. 215 */ 216 static ElementDescription<XsdSchemaToken, XsdTagScope::Type>::Hash setupElementDescriptions(); 217 218 NamePool::Ptr m_namePool; 219 XsdSchema::Ptr m_schema; 220 XsdSchemaChecker::Ptr m_checker; 221 XsdSchemaResolver::Ptr m_resolver; 222 const ElementDescription<XsdSchemaToken, XsdTagScope::Type>::Hash m_elementDescriptions; 223 mutable QAtomicInt m_anonymousNameCounter; 224 }; 225 } 226 227 QT_END_NAMESPACE 228 229 QT_END_HEADER 230 231 #endif 232