Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
[qt-netbsd.git] / src / xmlpatterns / schema / qxsdschemaresolver_p.h
blobef0154bdb3d4cad602c1c21ce25e1ec805ef5405
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 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
43 // W A R N I N G
44 // -------------
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.
50 // We mean it.
52 #ifndef Patternist_XsdSchemaResolver_H
53 #define Patternist_XsdSchemaResolver_H
55 #include "qnamespacesupport_p.h"
56 #include "qschematype_p.h"
57 #include "qschematypefactory_p.h"
58 #include "qxsdalternative_p.h"
59 #include "qxsdattribute_p.h"
60 #include "qxsdattributegroup_p.h"
61 #include "qxsdelement_p.h"
62 #include "qxsdmodelgroup_p.h"
63 #include "qxsdnotation_p.h"
64 #include "qxsdreference_p.h"
65 #include "qxsdschema_p.h"
66 #include "qxsdschemachecker_p.h"
67 #include "qxsdsimpletype_p.h"
69 #include <QtCore/QExplicitlySharedDataPointer>
71 QT_BEGIN_HEADER
73 QT_BEGIN_NAMESPACE
75 namespace QPatternist
77 class XsdSchemaContext;
78 class XsdSchemaParserContext;
80 /**
81 * @short Encapsulates the resolving of type/element references in a schema after parsing has finished.
83 * This class collects task for resolving types or element references. After the parsing has finished,
84 * one can start the resolve process by calling resolve().
86 * @ingroup Patternist_schema
87 * @author Tobias Koenig <tobias.koenig@nokia.com>
89 class XsdSchemaResolver : public QSharedData
91 public:
92 typedef QExplicitlySharedDataPointer<XsdSchemaResolver> Ptr;
94 /**
95 * Creates a new schema resolver.
97 * @param context The schema context used for error reporting etc..
98 * @param parserContext The schema parser context where all objects to resolve belong to.
100 XsdSchemaResolver(const QExplicitlySharedDataPointer<XsdSchemaContext> &context, const XsdSchemaParserContext *parserContext);
103 * Destroys the schema resolver.
105 ~XsdSchemaResolver();
108 * Starts the resolve process.
110 void resolve();
113 * Adds a resolve task for key references.
115 * The resolver will try to set the referencedKey property of @p keyRef to the <em>key</em> or <em>unique</em> object
116 * of @p element that has the given @p name.
118 void addKeyReference(const XsdElement::Ptr &element, const XsdIdentityConstraint::Ptr &keyRef, const QXmlName &name, const QSourceLocation &location);
121 * Adds a resolve task for the base type of restriction of a simple type.
123 * The resolver will set the base type of @p simpleType to the type named by @p baseName.
125 void addSimpleRestrictionBase(const XsdSimpleType::Ptr &simpleType, const QXmlName &baseName, const QSourceLocation &location);
128 * Removes the resolve task for the base type of restriction of the simple @p type.
130 void removeSimpleRestrictionBase(const XsdSimpleType::Ptr &type);
133 * Adds a resolve task for the list type of a simple type.
135 * The resolver will set the itemType property of @p simpleType to the type named by @p typeName.
137 void addSimpleListType(const XsdSimpleType::Ptr &simpleType, const QXmlName &typeName, const QSourceLocation &location);
140 * Adds a resolve task for the member types of a simple type.
142 * The resolver will set the memberTypes property of @p simpleType to the types named by @p typeNames.
144 void addSimpleUnionTypes(const XsdSimpleType::Ptr &simpleType, const QList<QXmlName> &typeNames, const QSourceLocation &location);
147 * Adds a resolve task for the type of an element.
149 * The resolver will set the type of the @p element to the type named by @p typeName.
151 void addElementType(const XsdElement::Ptr &element, const QXmlName &typeName, const QSourceLocation &location);
154 * Adds a resolve task for the base type of a complex type.
156 * The resolver will set the base type of @p complexType to the type named by @p baseName.
158 void addComplexBaseType(const XsdComplexType::Ptr &complexType, const QXmlName &baseName, const QSourceLocation &location, const XsdFacet::Hash &facets = XsdFacet::Hash());
161 * Removes the resolve task for the base type of the complex @p type.
163 void removeComplexBaseType(const XsdComplexType::Ptr &type);
166 * Adds a resolve task for the content type of a complex type.
168 * The resolver will set the content type properties for @p complexType based on the
169 * given explicit @p content and effective @p mixed value.
171 void addComplexContentType(const XsdComplexType::Ptr &complexType, const XsdParticle::Ptr &content, bool mixed);
174 * Adds a resolve task for the type of an attribute.
176 * The resolver will set the type of the @p attribute to the type named by @p typeName.
178 void addAttributeType(const XsdAttribute::Ptr &attribute, const QXmlName &typeName, const QSourceLocation &location);
181 * Adds a resolve task for the type of an alternative.
183 * The resolver will set the type of the @p alternative to the type named by @p typeName.
185 void addAlternativeType(const XsdAlternative::Ptr &alternative, const QXmlName &typeName, const QSourceLocation &location);
188 * Adds a resolve task for the type of an alternative.
190 * The resolver will set the type of the @p alternative to the type of the @p element after
191 * the type of the @p element has been resolved.
193 void addAlternativeType(const XsdAlternative::Ptr &alternative, const XsdElement::Ptr &element);
196 * Adds a resolve task for the substituion group affiliations of an element.
198 * The resolver will set the substitution group affiliations of the @p element to the
199 * top-level element named by @p elementNames.
201 void addSubstitutionGroupAffiliation(const XsdElement::Ptr &element, const QList<QXmlName> &elementName, const QSourceLocation &location);
204 * Adds a resolve task for an element that has no type specified, only a substitution group
205 * affiliation.
207 * The resolver will set the type of the substitution group affiliation as type for the element.
209 void addSubstitutionGroupType(const XsdElement::Ptr &element);
212 * Adds the component location hash, so the resolver is able to report meaning full
213 * error messages.
215 void addComponentLocationHash(const QHash<NamedSchemaComponent::Ptr, QSourceLocation> &hash);
218 * Add a resolve task for enumeration facet values.
220 * In case the enumeration is of type QName or NOTATION, we have to resolve the QName later,
221 * so we store the namespace bindings together with the facet value here and resolve it as soon as
222 * we have all type information available.
224 void addEnumerationFacetValue(const AtomicValue::Ptr &facetValue, const NamespaceSupport &namespaceSupport);
227 * Add a check job for redefined groups.
229 * When an element group is redefined, we have to check whether the redefined group is a valid
230 * restriction of the group it redefines. As we need all type information for that, we keep them
231 * here for later checking.
233 void addRedefinedGroups(const XsdModelGroup::Ptr &redefinedGroup, const XsdModelGroup::Ptr &group);
236 * Add a check job for redefined attribute groups.
238 * When an attribute group is redefined, we have to check whether the redefined group is a valid
239 * restriction of the group it redefines. As we need all type information for that, we keep them
240 * here for later checking.
242 void addRedefinedAttributeGroups(const XsdAttributeGroup::Ptr &redefinedGroup, const XsdAttributeGroup::Ptr &group);
245 * Adds a check for nested <em>all</em> groups.
247 void addAllGroupCheck(const XsdReference::Ptr &reference);
250 * Copies the data to resolve to an @p other resolver.
252 * @note That functionality is only used by the redefine algorithm in the XsdSchemaParser.
254 void copyDataTo(const XsdSchemaResolver::Ptr &other) const;
257 * Returns the to resolve base type name for the given @p type.
259 * @note That functionality is only used by the redefine algorithm in the XsdSchemaParser.
261 QXmlName baseTypeNameOfType(const SchemaType::Ptr &type) const;
264 * Returns the to resolve type name for the given @p attribute.
266 * @note That functionality is only used by the redefine algorithm in the XsdSchemaParser.
268 QXmlName typeNameOfAttribute(const XsdAttribute::Ptr &attribute) const;
271 * Sets the defaultOpenContent object from the schema parser.
273 void setDefaultOpenContent(const XsdComplexType::OpenContent::Ptr &openContent, bool appliesToEmpty);
275 private:
277 * Resolves key references.
279 void resolveKeyReferences();
282 * Resolves the base types of simple types derived by restriction.
284 void resolveSimpleRestrictionBaseTypes();
287 * Resolves the other properties except the base type
288 * of all simple restrictions.
290 void resolveSimpleRestrictions();
293 * Resolves the other properties except the base type
294 * of the given simple restriction.
296 * @param simpleType The restricted type to resolve.
297 * @param visitedTypes A set of already resolved types, used for termination of recursion.
299 void resolveSimpleRestrictions(const XsdSimpleType::Ptr &simpleType, QSet<XsdSimpleType::Ptr> &visitedTypes);
302 * Resolves the item type property of simple types derived by list.
304 void resolveSimpleListType();
307 * Resolves the member types property of simple types derived by union.
309 void resolveSimpleUnionTypes();
312 * Resolves element types.
314 void resolveElementTypes();
317 * Resolves base type of complex types.
319 void resolveComplexBaseTypes();
322 * Resolves the simple content model of a complex type
323 * depending on its base type.
325 void resolveSimpleContentComplexTypes();
328 * Resolves the complex content model of a complex type
329 * depending on its base type.
331 void resolveComplexContentComplexTypes();
334 * Resolves the simple content model of a complex type
335 * depending on its base type.
337 * @param complexType The complex type to resolve.
338 * @param visitedTypes A set of already resolved types, used for termination of recursion.
340 void resolveSimpleContentComplexTypes(const XsdComplexType::Ptr &complexType, QSet<XsdComplexType::Ptr> &visitedTypes);
343 * Resolves the complex content model of a complex type
344 * depending on its base type.
346 * @param complexType The complex type to resolve.
347 * @param visitedTypes A set of already resolved types, used for termination of recursion.
349 void resolveComplexContentComplexTypes(const XsdComplexType::Ptr &complexType, QSet<XsdComplexType::Ptr> &visitedTypes);
352 * Resolves attribute types.
354 void resolveAttributeTypes();
357 * Resolves alternative types.
359 void resolveAlternativeTypes();
362 * Resolves substitution group affiliations.
364 void resolveSubstitutionGroupAffiliations();
367 * Resolves substitution groups.
369 void resolveSubstitutionGroups();
372 * Resolves all XsdReferences in the schema by their corresponding XsdElement or XsdModelGroup terms.
374 void resolveTermReferences();
377 * Resolves all XsdReferences in the @p particle recursive by their corresponding XsdElement or XsdModelGroup terms.
379 void resolveTermReference(const XsdParticle::Ptr &particle, QSet<QXmlName> visitedGroups);
382 * Resolves all XsdAttributeReferences in the schema by their corresponding XsdAttributeUse objects.
384 void resolveAttributeTermReferences();
387 * Resolves all XsdAttributeReferences in the list of @p attributeUses by their corresponding XsdAttributeUse objects.
389 XsdAttributeUse::List resolveAttributeTermReferences(const XsdAttributeUse::List &attributeUses, XsdWildcard::Ptr &wildcard, QSet<QXmlName> visitedAttributeGroups);
392 * Resolves the attribute inheritance of complex types.
394 * @note This method must be called after all base types have been resolved.
396 void resolveAttributeInheritance();
399 * Resolves the attribute inheritance of the given complex types.
401 * @param complexType The complex type to resolve.
402 * @param visitedTypes A set of already resolved types, used for termination of recursion.
404 * @note This method must be called after all base types have been resolved.
406 void resolveAttributeInheritance(const XsdComplexType::Ptr &complexType, QSet<XsdComplexType::Ptr> &visitedTypes);
409 * Resolves the enumeration facet values for QName and NOTATION based facets.
411 void resolveEnumerationFacetValues();
414 * Returns the source location of the given schema @p component or a dummy
415 * source location if the component is not found in the component location hash.
417 QSourceLocation sourceLocation(const NamedSchemaComponent::Ptr component) const;
420 * Returns the facets that are marked for the given complex @p type with a simple
421 * type restriction.
423 XsdFacet::Hash complexTypeFacets(const XsdComplexType::Ptr &complexType) const;
426 * Finds the primitive type for the given simple @p type.
428 * The type is found by walking up the inheritance tree, until one of the builtin
429 * primitive type definitions is reached.
431 AnySimpleType::Ptr findPrimitiveType(const AnySimpleType::Ptr &type, QSet<AnySimpleType::Ptr> &visitedTypes);
434 * Checks the redefined groups.
436 void checkRedefinedGroups();
439 * Checks the redefined attribute groups.
441 void checkRedefinedAttributeGroups();
443 class KeyReference
445 public:
446 XsdElement::Ptr element;
447 XsdIdentityConstraint::Ptr keyRef;
448 QXmlName reference;
449 QSourceLocation location;
452 class SimpleRestrictionBase
454 public:
455 XsdSimpleType::Ptr simpleType;
456 QXmlName baseName;
457 QSourceLocation location;
460 class SimpleListType
462 public:
463 XsdSimpleType::Ptr simpleType;
464 QXmlName typeName;
465 QSourceLocation location;
468 class SimpleUnionType
470 public:
471 XsdSimpleType::Ptr simpleType;
472 QList<QXmlName> typeNames;
473 QSourceLocation location;
476 class ElementType
478 public:
479 XsdElement::Ptr element;
480 QXmlName typeName;
481 QSourceLocation location;
484 class ComplexBaseType
486 public:
487 XsdComplexType::Ptr complexType;
488 QXmlName baseName;
489 QSourceLocation location;
490 XsdFacet::Hash facets;
493 class ComplexContentType
495 public:
496 XsdComplexType::Ptr complexType;
497 XsdParticle::Ptr explicitContent;
498 bool effectiveMixed;
501 class AttributeType
503 public:
504 XsdAttribute::Ptr attribute;
505 QXmlName typeName;
506 QSourceLocation location;
509 class AlternativeType
511 public:
512 XsdAlternative::Ptr alternative;
513 QXmlName typeName;
514 QSourceLocation location;
517 class AlternativeTypeElement
519 public:
520 XsdAlternative::Ptr alternative;
521 XsdElement::Ptr element;
524 class SubstitutionGroupAffiliation
526 public:
527 XsdElement::Ptr element;
528 QList<QXmlName> elementNames;
529 QSourceLocation location;
532 class RedefinedGroups
534 public:
535 XsdModelGroup::Ptr redefinedGroup;
536 XsdModelGroup::Ptr group;
539 class RedefinedAttributeGroups
541 public:
542 XsdAttributeGroup::Ptr redefinedGroup;
543 XsdAttributeGroup::Ptr group;
546 QVector<KeyReference> m_keyReferences;
547 QVector<SimpleRestrictionBase> m_simpleRestrictionBases;
548 QVector<SimpleListType> m_simpleListTypes;
549 QVector<SimpleUnionType> m_simpleUnionTypes;
550 QVector<ElementType> m_elementTypes;
551 QVector<ComplexBaseType> m_complexBaseTypes;
552 QVector<ComplexContentType> m_complexContentTypes;
553 QVector<AttributeType> m_attributeTypes;
554 QVector<AlternativeType> m_alternativeTypes;
555 QVector<AlternativeTypeElement> m_alternativeTypeElements;
556 QVector<SubstitutionGroupAffiliation> m_substitutionGroupAffiliations;
557 QVector<XsdElement::Ptr> m_substitutionGroupTypes;
558 QVector<RedefinedGroups> m_redefinedGroups;
559 QVector<RedefinedAttributeGroups> m_redefinedAttributeGroups;
560 QHash<AtomicValue::Ptr, NamespaceSupport> m_enumerationFacetValues;
561 QSet<XsdReference::Ptr> m_allGroups;
563 QExplicitlySharedDataPointer<XsdSchemaContext> m_context;
564 QExplicitlySharedDataPointer<XsdSchemaChecker> m_checker;
565 NamePool::Ptr m_namePool;
566 XsdSchema::Ptr m_schema;
567 QHash<NamedSchemaComponent::Ptr, QSourceLocation> m_componentLocationHash;
568 XsdComplexType::OpenContent::Ptr m_defaultOpenContent;
569 bool m_defaultOpenContentAppliesToEmpty;
570 SchemaType::List m_predefinedSchemaTypes;
574 QT_END_NAMESPACE
576 QT_END_HEADER
578 #endif