| 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_XsdElement_H |
| 51 | #define Patternist_XsdElement_H |
| 52 | |
| 53 | #include <private/qschemacomponent_p.h> |
| 54 | #include <private/qschematype_p.h> |
| 55 | #include <private/qxsdalternative_p.h> |
| 56 | #include <private/qxsdidentityconstraint_p.h> |
| 57 | #include <private/qxsdcomplextype_p.h> |
| 58 | |
| 59 | #include <QtCore/QList> |
| 60 | #include <QtCore/QSet> |
| 61 | |
| 62 | QT_BEGIN_NAMESPACE |
| 63 | |
| 64 | namespace QPatternist |
| 65 | { |
| 66 | /** |
| 67 | * @short Represents a XSD element object. |
| 68 | * |
| 69 | * This class represents the <em>element</em> object of a XML schema as described |
| 70 | * <a href="http://www.w3.org/TR/xmlschema11-1/#cElement_Declarations">here</a>. |
| 71 | * |
| 72 | * It contains information from either a top-level element declaration (as child of a <em>schema</em> object) |
| 73 | * or a local element declaration (as descendant of an <em>complexType</em> object). |
| 74 | * |
| 75 | * @see <a href="http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040309/xml-schema-api.html#Interface-XSElementDecl">XML Schema API reference</a> |
| 76 | * @ingroup Patternist_schema |
| 77 | * @author Tobias Koenig <tobias.koenig@nokia.com> |
| 78 | */ |
| 79 | class XsdElement : public XsdTerm |
| 80 | { |
| 81 | public: |
| 82 | typedef QExplicitlySharedDataPointer<XsdElement> Ptr; |
| 83 | typedef QList<XsdElement::Ptr> List; |
| 84 | |
| 85 | |
| 86 | /** |
| 87 | * Describes the <a href="http://www.w3.org/TR/xmlschema11-1/#ed-value_constraint">constraint type</a> of the element. |
| 88 | */ |
| 89 | enum ConstraintType |
| 90 | { |
| 91 | NoneConstraint, ///< The value of the element has no constraints. |
| 92 | DefaultConstraint, ///< The element has a default value set. |
| 93 | FixedConstraint ///< The element has a fixed value set. |
| 94 | }; |
| 95 | |
| 96 | /** |
| 97 | * Describes the scope of an element. |
| 98 | * |
| 99 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#sc_e">Scope Definition</a> |
| 100 | */ |
| 101 | class Scope : public QSharedData |
| 102 | { |
| 103 | public: |
| 104 | typedef QExplicitlySharedDataPointer<Scope> Ptr; |
| 105 | |
| 106 | /** |
| 107 | * Describes the <a href="http://www.w3.org/TR/xmlschema11-1/#ad-scope">scope</a> of an attribute. |
| 108 | */ |
| 109 | enum Variety |
| 110 | { |
| 111 | Global, ///< The element is defined globally as child of the <em>schema</em> object. |
| 112 | Local ///< The element is defined locally as child of a complex type or model group definition. |
| 113 | }; |
| 114 | |
| 115 | /** |
| 116 | * Sets the @p variety of the element scope. |
| 117 | */ |
| 118 | void setVariety(Variety variety); |
| 119 | |
| 120 | /** |
| 121 | * Returns the variety of the element scope. |
| 122 | */ |
| 123 | Variety variety() const; |
| 124 | |
| 125 | /** |
| 126 | * Sets the @p parent complex type or model group definition of the element scope. |
| 127 | */ |
| 128 | void setParent(const NamedSchemaComponent *parent); |
| 129 | |
| 130 | /** |
| 131 | * Returns the parent complex type or model group definition of the element scope. |
| 132 | */ |
| 133 | const NamedSchemaComponent *parent() const; |
| 134 | |
| 135 | private: |
| 136 | Variety m_variety; |
| 137 | const NamedSchemaComponent *m_parent = nullptr; |
| 138 | }; |
| 139 | |
| 140 | /** |
| 141 | * Describes a type table of an element. |
| 142 | * |
| 143 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#tt">Type Table Definition</a> |
| 144 | */ |
| 145 | class TypeTable : public QSharedData |
| 146 | { |
| 147 | public: |
| 148 | typedef QExplicitlySharedDataPointer<TypeTable> Ptr; |
| 149 | |
| 150 | /** |
| 151 | * Adds an @p alternative to the type table. |
| 152 | */ |
| 153 | void addAlternative(const XsdAlternative::Ptr &alternative); |
| 154 | |
| 155 | /** |
| 156 | * Returns the alternatives of the type table. |
| 157 | */ |
| 158 | XsdAlternative::List alternatives() const; |
| 159 | |
| 160 | /** |
| 161 | * Sets the default @p type definition. |
| 162 | */ |
| 163 | void setDefaultTypeDefinition(const XsdAlternative::Ptr &type); |
| 164 | |
| 165 | /** |
| 166 | * Returns the default type definition. |
| 167 | */ |
| 168 | XsdAlternative::Ptr defaultTypeDefinition() const; |
| 169 | |
| 170 | private: |
| 171 | XsdAlternative::List m_alternatives; |
| 172 | XsdAlternative::Ptr m_defaultTypeDefinition; |
| 173 | }; |
| 174 | |
| 175 | |
| 176 | /** |
| 177 | * Describes the value constraint of an element. |
| 178 | * |
| 179 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#vc_e">Value Constraint Definition</a> |
| 180 | */ |
| 181 | class ValueConstraint : public QSharedData |
| 182 | { |
| 183 | public: |
| 184 | typedef QExplicitlySharedDataPointer<ValueConstraint> Ptr; |
| 185 | |
| 186 | /** |
| 187 | * Describes the <a href="http://www.w3.org/TR/xmlschema11-1/#ed-value_constraint">value constraint</a> of an element. |
| 188 | */ |
| 189 | enum Variety |
| 190 | { |
| 191 | Default, ///< The element has a default value set. |
| 192 | Fixed ///< The element has a fixed value set. |
| 193 | }; |
| 194 | |
| 195 | /** |
| 196 | * Sets the @p variety of the element value constraint. |
| 197 | */ |
| 198 | void setVariety(Variety variety); |
| 199 | |
| 200 | /** |
| 201 | * Returns the variety of the element value constraint. |
| 202 | */ |
| 203 | Variety variety() const; |
| 204 | |
| 205 | /** |
| 206 | * Sets the @p value of the constraint. |
| 207 | */ |
| 208 | void setValue(const QString &value); |
| 209 | |
| 210 | /** |
| 211 | * Returns the value of the constraint. |
| 212 | */ |
| 213 | QString value() const; |
| 214 | |
| 215 | /** |
| 216 | * Sets the lexical @p form of the constraint. |
| 217 | */ |
| 218 | void setLexicalForm(const QString &form); |
| 219 | |
| 220 | /** |
| 221 | * Returns the lexical form of the constraint. |
| 222 | */ |
| 223 | QString lexicalForm() const; |
| 224 | |
| 225 | private: |
| 226 | Variety m_variety; |
| 227 | QString m_value; |
| 228 | QString m_lexicalForm; |
| 229 | }; |
| 230 | |
| 231 | /** |
| 232 | * Creates a new element object. |
| 233 | */ |
| 234 | XsdElement(); |
| 235 | |
| 236 | /** |
| 237 | * Always returns @c true, used to avoid dynamic casts. |
| 238 | */ |
| 239 | virtual bool isElement() const; |
| 240 | |
| 241 | /** |
| 242 | * Sets the @p type of the element. |
| 243 | * |
| 244 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ed-type_definition">Type Definition</a> |
| 245 | */ |
| 246 | void setType(const SchemaType::Ptr &type); |
| 247 | |
| 248 | /** |
| 249 | * Returns the type of the element. |
| 250 | */ |
| 251 | SchemaType::Ptr type() const; |
| 252 | |
| 253 | /** |
| 254 | * Sets the @p scope of the element. |
| 255 | * |
| 256 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ed-scope">Scope Definition</a> |
| 257 | */ |
| 258 | void setScope(const Scope::Ptr &scope); |
| 259 | |
| 260 | /** |
| 261 | * Returns the scope of the element. |
| 262 | */ |
| 263 | Scope::Ptr scope() const; |
| 264 | |
| 265 | /** |
| 266 | * Sets the value @p constraint of the element. |
| 267 | * |
| 268 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ed-value_constraint">Value Constraint Definition</a> |
| 269 | */ |
| 270 | void setValueConstraint(const ValueConstraint::Ptr &constraint); |
| 271 | |
| 272 | /** |
| 273 | * Returns the value constraint of the element. |
| 274 | */ |
| 275 | ValueConstraint::Ptr valueConstraint() const; |
| 276 | |
| 277 | /** |
| 278 | * Sets the type table of the element. |
| 279 | * |
| 280 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ed-type_table">Type Table Definition</a> |
| 281 | */ |
| 282 | void setTypeTable(const TypeTable::Ptr &table); |
| 283 | |
| 284 | /** |
| 285 | * Returns the type table of the element. |
| 286 | */ |
| 287 | TypeTable::Ptr typeTable() const; |
| 288 | |
| 289 | /** |
| 290 | * Sets whether the element is @p abstract. |
| 291 | * |
| 292 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ed-abstract">Abstract Definition</a> |
| 293 | */ |
| 294 | void setIsAbstract(bool abstract); |
| 295 | |
| 296 | /** |
| 297 | * Returns whether the element is abstract. |
| 298 | */ |
| 299 | bool isAbstract() const; |
| 300 | |
| 301 | /** |
| 302 | * Sets whether the element is @p nillable. |
| 303 | * |
| 304 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ed-nillable">Nillable Definition</a> |
| 305 | */ |
| 306 | void setIsNillable(bool nillable); |
| 307 | |
| 308 | /** |
| 309 | * Returns whether the element is nillable. |
| 310 | */ |
| 311 | bool isNillable() const; |
| 312 | |
| 313 | /** |
| 314 | * Sets the disallowed @p substitutions of the element. |
| 315 | * |
| 316 | * Only ExtensionConstraint, RestrictionConstraint and SubstitutionConstraint are allowed. |
| 317 | * |
| 318 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ed-disallowed_substitutions">Disallowed Substitutions Definition</a> |
| 319 | */ |
| 320 | void setDisallowedSubstitutions(const BlockingConstraints &substitutions); |
| 321 | |
| 322 | /** |
| 323 | * Returns the disallowed substitutions of the element. |
| 324 | */ |
| 325 | BlockingConstraints disallowedSubstitutions() const; |
| 326 | |
| 327 | /** |
| 328 | * Sets the substitution group @p exclusions of the element. |
| 329 | * |
| 330 | * Only SchemaType::ExtensionConstraint and SchemaType::RestrictionConstraint are allowed. |
| 331 | * |
| 332 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ed-substitution_group_exclusions">Substitution Group Exclusions Definition</a> |
| 333 | */ |
| 334 | void setSubstitutionGroupExclusions(const SchemaType::DerivationConstraints &exclusions); |
| 335 | |
| 336 | /** |
| 337 | * Returns the substitution group exclusions of the element. |
| 338 | */ |
| 339 | SchemaType::DerivationConstraints substitutionGroupExclusions() const; |
| 340 | |
| 341 | /** |
| 342 | * Sets the identity @p constraints of the element. |
| 343 | * |
| 344 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ed-identity-constraint_definitions">Identity Constraint Definition</a> |
| 345 | */ |
| 346 | void setIdentityConstraints(const XsdIdentityConstraint::List &constraints); |
| 347 | |
| 348 | /** |
| 349 | * Adds a new identity @p constraint to the element. |
| 350 | */ |
| 351 | void addIdentityConstraint(const XsdIdentityConstraint::Ptr &constraint); |
| 352 | |
| 353 | /** |
| 354 | * Returns a list of all identity constraints of the element. |
| 355 | */ |
| 356 | XsdIdentityConstraint::List identityConstraints() const; |
| 357 | |
| 358 | /** |
| 359 | * Sets the substitution group @p affiliations of the element. |
| 360 | * |
| 361 | * @see <a href="http://www.w3.org/TR/xmlschema11-1/#ed-substituion_group_affiliations">Substitution Group Affiliations</a> |
| 362 | */ |
| 363 | void setSubstitutionGroupAffiliations(const XsdElement::List &affiliations); |
| 364 | |
| 365 | /** |
| 366 | * Returns the substitution group affiliations of the element. |
| 367 | */ |
| 368 | XsdElement::List substitutionGroupAffiliations() const; |
| 369 | |
| 370 | /** |
| 371 | * Adds a substitution group to the element. |
| 372 | */ |
| 373 | void addSubstitutionGroup(const XsdElement::Ptr &elements); |
| 374 | |
| 375 | /** |
| 376 | * Returns the substitution groups of the element. |
| 377 | */ |
| 378 | XsdElement::List substitutionGroups() const; |
| 379 | |
| 380 | private: |
| 381 | SchemaType::Ptr m_type; |
| 382 | Scope::Ptr m_scope; |
| 383 | ValueConstraint::Ptr m_valueConstraint; |
| 384 | TypeTable::Ptr m_typeTable; |
| 385 | bool m_isAbstract; |
| 386 | bool m_isNillable; |
| 387 | BlockingConstraints m_disallowedSubstitutions; |
| 388 | SchemaType::DerivationConstraints m_substitutionGroupExclusions; |
| 389 | XsdIdentityConstraint::List m_identityConstraints; |
| 390 | XsdElement::List m_substitutionGroupAffiliations; |
| 391 | QSet<XsdElement::Ptr> m_substitutionGroups; |
| 392 | }; |
| 393 | } |
| 394 | |
| 395 | QT_END_NAMESPACE |
| 396 | |
| 397 | #endif |
| 398 | |