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