1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
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.
52 #ifndef Patternist_SchemaType_H
53 #define Patternist_SchemaType_H
55 #include "qnamepool_p.h"
56 #include "qschemacomponent_p.h"
59 template<typename N, typename M> class QHash;
60 template<typename N> class QList;
71 * @short Base class for W3C XML Schema types.
73 * This is the base class of all data types in a W3C XML Schema.
75 * @ingroup Patternist_types
76 * @author Frans Englich <frans.englich@nokia.com>
78 class SchemaType : public SchemaComponent
82 typedef QExplicitlySharedDataPointer<SchemaType> Ptr;
83 typedef QHash<QXmlName, SchemaType::Ptr> Hash;
84 typedef QList<SchemaType::Ptr> List;
87 * Schema types are divided into different categories such as
88 * complex type, atomic imple type, union simple type, and so forth. This
89 * enumerator, which category() returns a value of, identifies what
90 * category the type belong to.
92 * @todo Add docs & links for the enums
98 * A simple atomic type. These are also sometimes
99 * referred to as primitive types. An example of this type is
102 * Formally speaking, a simple type with variety atomic.
110 enum DerivationMethod
112 DerivationRestriction = 1,
113 DerivationExtension = 2,
117 * Used for <tt>xs:anyType</tt>.
123 * Describes the derivation constraints that are given by the 'final' or 'block' attributes.
125 enum DerivationConstraint
127 RestrictionConstraint = 1,
128 ExtensionConstraint = 2,
132 Q_DECLARE_FLAGS(DerivationConstraints, DerivationConstraint)
135 virtual ~SchemaType();
138 * Determines how this SchemaType is derived from its super type.
140 * @note Despite that DerivationMethod is designed for being
141 * used for bitwise OR'd value, this function may only return one enum
142 * value. If the type does not derive from any type, which is the case of
143 * <tt>xs:anyType</tt>, this function returns NoDerivation.
145 * @see SchemaType::wxsSuperType()
146 * @see <a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#TypeInfo-DerivationMethods">Document
147 * Object Model (DOM) Level 3 Core Specification, Definition group DerivationMethods</a>
148 * @returns a DerivationMethod enumerator signifiying how
149 * this SchemaType is derived from its base type
151 virtual DerivationMethod derivationMethod() const = 0;
154 * Determines what derivation constraints exists for the type.
156 virtual DerivationConstraints derivationConstraints() const = 0;
159 * Determines whether the type is an abstract type.
161 * @note It is important a correct value is returned, since
162 * abstract types must not be instantiated.
164 virtual bool isAbstract() const = 0;
167 * @short Returns the name of the type.
169 * The reason to why we take the name pool argument, is that the basic
170 * types, @c xs:anySimpleType and so on, are stored globally in
171 * BuiltinTypes and ComonSequenceTypes, and therefore cannot be tied to
172 * a certain name pool. Type instances that knows they always will be
173 * used with a certain name pool, can therefore ignore @p np and return
174 * a QXmlName instance stored as a member.
176 * If the type code was refactored to not be store globally and
177 * therefore by design would be tied to a name pool, this argument could
180 virtual QXmlName name(const NamePool::Ptr &np) const = 0;
183 * @short Returns a suitable display name for this type.
185 * See name() for an explanation to why we take a NamePool as argument.
187 virtual QString displayName(const NamePool::Ptr &np) const = 0;
190 * @returns the W3C XML Schema base type that this type derives from. All types
191 * returns an instance, except for the xs:anyType since it
192 * is the very base type of all types, and it returns 0. Hence,
193 * one can walk the hierarchy of a schema type by recursively calling
194 * wxsSuperType, until zero is returned.
196 * This function walks the Schema hierarchy. Some simple types, the atomic types,
197 * is also part of the XPath Data Model hierarchy, and their super type in that
198 * hierarchy can be introspected with xdtSuperType().
200 * wxsSuperType() can be said to correspond to the {base type definition} property
201 * in the Post Schema Valid Infoset(PSVI).
203 * @see ItemType::xdtSuperType()
205 virtual SchemaType::Ptr wxsSuperType() const = 0;
208 * @returns @c true if @p other is identical to 'this' schema type or if @p other
209 * is either directly or indirectly a base type of 'this'. Hence, calling
210 * AnyType::wxsTypeMatches() with @p other as argument returns @c true for all types,
211 * since all types have @c xs:anyType as super type.
213 virtual bool wxsTypeMatches(const SchemaType::Ptr &other) const = 0;
215 virtual TypeCategory category() const = 0;
218 * Determines whether the type is a simple type, by introspecting
219 * the result of category().
221 * @note Do not re-implement this function, but instead override category()
222 * and let it return an appropriate value.
224 virtual bool isSimpleType() const;
227 * Determines whether the type is a complex type, by introspecting
228 * the result of category().
230 * @note Do not re-implement this function, but instead override category()
231 * and let it return an appropriate value.
233 virtual bool isComplexType() const;
236 * Returns whether the value has been defined by a schema (is not a built in type).
238 virtual bool isDefinedBySchema() const;
241 Q_DECLARE_OPERATORS_FOR_FLAGS(SchemaType::DerivationConstraints)