| 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_XsdSchemaParser_H |
| 51 | #define Patternist_XsdSchemaParser_H |
| 52 | |
| 53 | #include <private/qnamespacesupport_p.h> |
| 54 | #include <private/qxsdalternative_p.h> |
| 55 | #include <private/qxsdattribute_p.h> |
| 56 | #include <private/qxsdattributegroup_p.h> |
| 57 | #include <private/qxsdattributeterm_p.h> |
| 58 | #include <private/qxsdcomplextype_p.h> |
| 59 | #include <private/qxsdelement_p.h> |
| 60 | #include <private/qxsdidcache_p.h> |
| 61 | #include <private/qxsdmodelgroup_p.h> |
| 62 | #include <private/qxsdnotation_p.h> |
| 63 | #include <private/qxsdsimpletype_p.h> |
| 64 | #include <private/qxsdschemacontext_p.h> |
| 65 | #include <private/qxsdschemaparsercontext_p.h> |
| 66 | #include <private/qxsdstatemachine_p.h> |
| 67 | |
| 68 | #include <QtCore/QHash> |
| 69 | #include <QtCore/QSet> |
| 70 | #include <QtCore/QUrl> |
| 71 | #include <QtCore/QXmlStreamReader> |
| 72 | #include <QtXmlPatterns/QXmlNamePool> |
| 73 | |
| 74 | QT_BEGIN_NAMESPACE |
| 75 | |
| 76 | namespace QPatternist |
| 77 | { |
| 78 | /** |
| 79 | * @short Implements the parsing of XML schema file. |
| 80 | * |
| 81 | * This class parses a XML schema in XML presentation from an QIODevice |
| 82 | * and returns object representation as XsdSchema. |
| 83 | * |
| 84 | * @ingroup Patternist_schema |
| 85 | * @author Tobias Koenig <tobias.koenig@nokia.com> |
| 86 | */ |
| 87 | class XsdSchemaParser : public MaintainingReader<XsdSchemaToken, XsdTagScope::Type> |
| 88 | { |
| 89 | friend class ElementNamespaceHandler; |
| 90 | friend class TagValidationHandler; |
| 91 | |
| 92 | public: |
| 93 | enum ParserType |
| 94 | { |
| 95 | TopLevelParser, |
| 96 | IncludeParser, |
| 97 | ImportParser, |
| 98 | RedefineParser |
| 99 | }; |
| 100 | |
| 101 | /** |
| 102 | * Creates a new schema parser object. |
| 103 | */ |
| 104 | XsdSchemaParser(const XsdSchemaContext::Ptr &context, const XsdSchemaParserContext::Ptr &parserContext, QIODevice *device); |
| 105 | |
| 106 | /** |
| 107 | * Parses the XML schema file. |
| 108 | * |
| 109 | * @return @c true on success, @c false if the schema is somehow invalid. |
| 110 | */ |
| 111 | bool parse(ParserType parserType = TopLevelParser); |
| 112 | |
| 113 | /** |
| 114 | * Describes a set of namespace URIs |
| 115 | */ |
| 116 | typedef QSet<QUrl> NamespaceSet; |
| 117 | |
| 118 | /** |
| 119 | * Adds @p schemas to the list of already included schemas, so the parser |
| 120 | * can detect multiple includes of the same schema. |
| 121 | */ |
| 122 | void addIncludedSchemas(const NamespaceSet &schemas); |
| 123 | |
| 124 | /** |
| 125 | * Sets which @p schemas have been included already, so the parser |
| 126 | * can detect multiple includes of the same schema. |
| 127 | */ |
| 128 | void setIncludedSchemas(const NamespaceSet &schemas); |
| 129 | |
| 130 | /** |
| 131 | * Adds @p schemas to the list of already imported schemas, so the parser |
| 132 | * can detect multiple imports of the same schema. |
| 133 | */ |
| 134 | void addImportedSchemas(const NamespaceSet &schemas); |
| 135 | |
| 136 | /** |
| 137 | * Sets which @p schemas have been imported already, so the parser |
| 138 | * can detect circular imports. |
| 139 | */ |
| 140 | void setImportedSchemas(const NamespaceSet &schemas); |
| 141 | |
| 142 | /** |
| 143 | * Adds @p schemas to the list of already redefined schemas, so the parser |
| 144 | * can detect multiple redefines of the same schema. |
| 145 | */ |
| 146 | void addRedefinedSchemas(const NamespaceSet &schemas); |
| 147 | |
| 148 | /** |
| 149 | * Sets which @p schemas have been redefined already, so the parser |
| 150 | * can detect multiple redefines of the same schema. |
| 151 | */ |
| 152 | void setRedefinedSchemas(const NamespaceSet &schemas); |
| 153 | |
| 154 | /** |
| 155 | * Sets the target namespace of the schema to parse. |
| 156 | */ |
| 157 | void setTargetNamespace(const QString &targetNamespace); |
| 158 | |
| 159 | /** |
| 160 | * Sets the document URI of the schema to parse. |
| 161 | */ |
| 162 | void setDocumentURI(const QUrl &uri); |
| 163 | |
| 164 | /** |
| 165 | * Returns the document URI of the schema to parse. |
| 166 | */ |
| 167 | QUrl documentURI() const; |
| 168 | |
| 169 | /** |
| 170 | * Reimplemented from MaintainingReader, always returns @c false. |
| 171 | */ |
| 172 | bool isAnyAttributeAllowed() const; |
| 173 | |
| 174 | private: |
| 175 | /** |
| 176 | * Used internally to report any kind of parsing error or |
| 177 | * schema inconsistency. |
| 178 | */ |
| 179 | virtual void error(const QString &msg); |
| 180 | |
| 181 | void attributeContentError(const char *attributeName, const char *elementName, const QString &value, const SchemaType::Ptr &type = SchemaType::Ptr()); |
| 182 | |
| 183 | /** |
| 184 | * Sets the target namespace of the schema to parse. |
| 185 | */ |
| 186 | void setTargetNamespaceExtended(const QString &targetNamespace); |
| 187 | |
| 188 | /** |
| 189 | * This method is called for parsing the top-level <em>schema</em> object. |
| 190 | */ |
| 191 | void parseSchema(ParserType parserType); |
| 192 | |
| 193 | /** |
| 194 | * This method is called for parsing any top-level <em>include</em> object. |
| 195 | */ |
| 196 | void parseInclude(); |
| 197 | |
| 198 | /** |
| 199 | * This method is called for parsing any top-level <em>import</em> object. |
| 200 | */ |
| 201 | void parseImport(); |
| 202 | |
| 203 | /** |
| 204 | * This method is called for parsing any top-level <em>redefine</em> object. |
| 205 | */ |
| 206 | void parseRedefine(); |
| 207 | |
| 208 | /** |
| 209 | * This method is called for parsing any <em>annotation</em> object everywhere |
| 210 | * in the schema. |
| 211 | */ |
| 212 | XsdAnnotation::Ptr parseAnnotation(); |
| 213 | |
| 214 | /** |
| 215 | * This method is called for parsing an <em>appinfo</em> object as child of |
| 216 | * an <em>annotation</em> object. |
| 217 | */ |
| 218 | XsdApplicationInformation::Ptr parseAppInfo(); |
| 219 | |
| 220 | /** |
| 221 | * This method is called for parsing a <em>documentation</em> object as child of |
| 222 | * an <em>annotation</em> object. |
| 223 | */ |
| 224 | XsdDocumentation::Ptr parseDocumentation(); |
| 225 | |
| 226 | /** |
| 227 | * This method is called for parsing a <em>defaultOpenContent</em> object. |
| 228 | */ |
| 229 | void parseDefaultOpenContent(); |
| 230 | |
| 231 | /** |
| 232 | * This method is called for parsing any top-level <em>simpleType</em> object. |
| 233 | */ |
| 234 | XsdSimpleType::Ptr parseGlobalSimpleType(); |
| 235 | |
| 236 | /** |
| 237 | * This method is called for parsing any <em>simpleType</em> object as descendant |
| 238 | * of an <em>element</em> or <em>complexType</em> object. |
| 239 | */ |
| 240 | XsdSimpleType::Ptr parseLocalSimpleType(); |
| 241 | |
| 242 | /** |
| 243 | * This method is called for parsing a <em>restriction</em> object as child |
| 244 | * of a <em>simpleType</em> object. |
| 245 | */ |
| 246 | void parseSimpleRestriction(const XsdSimpleType::Ptr &ptr); |
| 247 | |
| 248 | /** |
| 249 | * This method is called for parsing a <em>list</em> object as child |
| 250 | * of a <em>simpleType</em> object. |
| 251 | */ |
| 252 | void parseList(const XsdSimpleType::Ptr &ptr); |
| 253 | |
| 254 | /** |
| 255 | * This method is called for parsing a <em>union</em> object as child |
| 256 | * of a <em>simpleType</em> object. |
| 257 | */ |
| 258 | void parseUnion(const XsdSimpleType::Ptr &ptr); |
| 259 | |
| 260 | /** |
| 261 | * This method is called for parsing a <em>minExclusive</em> object as child |
| 262 | * of a <em>restriction</em> object. |
| 263 | */ |
| 264 | XsdFacet::Ptr parseMinExclusiveFacet(); |
| 265 | |
| 266 | /** |
| 267 | * This method is called for parsing a <em>minInclusive</em> object as child |
| 268 | * of a <em>restriction</em> object. |
| 269 | */ |
| 270 | XsdFacet::Ptr parseMinInclusiveFacet(); |
| 271 | |
| 272 | /** |
| 273 | * This method is called for parsing a <em>maxExclusive</em> object as child |
| 274 | * of a <em>restriction</em> object. |
| 275 | */ |
| 276 | XsdFacet::Ptr parseMaxExclusiveFacet(); |
| 277 | |
| 278 | /** |
| 279 | * This method is called for parsing a <em>maxInclusive</em> object as child |
| 280 | * of a <em>restriction</em> object. |
| 281 | */ |
| 282 | XsdFacet::Ptr parseMaxInclusiveFacet(); |
| 283 | |
| 284 | /** |
| 285 | * This method is called for parsing a <em>totalDigits</em> object as child |
| 286 | * of a <em>restriction</em> object. |
| 287 | */ |
| 288 | XsdFacet::Ptr parseTotalDigitsFacet(); |
| 289 | |
| 290 | /** |
| 291 | * This method is called for parsing a <em>fractionDigits</em> object as child |
| 292 | * of a <em>restriction</em> object. |
| 293 | */ |
| 294 | XsdFacet::Ptr parseFractionDigitsFacet(); |
| 295 | |
| 296 | /** |
| 297 | * This method is called for parsing a <em>length</em> object as child |
| 298 | * of a <em>restriction</em> object. |
| 299 | */ |
| 300 | XsdFacet::Ptr parseLengthFacet(); |
| 301 | |
| 302 | /** |
| 303 | * This method is called for parsing a <em>minLength</em> object as child |
| 304 | * of a <em>restriction</em> object. |
| 305 | */ |
| 306 | XsdFacet::Ptr parseMinLengthFacet(); |
| 307 | |
| 308 | /** |
| 309 | * This method is called for parsing a <em>maxLength</em> object as child |
| 310 | * of a <em>restriction</em> object. |
| 311 | */ |
| 312 | XsdFacet::Ptr parseMaxLengthFacet(); |
| 313 | |
| 314 | /** |
| 315 | * This method is called for parsing an <em>enumeration</em> object as child |
| 316 | * of a <em>restriction</em> object. |
| 317 | */ |
| 318 | XsdFacet::Ptr parseEnumerationFacet(); |
| 319 | |
| 320 | /** |
| 321 | * This method is called for parsing a <em>whiteSpace</em> object as child |
| 322 | * of a <em>restriction</em> object. |
| 323 | */ |
| 324 | XsdFacet::Ptr parseWhiteSpaceFacet(); |
| 325 | |
| 326 | /** |
| 327 | * This method is called for parsing a <em>pattern</em> object as child |
| 328 | * of a <em>restriction</em> object. |
| 329 | */ |
| 330 | XsdFacet::Ptr parsePatternFacet(); |
| 331 | |
| 332 | /** |
| 333 | * This method is called for parsing an <em>assertion</em> object as child |
| 334 | * of a <em>restriction</em> object. |
| 335 | */ |
| 336 | XsdFacet::Ptr parseAssertionFacet(); |
| 337 | |
| 338 | /** |
| 339 | * This method is called for parsing any top-level <em>complexType</em> object. |
| 340 | */ |
| 341 | XsdComplexType::Ptr parseGlobalComplexType(); |
| 342 | |
| 343 | /** |
| 344 | * This method is called for parsing any <em>complexType</em> object as descendant |
| 345 | * of an <em>element</em> object. |
| 346 | */ |
| 347 | XsdComplexType::Ptr parseLocalComplexType(); |
| 348 | |
| 349 | /** |
| 350 | * This method resolves the content type of the @p complexType for the given |
| 351 | * @p effectiveMixed value. |
| 352 | */ |
| 353 | void resolveComplexContentType(const XsdComplexType::Ptr &complexType, bool effectiveMixed); |
| 354 | |
| 355 | /** |
| 356 | * This method is called for parsing a <em>simpleContent</em> object as child |
| 357 | * of a <em>complexType</em> object. |
| 358 | */ |
| 359 | void parseSimpleContent(const XsdComplexType::Ptr &complexType); |
| 360 | |
| 361 | /** |
| 362 | * This method is called for parsing a <em>restriction</em> object as child |
| 363 | * of a <em>simpleContent</em> object. |
| 364 | */ |
| 365 | void parseSimpleContentRestriction(const XsdComplexType::Ptr &complexType); |
| 366 | |
| 367 | /** |
| 368 | * This method is called for parsing an <em>extension</em> object as child |
| 369 | * of a <em>simpleContent</em> object. |
| 370 | */ |
| 371 | void parseSimpleContentExtension(const XsdComplexType::Ptr &complexType); |
| 372 | |
| 373 | /** |
| 374 | * This method is called for parsing a <em>complexContent</em> object as child |
| 375 | * of a <em>complexType</em> object. |
| 376 | * |
| 377 | * @param complexType The complex type the complex content belongs to. |
| 378 | * @param mixed The output parameter for the mixed value. |
| 379 | */ |
| 380 | void parseComplexContent(const XsdComplexType::Ptr &complexType, bool *mixed); |
| 381 | |
| 382 | /** |
| 383 | * This method is called for parsing a <em>restriction</em> object as child |
| 384 | * of a <em>complexContent</em> object. |
| 385 | */ |
| 386 | void parseComplexContentRestriction(const XsdComplexType::Ptr &complexType); |
| 387 | |
| 388 | /** |
| 389 | * This method is called for parsing an <em>extension</em> object as child |
| 390 | * of a <em>complexContent</em> object. |
| 391 | */ |
| 392 | void parseComplexContentExtension(const XsdComplexType::Ptr &complexType); |
| 393 | |
| 394 | /** |
| 395 | * This method is called for parsing an <em>assert</em> object as child |
| 396 | * of a <em>complexType</em> or parsing a <em>assertion</em> facet object as |
| 397 | * child of a <em>simpleType</em>. |
| 398 | * |
| 399 | * @param nodeName Either XsdSchemaToken::Assert or XsdSchemaToken::Assertion. |
| 400 | * @param tag Either XsdTagScope::Assert or XsdTagScope::Assertion. |
| 401 | */ |
| 402 | XsdAssertion::Ptr parseAssertion(const XsdSchemaToken::NodeName &nodeName, const XsdTagScope::Type &tag); |
| 403 | |
| 404 | /** |
| 405 | * This method is called for parsing an <em>openContent</em> object. |
| 406 | */ |
| 407 | XsdComplexType::OpenContent::Ptr parseOpenContent(); |
| 408 | |
| 409 | /** |
| 410 | * This method is called for parsing a top-level <em>group</em> object. |
| 411 | */ |
| 412 | XsdModelGroup::Ptr parseNamedGroup(); |
| 413 | |
| 414 | /** |
| 415 | * This method is called for parsing a non-top-level <em>group</em> object |
| 416 | * that contains a <em>ref</em> attribute. |
| 417 | */ |
| 418 | XsdTerm::Ptr parseReferredGroup(const XsdParticle::Ptr &particle); |
| 419 | |
| 420 | /** |
| 421 | * This method is called for parsing an <em>all</em> object as child |
| 422 | * of a top-level <em>group</em> object. |
| 423 | * |
| 424 | * @param parent The schema component the <em>all</em> object is part of. |
| 425 | */ |
| 426 | XsdModelGroup::Ptr parseAll(const NamedSchemaComponent::Ptr &parent); |
| 427 | |
| 428 | /** |
| 429 | * This method is called for parsing an <em>all</em> object as descendant |
| 430 | * of a <em>complexType</em> object. |
| 431 | * |
| 432 | * @param particle The particle the <em>all</em> object belongs to. |
| 433 | * @param parent The schema component the <em>all</em> object is part of. |
| 434 | */ |
| 435 | XsdModelGroup::Ptr parseLocalAll(const XsdParticle::Ptr &particle, const NamedSchemaComponent::Ptr &parent); |
| 436 | |
| 437 | /** |
| 438 | * This method is called for parsing a <em>choice</em> object as child |
| 439 | * of a top-level <em>group</em> object. |
| 440 | * |
| 441 | * @param parent The schema component the <em>choice</em> object is part of. |
| 442 | */ |
| 443 | XsdModelGroup::Ptr parseChoice(const NamedSchemaComponent::Ptr &parent); |
| 444 | |
| 445 | /** |
| 446 | * This method is called for parsing a <em>choice</em> object as descendant |
| 447 | * of a <em>complexType</em> object or a <em>choice</em> object. |
| 448 | * |
| 449 | * @param particle The particle the <em>choice</em> object belongs to. |
| 450 | * @param parent The schema component the <em>choice</em> object is part of. |
| 451 | */ |
| 452 | XsdModelGroup::Ptr parseLocalChoice(const XsdParticle::Ptr &particle, const NamedSchemaComponent::Ptr &parent); |
| 453 | |
| 454 | /** |
| 455 | * This method is called for parsing a <em>sequence</em> object as child |
| 456 | * of a top-level <em>group</em> object. |
| 457 | * |
| 458 | * @param parent The schema component the <em>sequence</em> object is part of. |
| 459 | */ |
| 460 | XsdModelGroup::Ptr parseSequence(const NamedSchemaComponent::Ptr &parent); |
| 461 | |
| 462 | /** |
| 463 | * This method is called for parsing a <em>sequence</em> object as descendant |
| 464 | * of a <em>complexType</em> object or a <em>sequence</em> object. |
| 465 | * |
| 466 | * @param particle The particle the <em>sequence</em> object belongs to. |
| 467 | * @param parent The schema component the <em>sequence</em> object is part of. |
| 468 | */ |
| 469 | XsdModelGroup::Ptr parseLocalSequence(const XsdParticle::Ptr &particle, const NamedSchemaComponent::Ptr &parent); |
| 470 | |
| 471 | /** |
| 472 | * A helper method that parses the minOccurs and maxOccurs constraints for |
| 473 | * the given @p particle that has the given @p tagName. |
| 474 | */ |
| 475 | bool parseMinMaxConstraint(const XsdParticle::Ptr &particle, const char* tagName); |
| 476 | |
| 477 | /** |
| 478 | * This method is called for parsing any top-level <em>attribute</em> object. |
| 479 | */ |
| 480 | XsdAttribute::Ptr parseGlobalAttribute(); |
| 481 | |
| 482 | /** |
| 483 | * This method is called for parsing any non-top-level <em>attribute</em> object as a |
| 484 | * descendant of a <em>complexType</em> object or an <em>attributeGroup</em> object. |
| 485 | * |
| 486 | * @param parent The parent component the <em>attribute</em> object is part of. |
| 487 | */ |
| 488 | XsdAttributeUse::Ptr parseLocalAttribute(const NamedSchemaComponent::Ptr &parent); |
| 489 | |
| 490 | /** |
| 491 | * This method is called for parsing a top-level <em>attributeGroup</em> object. |
| 492 | */ |
| 493 | XsdAttributeGroup::Ptr parseNamedAttributeGroup(); |
| 494 | |
| 495 | /** |
| 496 | * This method is called for parsing a non-top-level <em>attributeGroup</em> object |
| 497 | * that contains a <em>ref</em> attribute. |
| 498 | */ |
| 499 | XsdAttributeUse::Ptr parseReferredAttributeGroup(); |
| 500 | |
| 501 | /** |
| 502 | * This method is called for parsing any top-level <em>element</em> object. |
| 503 | */ |
| 504 | XsdElement::Ptr parseGlobalElement(); |
| 505 | |
| 506 | /** |
| 507 | * This method is called for parsing any non-top-level <em>element</em> object as a |
| 508 | * descendant of a <em>complexType</em> object or a <em>group</em> object. |
| 509 | * |
| 510 | * @param particle The particle the <em>element</em> object belongs to. |
| 511 | * @param parent The parent component the <em>element</em> object is part of. |
| 512 | */ |
| 513 | XsdTerm::Ptr parseLocalElement(const XsdParticle::Ptr &particle, const NamedSchemaComponent::Ptr &parent); |
| 514 | |
| 515 | /** |
| 516 | * This method is called for parsing a <em>unique</em> object as child of an <em>element</em> object. |
| 517 | */ |
| 518 | XsdIdentityConstraint::Ptr parseUnique(); |
| 519 | |
| 520 | /** |
| 521 | * This method is called for parsing a <em>key</em> object as child of an <em>element</em> object. |
| 522 | */ |
| 523 | XsdIdentityConstraint::Ptr parseKey(); |
| 524 | |
| 525 | /** |
| 526 | * This method is called for parsing a <em>keyref</em> object as child of an <em>element</em> object. |
| 527 | */ |
| 528 | XsdIdentityConstraint::Ptr parseKeyRef(const XsdElement::Ptr &element); |
| 529 | |
| 530 | /** |
| 531 | * This method is called for parsing a <em>selector</em> object as child of an <em>unique</em> object, |
| 532 | * <em>key</em> object or <em>keyref</em> object, |
| 533 | * |
| 534 | * @param ptr The identity constraint it belongs to. |
| 535 | */ |
| 536 | void parseSelector(const XsdIdentityConstraint::Ptr &ptr); |
| 537 | |
| 538 | /** |
| 539 | * This method is called for parsing a <em>field</em> object as child of an <em>unique</em> object, |
| 540 | * <em>key</em> object or <em>keyref</em> object, |
| 541 | * |
| 542 | * @param ptr The identity constraint it belongs to. |
| 543 | */ |
| 544 | void parseField(const XsdIdentityConstraint::Ptr &ptr); |
| 545 | |
| 546 | /** |
| 547 | * This method is called for parsing an <em>alternative</em> object inside an <em>element</em> object. |
| 548 | */ |
| 549 | XsdAlternative::Ptr parseAlternative(); |
| 550 | |
| 551 | /** |
| 552 | * This method is called for parsing a top-level <em>notation</em> object. |
| 553 | */ |
| 554 | XsdNotation::Ptr parseNotation(); |
| 555 | |
| 556 | /** |
| 557 | * This method is called for parsing an <em>any</em> object somewhere in |
| 558 | * the schema. |
| 559 | * |
| 560 | * @param particle The particle the <em>any</em> object belongs to. |
| 561 | */ |
| 562 | XsdWildcard::Ptr parseAny(const XsdParticle::Ptr &particle); |
| 563 | |
| 564 | /** |
| 565 | * This method is called for parsing an <em>anyAttribute</em> object somewhere in |
| 566 | * the schema. |
| 567 | */ |
| 568 | XsdWildcard::Ptr parseAnyAttribute(); |
| 569 | |
| 570 | /** |
| 571 | * This method is called for parsing unknown object as descendant of the <em>annotation</em> object. |
| 572 | */ |
| 573 | void parseUnknownDocumentation(); |
| 574 | |
| 575 | /** |
| 576 | * This method is called for parsing unknown object in the schema. |
| 577 | */ |
| 578 | void parseUnknown(); |
| 579 | |
| 580 | /** |
| 581 | * Returnes an source location for the current position. |
| 582 | */ |
| 583 | QSourceLocation currentSourceLocation() const; |
| 584 | |
| 585 | /** |
| 586 | * Converts a @p qualified name into a QXmlName @p name and does some error handling. |
| 587 | */ |
| 588 | void convertName(const QString &qualified, NamespaceSupport::NameType type, QXmlName &name); |
| 589 | |
| 590 | /** |
| 591 | * A helper method that reads in a 'name' attribute and checks it for syntactic errors. |
| 592 | */ |
| 593 | inline QString readNameAttribute(const char *elementName); |
| 594 | |
| 595 | /** |
| 596 | * A helper method that reads in an attribute that contains an QName and |
| 597 | * checks it for syntactic errors. |
| 598 | */ |
| 599 | inline QString readQNameAttribute(const QString &typeAttribute, const char *elementName); |
| 600 | |
| 601 | /** |
| 602 | * A helper method that reads in a namespace attribute and checks for syntactic errors. |
| 603 | */ |
| 604 | inline QString readNamespaceAttribute(const QString &attributeName, const char *elementName); |
| 605 | |
| 606 | /** |
| 607 | * A helper method that reads the final attribute and does correct handling of schema default definitions. |
| 608 | */ |
| 609 | inline SchemaType::DerivationConstraints readDerivationConstraintAttribute(const SchemaType::DerivationConstraints &allowedConstraints, const char *elementName); |
| 610 | |
| 611 | /** |
| 612 | * A helper method that reads the block attribute and does correct handling of schema default definitions. |
| 613 | */ |
| 614 | inline NamedSchemaComponent::BlockingConstraints readBlockingConstraintAttribute(const NamedSchemaComponent::BlockingConstraints &allowedConstraints, const char *elementName); |
| 615 | |
| 616 | /** |
| 617 | * A helper method that reads all components for a xpath expression for the current scope. |
| 618 | */ |
| 619 | XsdXPathExpression::Ptr readXPathExpression(const char *elementName); |
| 620 | |
| 621 | /** |
| 622 | * Describes the type of XPath that is allowed by the readXPathAttribute method. |
| 623 | */ |
| 624 | enum XPathType { |
| 625 | XPath20, |
| 626 | XPathSelector, |
| 627 | XPathField |
| 628 | }; |
| 629 | |
| 630 | /** |
| 631 | * A helper method that reads an attribute that represents a xpath query and does basic |
| 632 | * validation. |
| 633 | */ |
| 634 | QString readXPathAttribute(const QString &attributeName, XPathType type, const char *elementName); |
| 635 | |
| 636 | /** |
| 637 | * A helper method that reads in an "id" attribute, checks it for syntactic errors |
| 638 | * and tests whether a component with the same id has already been parsed. |
| 639 | */ |
| 640 | inline void validateIdAttribute(const char *elementName); |
| 641 | |
| 642 | /** |
| 643 | * Adds an @p element to the schema and checks for duplicated entries. |
| 644 | */ |
| 645 | void addElement(const XsdElement::Ptr &element); |
| 646 | |
| 647 | /** |
| 648 | * Adds an @p attribute to the schema and checks for duplicated entries. |
| 649 | */ |
| 650 | void addAttribute(const XsdAttribute::Ptr &attribute); |
| 651 | |
| 652 | /** |
| 653 | * Adds a @p type to the schema and checks for duplicated entries. |
| 654 | */ |
| 655 | void addType(const SchemaType::Ptr &type); |
| 656 | |
| 657 | /** |
| 658 | * Adds an anonymous @p type to the schema and checks for duplicated entries. |
| 659 | */ |
| 660 | void addAnonymousType(const SchemaType::Ptr &type); |
| 661 | |
| 662 | /** |
| 663 | * Adds an attribute @p group to the schema and checks for duplicated entries. |
| 664 | */ |
| 665 | void addAttributeGroup(const XsdAttributeGroup::Ptr &group); |
| 666 | |
| 667 | /** |
| 668 | * Adds an element @p group to the schema and checks for duplicated entries. |
| 669 | */ |
| 670 | void addElementGroup(const XsdModelGroup::Ptr &group); |
| 671 | |
| 672 | /** |
| 673 | * Adds a @p notation to the schema and checks for duplicated entries. |
| 674 | */ |
| 675 | void addNotation(const XsdNotation::Ptr ¬ation); |
| 676 | |
| 677 | /** |
| 678 | * Adds an identity @p constraint to the schema and checks for duplicated entries. |
| 679 | */ |
| 680 | void addIdentityConstraint(const XsdIdentityConstraint::Ptr &constraint); |
| 681 | |
| 682 | /** |
| 683 | * Adds the @p facet to the list of @p facets for @p type and checks for duplicates. |
| 684 | */ |
| 685 | void addFacet(const XsdFacet::Ptr &facet, XsdFacet::Hash &facets, const SchemaType::Ptr &type); |
| 686 | |
| 687 | /** |
| 688 | * Sets up the state machines for validating the right occurrence of xml elements. |
| 689 | */ |
| 690 | void setupStateMachines(); |
| 691 | |
| 692 | /** |
| 693 | * Sets up a list of names of known builtin types. |
| 694 | */ |
| 695 | void setupBuiltinTypeNames(); |
| 696 | |
| 697 | /** |
| 698 | * Checks whether the given @p tag is equal to the given @p token and |
| 699 | * the given @p namespaceToken is the XML Schema namespace. |
| 700 | */ |
| 701 | inline bool isSchemaTag(XsdSchemaToken::NodeName tag, XsdSchemaToken::NodeName token, XsdSchemaToken::NodeName namespaceToken) const; |
| 702 | |
| 703 | XsdSchemaContext::Ptr m_context; |
| 704 | XsdSchemaParserContext::Ptr m_parserContext; |
| 705 | NamePool::Ptr m_namePool; |
| 706 | NamespaceSupport m_namespaceSupport; |
| 707 | XsdSchemaResolver::Ptr m_schemaResolver; |
| 708 | XsdSchema::Ptr m_schema; |
| 709 | |
| 710 | QString m_targetNamespace; |
| 711 | QString m_attributeFormDefault; |
| 712 | QString m_elementFormDefault; |
| 713 | QString m_blockDefault; |
| 714 | QString m_finalDefault; |
| 715 | QString m_xpathDefaultNamespace; |
| 716 | QXmlName m_defaultAttributes; |
| 717 | XsdComplexType::OpenContent::Ptr m_defaultOpenContent; |
| 718 | bool m_defaultOpenContentAppliesToEmpty; |
| 719 | |
| 720 | NamespaceSet m_includedSchemas; |
| 721 | NamespaceSet m_importedSchemas; |
| 722 | NamespaceSet m_redefinedSchemas; |
| 723 | QUrl m_documentURI; |
| 724 | XsdIdCache::Ptr m_idCache; |
| 725 | QHash<XsdTagScope::Type, XsdStateMachine<XsdSchemaToken::NodeName> > m_stateMachines; |
| 726 | ComponentLocationHash m_componentLocationHash; |
| 727 | QSet<QXmlName> m_builtinTypeNames; |
| 728 | }; |
| 729 | } |
| 730 | |
| 731 | QT_END_NAMESPACE |
| 732 | |
| 733 | #endif |
| 734 | |