Qt 4.8
qxsdschemaparser_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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_XsdSchemaParser_H
53 #define Patternist_XsdSchemaParser_H
54 
55 #include "qnamespacesupport_p.h"
56 #include "qxsdalternative_p.h"
57 #include "qxsdattribute_p.h"
58 #include "qxsdattributegroup_p.h"
59 #include "qxsdattributeterm_p.h"
60 #include "qxsdcomplextype_p.h"
61 #include "qxsdelement_p.h"
62 #include "qxsdidcache_p.h"
63 #include "qxsdmodelgroup_p.h"
64 #include "qxsdnotation_p.h"
65 #include "qxsdsimpletype_p.h"
66 #include "qxsdschemacontext_p.h"
68 #include "qxsdstatemachine_p.h"
69 
70 #include <QtCore/QHash>
71 #include <QtCore/QSet>
72 #include <QtCore/QUrl>
73 #include <QtXml/QXmlStreamReader>
74 #include <QtXmlPatterns/QXmlNamePool>
75 
77 
79 
80 namespace QPatternist
81 {
91  class XsdSchemaParser : public MaintainingReader<XsdSchemaToken, XsdTagScope::Type>
92  {
94  friend class TagValidationHandler;
95 
96  public:
98  {
103  };
104 
108  XsdSchemaParser(const XsdSchemaContext::Ptr &context, const XsdSchemaParserContext::Ptr &parserContext, QIODevice *device);
109 
115  bool parse(ParserType parserType = TopLevelParser);
116 
121 
126  void addIncludedSchemas(const NamespaceSet &schemas);
127 
132  void setIncludedSchemas(const NamespaceSet &schemas);
133 
138  void addImportedSchemas(const NamespaceSet &schemas);
139 
144  void setImportedSchemas(const NamespaceSet &schemas);
145 
150  void addRedefinedSchemas(const NamespaceSet &schemas);
151 
156  void setRedefinedSchemas(const NamespaceSet &schemas);
157 
161  void setTargetNamespace(const QString &targetNamespace);
162 
166  void setDocumentURI(const QUrl &uri);
167 
171  QUrl documentURI() const;
172 
176  bool isAnyAttributeAllowed() const;
177 
178  private:
183  virtual void error(const QString &msg);
184 
185  void attributeContentError(const char *attributeName, const char *elementName, const QString &value, const SchemaType::Ptr &type = SchemaType::Ptr());
186 
190  void setTargetNamespaceExtended(const QString &targetNamespace);
191 
195  void parseSchema(ParserType parserType);
196 
200  void parseInclude();
201 
205  void parseImport();
206 
210  void parseRedefine();
211 
217 
223 
229 
234 
239 
245 
251 
256  void parseList(const XsdSimpleType::Ptr &ptr);
257 
262  void parseUnion(const XsdSimpleType::Ptr &ptr);
263 
269 
275 
281 
287 
293 
299 
305 
311 
317 
323 
329 
335 
341 
346 
352 
357  void resolveComplexContentType(const XsdComplexType::Ptr &complexType, bool effectiveMixed);
358 
363  void parseSimpleContent(const XsdComplexType::Ptr &complexType);
364 
369  void parseSimpleContentRestriction(const XsdComplexType::Ptr &complexType);
370 
375  void parseSimpleContentExtension(const XsdComplexType::Ptr &complexType);
376 
384  void parseComplexContent(const XsdComplexType::Ptr &complexType, bool *mixed);
385 
390  void parseComplexContentRestriction(const XsdComplexType::Ptr &complexType);
391 
396  void parseComplexContentExtension(const XsdComplexType::Ptr &complexType);
397 
407 
412 
417 
423 
431 
440 
448 
457 
465 
474 
479  bool parseMinMaxConstraint(const XsdParticle::Ptr &particle, const char* tagName);
480 
485 
493 
498 
504 
509 
518 
523 
528 
533 
541 
549 
554 
559 
566  XsdWildcard::Ptr parseAny(const XsdParticle::Ptr &particle);
567 
573 
578 
582  void parseUnknown();
583 
588 
593 
597  inline QString readNameAttribute(const char *elementName);
598 
603  inline QString readQNameAttribute(const QString &typeAttribute, const char *elementName);
604 
608  inline QString readNamespaceAttribute(const QString &attributeName, const char *elementName);
609 
613  inline SchemaType::DerivationConstraints readDerivationConstraintAttribute(const SchemaType::DerivationConstraints &allowedConstraints, const char *elementName);
614 
618  inline NamedSchemaComponent::BlockingConstraints readBlockingConstraintAttribute(const NamedSchemaComponent::BlockingConstraints &allowedConstraints, const char *elementName);
619 
623  XsdXPathExpression::Ptr readXPathExpression(const char *elementName);
624 
628  enum XPathType {
632  };
633 
638  QString readXPathAttribute(const QString &attributeName, XPathType type, const char *elementName);
639 
644  inline void validateIdAttribute(const char *elementName);
645 
649  void addElement(const XsdElement::Ptr &element);
650 
654  void addAttribute(const XsdAttribute::Ptr &attribute);
655 
659  void addType(const SchemaType::Ptr &type);
660 
665 
669  void addAttributeGroup(const XsdAttributeGroup::Ptr &group);
670 
674  void addElementGroup(const XsdModelGroup::Ptr &group);
675 
679  void addNotation(const XsdNotation::Ptr &notation);
680 
684  void addIdentityConstraint(const XsdIdentityConstraint::Ptr &constraint);
685 
689  void addFacet(const XsdFacet::Ptr &facet, XsdFacet::Hash &facets, const SchemaType::Ptr &type);
690 
694  void setupStateMachines();
695 
699  void setupBuiltinTypeNames();
700 
705  inline bool isSchemaTag(XsdSchemaToken::NodeName tag, XsdSchemaToken::NodeName token, XsdSchemaToken::NodeName namespaceToken) const;
706 
713 
723 
724  NamespaceSet m_includedSchemas;
725  NamespaceSet m_importedSchemas;
726  NamespaceSet m_redefinedSchemas;
732  };
733 }
734 
736 
738 
739 #endif
Error error() const
Returns the type of the current error, or NoError if no error occurred.
XsdSchemaParser(const XsdSchemaContext::Ptr &context, const XsdSchemaParserContext::Ptr &parserContext, QIODevice *device)
XsdTerm::Ptr parseLocalElement(const XsdParticle::Ptr &particle, const NamedSchemaComponent::Ptr &parent)
void addType(const SchemaType::Ptr &type)
XsdModelGroup::Ptr parseLocalSequence(const XsdParticle::Ptr &particle, const NamedSchemaComponent::Ptr &parent)
XsdWildcard::Ptr parseAnyAttribute()
void addAttribute(const XsdAttribute::Ptr &attribute)
int type
Definition: qmetatype.cpp:239
A context for schema parsing and validation.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void parseSchema(ParserType parserType)
XsdAttribute::Ptr parseGlobalAttribute()
void parseSelector(const XsdIdentityConstraint::Ptr &ptr)
void addIdentityConstraint(const XsdIdentityConstraint::Ptr &constraint)
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
XsdTerm::Ptr parseReferredGroup(const XsdParticle::Ptr &particle)
void parseComplexContentExtension(const XsdComplexType::Ptr &complexType)
void parseList(const XsdSimpleType::Ptr &ptr)
XsdAnnotation::Ptr parseAnnotation()
Store names such as namespace bindings and QNames and allows them to be referenced in efficient ways...
Definition: qnamepool_p.h:87
QString readXPathAttribute(const QString &attributeName, XPathType type, const char *elementName)
XsdModelGroup::Ptr parseChoice(const NamedSchemaComponent::Ptr &parent)
XsdIdentityConstraint::Ptr parseKey()
XsdComplexType::OpenContent::Ptr parseOpenContent()
void parseSimpleContent(const XsdComplexType::Ptr &complexType)
XsdComplexType::Ptr parseLocalComplexType()
void validateIdAttribute(const char *elementName)
XsdDocumentation::Ptr parseDocumentation()
Represents a XSD schema object.
Definition: qxsdschema_p.h:91
QStringRef name() const
Returns the local name of a StartElement, EndElement, or an EntityReference.
NamedSchemaComponent::BlockingConstraints readBlockingConstraintAttribute(const NamedSchemaComponent::BlockingConstraints &allowedConstraints, const char *elementName)
void resolveComplexContentType(const XsdComplexType::Ptr &complexType, bool effectiveMixed)
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
QSourceLocation currentSourceLocation() const
XsdSchemaParserContext * m_parserContext
XsdIdentityConstraint::Ptr parseKeyRef(const XsdElement::Ptr &element)
XsdAttributeUse::Ptr parseLocalAttribute(const NamedSchemaComponent::Ptr &parent)
void addIncludedSchemas(const NamespaceSet &schemas)
void addElement(const XsdElement::Ptr &element)
void parseComplexContent(const XsdComplexType::Ptr &complexType, bool *mixed)
XsdAttributeUse::Ptr parseReferredAttributeGroup()
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void addImportedSchemas(const NamespaceSet &schemas)
ComponentLocationHash m_componentLocationHash
Encapsulates the resolving of type/element references in a schema after parsing has finished...
XsdComplexType::OpenContent::Ptr m_defaultOpenContent
void parseSimpleContentExtension(const XsdComplexType::Ptr &complexType)
A helper class for automatically handling namespace scopes of elements.
bool parseMinMaxConstraint(const XsdParticle::Ptr &particle, const char *tagName)
void setTargetNamespaceExtended(const QString &targetNamespace)
QString readQNameAttribute(const QString &typeAttribute, const char *elementName)
void setIncludedSchemas(const NamespaceSet &schemas)
The namespace for the internal API of QtXmlPatterns.
XsdApplicationInformation::Ptr parseAppInfo()
The QSourceLocation class identifies a location in a resource by URI, line, and column.
const T * ptr(const T &t)
void addRedefinedSchemas(const NamespaceSet &schemas)
void setDocumentURI(const QUrl &uri)
A helper class for handling nested namespace declarations.
Base class for tokenizers that reads XML formats. This is XSLTTokenizer, and the W3C XML Schema parse...
QIODevice * device() const
Returns the current device associated with the QXmlStreamReader, or 0 if no device has been assigned...
Definition: qxmlstream.cpp:507
QHash< XsdTagScope::Type, XsdStateMachine< XsdSchemaToken::NodeName > > m_stateMachines
void addElementGroup(const XsdModelGroup::Ptr &group)
XsdAttributeGroup::Ptr parseNamedAttributeGroup()
XsdModelGroup::Ptr parseNamedGroup()
XsdComplexType::Ptr parseGlobalComplexType()
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
void setRedefinedSchemas(const NamespaceSet &schemas)
XsdSimpleType::Ptr parseGlobalSimpleType()
QString readNameAttribute(const char *elementName)
XsdAlternative::Ptr parseAlternative()
void parseComplexContentRestriction(const XsdComplexType::Ptr &complexType)
Implements the parsing of XML schema file.
void convertName(const QString &qualified, NamespaceSupport::NameType type, QXmlName &name)
XsdWildcard::Ptr parseAny(const XsdParticle::Ptr &particle)
XsdAssertion::Ptr parseAssertion(const XsdSchemaToken::NodeName &nodeName, const XsdTagScope::Type &tag)
void addAnonymousType(const SchemaType::Ptr &type)
XsdModelGroup::Ptr parseAll(const NamedSchemaComponent::Ptr &parent)
void addFacet(const XsdFacet::Ptr &facet, XsdFacet::Hash &facets, const SchemaType::Ptr &type)
void attributeContentError(const char *attributeName, const char *elementName, const QString &value, const SchemaType::Ptr &type=SchemaType::Ptr())
void setImportedSchemas(const NamespaceSet &schemas)
bool parse(ParserType parserType=TopLevelParser)
void parseSimpleRestriction(const XsdSimpleType::Ptr &ptr)
void parseSimpleContentRestriction(const XsdComplexType::Ptr &complexType)
XsdModelGroup::Ptr parseSequence(const NamedSchemaComponent::Ptr &parent)
XsdSchemaResolver * m_schemaResolver
void addNotation(const XsdNotation::Ptr &notation)
XsdSimpleType::Ptr parseLocalSimpleType()
QString readNamespaceAttribute(const QString &attributeName, const char *elementName)
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
void parseUnion(const XsdSimpleType::Ptr &ptr)
XsdXPathExpression::Ptr readXPathExpression(const char *elementName)
void addAttributeGroup(const XsdAttributeGroup::Ptr &group)
void parseField(const XsdIdentityConstraint::Ptr &ptr)
#define QT_END_HEADER
Definition: qglobal.h:137
SchemaType::DerivationConstraints readDerivationConstraintAttribute(const SchemaType::DerivationConstraints &allowedConstraints, const char *elementName)
XsdModelGroup::Ptr parseLocalAll(const XsdParticle::Ptr &particle, const NamedSchemaComponent::Ptr &parent)
bool isSchemaTag(XsdSchemaToken::NodeName tag, XsdSchemaToken::NodeName token, XsdSchemaToken::NodeName namespaceToken) const
XsdIdentityConstraint::Ptr parseUnique()
XsdModelGroup::Ptr parseLocalChoice(const XsdParticle::Ptr &particle, const NamedSchemaComponent::Ptr &parent)
void setTargetNamespace(const QString &targetNamespace)