~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/xmlpatterns/schema/qxsdtypechecker_p.h

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
15
**
 
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.
 
23
**
 
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.
 
27
**
 
28
** If you have questions regarding the use of this file, please contact
 
29
** Nokia at qt-info@nokia.com.
 
30
**
 
31
**
 
32
**
 
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 "qschematype_p.h"
 
58
#include "qsourcelocationreflection_p.h"
 
59
#include "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