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_XsdTypeChecker_H
51#define Patternist_XsdTypeChecker_H
52
53#include <QtXmlPatterns/QSourceLocation>
54
55#include <private/qschematype_p.h>
56#include <private/qsourcelocationreflection_p.h>
57#include <private/qxsdschemacontext_p.h>
58
59QT_BEGIN_NAMESPACE
60
61class QXmlQuery;
62
63namespace QPatternist
64{
65 /**
66 * @short An implementation of SourceLocationReflection that takes a QSourceLocation.
67 *
68 * This is a convenience class which provides a QSourceLocation with a SourceLocationReflection
69 * interface.
70 */
71 class XsdSchemaSourceLocationReflection : public SourceLocationReflection
72 {
73 public:
74 XsdSchemaSourceLocationReflection(const QSourceLocation &location);
75
76 virtual const SourceLocationReflection *actualReflection() const;
77 virtual QSourceLocation sourceLocation() const;
78
79 private:
80 const QSourceLocation m_sourceLocation;
81 };
82
83 /**
84 * @short The class that provides methods for checking a string against a type.
85 *
86 * The class provides functionality for type-aware string handling.
87 */
88 class XsdTypeChecker
89 {
90 public:
91 /**
92 * Creates a new type checker.
93 *
94 * @param context The schema context that is used for error reporting.
95 * @param namespaceBindings The namespace bindings that shall be used to check against xs:QName based types.
96 * @param location The source location that is used for error reporting.
97 */
98 XsdTypeChecker(const XsdSchemaContext::Ptr &context, const QVector<QXmlName> &namespaceBindings, const QSourceLocation &location);
99
100 /**
101 * Destroys the type checker.
102 */
103 ~XsdTypeChecker();
104
105 /**
106 * Returns all facets for the given @p type.
107 *
108 * The list of facets is created by following the type hierarchy from xs:anyType down to the given type
109 * and merging the facets in each step.
110 */
111 static XsdFacet::Hash mergedFacetsForType(const SchemaType::Ptr &type, const XsdSchemaContext::Ptr &context);
112
113 /**
114 * Returns the normalized value for the given @p value.
115 *
116 * The normalized value is the original value with all the white space facets
117 * applied on it.
118 *
119 * @param value The original value.
120 * @param facets The hash of all facets of the values type.
121 */
122 static QString normalizedValue(const QString &value, const XsdFacet::Hash &facets);
123
124 /**
125 * Checks whether the @p normalizedString is valid according the given @p type.
126 *
127 * @param normalizedString The string in normalized form (whitespace facets applied).
128 * @param type The type the string shall be tested against.
129 * @param errorMsg Contains the error message if the normalizedString does not match the type.
130 * @param boundType The type the data was bound to during validation.
131 *
132 * @note The @p boundType only differs from @p type if the type is derived from an based union value.
133 */
134 bool isValidString(const QString &normalizedString, const AnySimpleType::Ptr &type, QString &errorMsg, AnySimpleType::Ptr *boundType = 0) const;
135
136 /**
137 * Returns whether the given @p value and @p otherValue are of @p type and are equal.
138 */
139 bool valuesAreEqual(const QString &value, const QString &otherValue, const AnySimpleType::Ptr &type) const;
140
141 private:
142 Q_DISABLE_COPY(XsdTypeChecker)
143
144 /**
145 * Checks the given value against the facets of @p type.
146 */
147 bool checkConstrainingFacets(const AtomicValue::Ptr &value, const QString &lexicalValue, const AnySimpleType::Ptr &type, QString &errorMsg) const;
148 bool checkConstrainingFacetsString(const QString &value, const XsdFacet::Hash &facets, const AnySimpleType::Ptr &type, QString &errorMsg) const;
149 bool checkConstrainingFacetsSignedInteger(long long value, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const;
150 bool checkConstrainingFacetsUnsignedInteger(unsigned long long value, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const;
151 bool checkConstrainingFacetsDouble(double value, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const;
152 bool checkConstrainingFacetsDecimal(const AtomicValue::Ptr &value, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const;
153 bool checkConstrainingFacetsDateTime(const QDateTime &value, const QString &lexicalValue, const XsdFacet::Hash &facets, const AnySimpleType::Ptr &type, QString &errorMsg) const;
154 bool checkConstrainingFacetsDuration(const AtomicValue::Ptr &value, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const;
155 bool checkConstrainingFacetsBoolean(bool value, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const;
156 bool checkConstrainingFacetsBinary(const QByteArray &value, const XsdFacet::Hash &facets, const AnySimpleType::Ptr &type, QString &errorMsg) const;
157 bool checkConstrainingFacetsQName(const QXmlName&, const QString &lexicalValue, const XsdFacet::Hash &facets, QString &errorMsg) const;
158 bool checkConstrainingFacetsNotation(const QXmlName &value, const XsdFacet::Hash &facets, QString &errorMsg) const;
159 bool checkConstrainingFacetsList(const QStringList &values, const QString &lexicalValue, const AnySimpleType::Ptr &itemType, const XsdFacet::Hash &facets, QString &errorMsg) const;
160 bool checkConstrainingFacetsUnion(const QString &value, const QString &lexicalValue, const XsdSimpleType::Ptr &simpleType, const XsdFacet::Hash &facets, QString &errorMsg) const;
161
162 /**
163 * Creates an atomic value of @p type from the given string @p value.
164 */
165 AtomicValue::Ptr fromLexical(const QString &value, const SchemaType::Ptr &type, const ReportContext::Ptr &context, const SourceLocationReflection *const reflection) const;
166
167 /**
168 * Converts a qualified name into a QXmlName according to the namespace
169 * mappings of the current node.
170 */
171 QXmlName convertToQName(const QString &name) const;
172
173 XsdSchemaContext::Ptr m_context;
174 XsdSchema::Ptr m_schema;
175 const NamePool::Ptr m_namePool;
176 QVector<QXmlName> m_namespaceBindings;
177 SourceLocationReflection* m_reflection;
178 };
179}
180
181QT_END_NAMESPACE
182
183#endif
184

source code of qtxmlpatterns/src/xmlpatterns/schema/qxsdtypechecker_p.h