| 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_XsdValidatedXmlNodeModel_H |
| 51 | #define Patternist_XsdValidatedXmlNodeModel_H |
| 52 | |
| 53 | #include "qabstractxmlnodemodel.h" |
| 54 | |
| 55 | #include <private/qabstractxmlforwarditerator_p.h> |
| 56 | #include <private/qitem_p.h> |
| 57 | #include <private/qschematype_p.h> |
| 58 | #include <private/qxsdelement_p.h> |
| 59 | |
| 60 | QT_BEGIN_NAMESPACE |
| 61 | |
| 62 | namespace QPatternist |
| 63 | { |
| 64 | /** |
| 65 | * @short A delegate class that wraps around a QAbstractXmlNodeModel and provides |
| 66 | * additional validation specific information. |
| 67 | * |
| 68 | * This class represents the input XML document enriched with additional type |
| 69 | * information that has been assigned during validation. |
| 70 | * |
| 71 | * @ingroup Patternist_schema |
| 72 | * @author Tobias Koenig <tobias.koenig@nokia.com> |
| 73 | */ |
| 74 | class XsdValidatedXmlNodeModel : public QAbstractXmlNodeModel |
| 75 | { |
| 76 | public: |
| 77 | typedef QExplicitlySharedDataPointer<XsdValidatedXmlNodeModel> Ptr; |
| 78 | typedef QList<Ptr> List; |
| 79 | |
| 80 | /** |
| 81 | * Creates a new validated xml node model. |
| 82 | */ |
| 83 | XsdValidatedXmlNodeModel(const QAbstractXmlNodeModel *model); |
| 84 | |
| 85 | /** |
| 86 | * Destroys the validated xml node model. |
| 87 | */ |
| 88 | virtual ~XsdValidatedXmlNodeModel(); |
| 89 | |
| 90 | virtual QUrl baseUri(const QXmlNodeModelIndex &ni) const; |
| 91 | virtual QUrl documentUri(const QXmlNodeModelIndex &ni) const; |
| 92 | virtual QXmlNodeModelIndex::NodeKind kind(const QXmlNodeModelIndex &ni) const; |
| 93 | virtual QXmlNodeModelIndex::DocumentOrder compareOrder(const QXmlNodeModelIndex &ni1, const QXmlNodeModelIndex &ni2) const; |
| 94 | virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const; |
| 95 | virtual QXmlName name(const QXmlNodeModelIndex &ni) const; |
| 96 | virtual QString stringValue(const QXmlNodeModelIndex &n) const; |
| 97 | virtual QVariant typedValue(const QXmlNodeModelIndex &n) const; |
| 98 | virtual QExplicitlySharedDataPointer<QAbstractXmlForwardIterator<QXmlNodeModelIndex> > iterate(const QXmlNodeModelIndex &ni, QXmlNodeModelIndex::Axis axis) const; |
| 99 | virtual QPatternist::ItemIteratorPtr sequencedTypedValue(const QXmlNodeModelIndex &ni) const; |
| 100 | virtual QPatternist::ItemTypePtr type(const QXmlNodeModelIndex &ni) const; |
| 101 | virtual QXmlName::NamespaceCode namespaceForPrefix(const QXmlNodeModelIndex &ni, const QXmlName::PrefixCode prefix) const; |
| 102 | virtual bool isDeepEqual(const QXmlNodeModelIndex &ni1, const QXmlNodeModelIndex &ni2) const; |
| 103 | virtual void sendNamespaces(const QXmlNodeModelIndex &n, QAbstractXmlReceiver *const receiver) const; |
| 104 | virtual QVector<QXmlName> namespaceBindings(const QXmlNodeModelIndex &n) const; |
| 105 | virtual QXmlNodeModelIndex elementById(const QXmlName &NCName) const; |
| 106 | virtual QVector<QXmlNodeModelIndex> nodesByIdref(const QXmlName &NCName) const; |
| 107 | virtual void copyNodeTo(const QXmlNodeModelIndex &node, QAbstractXmlReceiver *const receiver, const NodeCopySettings &) const; |
| 108 | |
| 109 | /** |
| 110 | * Sets the @p element that is assigned to the xml node at @p index. |
| 111 | */ |
| 112 | void setAssignedElement(const QXmlNodeModelIndex &index, const XsdElement::Ptr &element); |
| 113 | |
| 114 | /** |
| 115 | * Returns the element that is assigned to the xml node at @p index. |
| 116 | */ |
| 117 | XsdElement::Ptr assignedElement(const QXmlNodeModelIndex &index) const; |
| 118 | |
| 119 | /** |
| 120 | * Sets the @p attribute that is assigned to the xml node at @p index. |
| 121 | */ |
| 122 | void setAssignedAttribute(const QXmlNodeModelIndex &index, const XsdAttribute::Ptr &attribute); |
| 123 | |
| 124 | /** |
| 125 | * Returns the attribute that is assigned to the xml node at @p index. |
| 126 | */ |
| 127 | XsdAttribute::Ptr assignedAttribute(const QXmlNodeModelIndex &index) const; |
| 128 | |
| 129 | /** |
| 130 | * Sets the @p type that is assigned to the xml node at @p index. |
| 131 | * |
| 132 | * @note The type can be a different than the type of the element or |
| 133 | * attribute that is assigned to the index, since the instance |
| 134 | * document can overwrite it by xsi:type. |
| 135 | */ |
| 136 | void setAssignedType(const QXmlNodeModelIndex &index, const SchemaType::Ptr &type); |
| 137 | |
| 138 | /** |
| 139 | * Returns the type that is assigned to the xml node at @p index. |
| 140 | */ |
| 141 | SchemaType::Ptr assignedType(const QXmlNodeModelIndex &index) const; |
| 142 | |
| 143 | /** |
| 144 | * Adds the attribute or element @p binding with the given @p id. |
| 145 | */ |
| 146 | void addIdIdRefBinding(const QString &id, const NamedSchemaComponent::Ptr &binding); |
| 147 | |
| 148 | /** |
| 149 | * Returns a list of all binding ids. |
| 150 | */ |
| 151 | QStringList idIdRefBindingIds() const; |
| 152 | |
| 153 | /** |
| 154 | * Returns the set of bindings with the given @p id. |
| 155 | */ |
| 156 | QSet<NamedSchemaComponent::Ptr> idIdRefBindings(const QString &id) const; |
| 157 | |
| 158 | protected: |
| 159 | virtual QXmlNodeModelIndex nextFromSimpleAxis(SimpleAxis axis, const QXmlNodeModelIndex &origin) const; |
| 160 | virtual QVector<QXmlNodeModelIndex> attributes(const QXmlNodeModelIndex &element) const; |
| 161 | |
| 162 | private: |
| 163 | QExplicitlySharedDataPointer<const QAbstractXmlNodeModel> m_internalModel; |
| 164 | QHash<QXmlNodeModelIndex, XsdElement::Ptr> m_assignedElements; |
| 165 | QHash<QXmlNodeModelIndex, XsdAttribute::Ptr> m_assignedAttributes; |
| 166 | QHash<QXmlNodeModelIndex, SchemaType::Ptr> m_assignedTypes; |
| 167 | QHash<QString, QSet<NamedSchemaComponent::Ptr> > m_idIdRefBindings; |
| 168 | }; |
| 169 | } |
| 170 | |
| 171 | QT_END_NAMESPACE |
| 172 | |
| 173 | #endif |
| 174 | |