| 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_XsdAttribute_H |
| 51 | #define Patternist_XsdAttribute_H |
| 52 | |
| 53 | #include <private/qanysimpletype_p.h> |
| 54 | #include <private/qnamedschemacomponent_p.h> |
| 55 | #include <private/qxsdannotated_p.h> |
| 56 | |
| 57 | #include <QtCore/QList> |
| 58 | |
| 59 | QT_BEGIN_NAMESPACE |
| 60 | |
| 61 | namespace QPatternist |
| 62 | { |
| 63 | /** |
| 64 | * @short Represents a XSD attribute object. |
| 65 | * |
| 66 | * This class represents the <em>attribute</em> object of a XML schema as described |
| 67 | * <a href="http://www.w3.org/TR/xmlschema11-1/#cAttribute_Declarations">here</a>. |
| 68 | * |
| 69 | * It contains information from either a top-level attribute declaration (as child of |
| 70 | * a <em>schema</em> object) or of a local attribute declaration (as child of <em>complexType</em> |
| 71 | * or <em>attributeGroup</em> object without a 'ref' attribute). |
| 72 | * |
| 73 | * All other occurrences of the <em>attribute</em> object are represented by the XsdAttributeUse class. |
| 74 | * |
| 75 | * @see <a href="http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040309/xml-schema-api.html#Interface-XSAttributeDeclaration">XML Schema API reference</a> |
| 76 | * @ingroup Patternist_schema |
| 77 | * @author Tobias Koenig <tobias.koenig@nokia.com> |
| 78 | */ |
| 79 | class XsdAttribute : public NamedSchemaComponent, public XsdAnnotated |
| 80 | { |
| 81 | public: |
| 82 | typedef QExplicitlySharedDataPointer<XsdAttribute> Ptr; |
| 83 | typedef QList<XsdAttribute::Ptr> List; |
| 84 | |
| 85 | /** |
| 86 | * @short Describes the scope of an attribute. |
| 87 | * |
| 88 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#sc_a">Scope Definition</a> |
| 89 | */ |
| 90 | class Scope : public QSharedData |
| 91 | { |
| 92 | public: |
| 93 | typedef QExplicitlySharedDataPointer<Scope> Ptr; |
| 94 | |
| 95 | /** |
| 96 | * Describes the <a href="http://www.w3.org/TR/xmlschema11-1/#ad-scope">scope</a> of an attribute. |
| 97 | */ |
| 98 | enum Variety |
| 99 | { |
| 100 | Global, ///< The attribute is defined globally as child of the <em>schema</em> object. |
| 101 | Local ///< The attribute is defined locally as child of a complex type or attribute group definition. |
| 102 | }; |
| 103 | |
| 104 | /** |
| 105 | * Sets the @p variety of the attribute scope. |
| 106 | * |
| 107 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#sc_a-variety">Variety Definition</a> |
| 108 | */ |
| 109 | void setVariety(Variety variety); |
| 110 | |
| 111 | /** |
| 112 | * Returns the variety of the attribute scope. |
| 113 | */ |
| 114 | Variety variety() const; |
| 115 | |
| 116 | /** |
| 117 | * Sets the @p parent complex type or attribute group definition of the attribute scope. |
| 118 | * |
| 119 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#sc_a-parent">Parent Definition</a> |
| 120 | */ |
| 121 | void setParent(const NamedSchemaComponent::Ptr &parent); |
| 122 | |
| 123 | /** |
| 124 | * Returns the parent complex type or attribute group definition of the attribute scope. |
| 125 | */ |
| 126 | NamedSchemaComponent::Ptr parent() const; |
| 127 | |
| 128 | private: |
| 129 | Variety m_variety; |
| 130 | NamedSchemaComponent::Ptr m_parent; |
| 131 | }; |
| 132 | |
| 133 | |
| 134 | /** |
| 135 | * @short Describes the value constraint of an attribute. |
| 136 | * |
| 137 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#vc_a">Value Constraint Definition</a> |
| 138 | */ |
| 139 | class ValueConstraint : public QSharedData |
| 140 | { |
| 141 | public: |
| 142 | typedef QExplicitlySharedDataPointer<ValueConstraint> Ptr; |
| 143 | |
| 144 | /** |
| 145 | * Describes the <a href="http://www.w3.org/TR/xmlschema11-1/#ad-value_constraint">value constraint</a> of an attribute. |
| 146 | */ |
| 147 | enum Variety |
| 148 | { |
| 149 | Default, ///< The attribute has a default value set. |
| 150 | Fixed ///< The attribute has a fixed value set. |
| 151 | }; |
| 152 | |
| 153 | /** |
| 154 | * Sets the @p variety of the attribute value constraint. |
| 155 | * |
| 156 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#vc_a-variety">Variety Definition</a> |
| 157 | */ |
| 158 | void setVariety(Variety variety); |
| 159 | |
| 160 | /** |
| 161 | * Returns the variety of the attribute value constraint. |
| 162 | */ |
| 163 | Variety variety() const; |
| 164 | |
| 165 | /** |
| 166 | * Sets the @p value of the constraint. |
| 167 | * |
| 168 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#vc_a-value">Value Definition</a> |
| 169 | */ |
| 170 | void setValue(const QString &value); |
| 171 | |
| 172 | /** |
| 173 | * Returns the value of the constraint. |
| 174 | */ |
| 175 | QString value() const; |
| 176 | |
| 177 | /** |
| 178 | * Sets the lexical @p form of the constraint. |
| 179 | * |
| 180 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#vc_a-lexical_form">Lexical Form Definition</a> |
| 181 | */ |
| 182 | void setLexicalForm(const QString &form); |
| 183 | |
| 184 | /** |
| 185 | * Returns the lexical form of the constraint. |
| 186 | */ |
| 187 | QString lexicalForm() const; |
| 188 | |
| 189 | private: |
| 190 | Variety m_variety; |
| 191 | QString m_value; |
| 192 | QString m_lexicalForm; |
| 193 | }; |
| 194 | |
| 195 | /** |
| 196 | * Sets the simple @p type definition of the attribute. |
| 197 | * |
| 198 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ad-type_definition">Simple Type Definition</a> |
| 199 | */ |
| 200 | void setType(const AnySimpleType::Ptr &type); |
| 201 | |
| 202 | /** |
| 203 | * Returns the simple type definition of the attribute. |
| 204 | */ |
| 205 | AnySimpleType::Ptr type() const; |
| 206 | |
| 207 | /** |
| 208 | * Sets the @p scope of the attribute. |
| 209 | * |
| 210 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ad-scope">Scope Definition</a> |
| 211 | */ |
| 212 | void setScope(const Scope::Ptr &scope); |
| 213 | |
| 214 | /** |
| 215 | * Returns the scope of the attribute. |
| 216 | */ |
| 217 | Scope::Ptr scope() const; |
| 218 | |
| 219 | /** |
| 220 | * Sets the value @p constraint of the attribute. |
| 221 | * |
| 222 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ad-value_constraint">Value Constraint Definition</a> |
| 223 | */ |
| 224 | void setValueConstraint(const ValueConstraint::Ptr &constraint); |
| 225 | |
| 226 | /** |
| 227 | * Returns the value constraint of the attribute. |
| 228 | */ |
| 229 | ValueConstraint::Ptr valueConstraint() const; |
| 230 | |
| 231 | private: |
| 232 | AnySimpleType::Ptr m_type; |
| 233 | Scope::Ptr m_scope; |
| 234 | ValueConstraint::Ptr m_valueConstraint; |
| 235 | }; |
| 236 | } |
| 237 | |
| 238 | QT_END_NAMESPACE |
| 239 | |
| 240 | #endif |
| 241 |
