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_XsdAttributeUse_H
51#define Patternist_XsdAttributeUse_H
52
53#include <private/qxsdattribute_p.h>
54#include <private/qxsdattributeterm_p.h>
55
56#include <QtCore/QList>
57
58QT_BEGIN_NAMESPACE
59
60namespace QPatternist
61{
62 /**
63 * @short Represents a XSD attribute use object.
64 *
65 * This class represents the <em>attribute use</em> object of a XML schema as described
66 * <a href="http://www.w3.org/TR/xmlschema11-1/#cAttributeUse">here</a>.
67 *
68 * It contains information from a local attribute declaration (as child of <em>complexType</em>
69 * or <em>attributeGroup</em> object).
70 *
71 * All other occurrences of the <em>attribute</em> object are represented by the XsdAttribute class.
72 *
73 * @see <a href="http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040309/xml-schema-api.html#Interface-XSAttributeUse">XML Schema API reference</a>
74 * @ingroup Patternist_schema
75 * @author Tobias Koenig <tobias.koenig@nokia.com>
76 */
77 class XsdAttributeUse : public XsdAttributeTerm
78 {
79 public:
80 typedef QExplicitlySharedDataPointer<XsdAttributeUse> Ptr;
81 typedef QList<XsdAttributeUse::Ptr> List;
82
83 /**
84 * Describes the value constraint of an attribute use.
85 *
86 * @see <a href="http://www.w3.org/TR/xmlschema11-1/#vc_au">Value Constraint Definition</a>
87 */
88 class ValueConstraint : public QSharedData
89 {
90 public:
91 typedef QExplicitlySharedDataPointer<ValueConstraint> Ptr;
92
93 /**
94 * Describes the <a href="http://www.w3.org/TR/xmlschema11-1/#au-value_constraint">value constraint</a> of an attribute use.
95 */
96 enum Variety
97 {
98 Default, ///< The attribute use has a default value set.
99 Fixed ///< The attribute use has a fixed value set.
100 };
101
102 /**
103 * Sets the @p variety of the attribute use value constraint.
104 */
105 void setVariety(Variety variety);
106
107 /**
108 * Returns the variety of the attribute use value constraint.
109 */
110 Variety variety() const;
111
112 /**
113 * Sets the @p value of the constraint.
114 */
115 void setValue(const QString &value);
116
117 /**
118 * Returns the value of the constraint.
119 */
120 QString value() const;
121
122 /**
123 * Sets the lexical @p form of the constraint.
124 */
125 void setLexicalForm(const QString &form);
126
127 /**
128 * Returns the lexical form of the constraint.
129 */
130 QString lexicalForm() const;
131
132 /**
133 * Creates a new value constraint from a XsdAttribute::ValueConstraint.
134 */
135 static ValueConstraint::Ptr fromAttributeValueConstraint(const XsdAttribute::ValueConstraint::Ptr &constraint);
136
137 private:
138 Variety m_variety;
139 QString m_value;
140 QString m_lexicalForm;
141 };
142
143 /**
144 * Describes the use type of the attribute use.
145 */
146 enum UseType
147 {
148 OptionalUse, ///< The attribute can be there but doesn't need to.
149 RequiredUse, ///< The attribute must be there.
150 ProhibitedUse ///< The attribute is not allowed to be there.
151 };
152
153 /**
154 * Creates a new attribute use object.
155 */
156 XsdAttributeUse();
157
158 /**
159 * Always returns true, used to avoid dynamic casts.
160 */
161 virtual bool isAttributeUse() const;
162
163 /**
164 * Sets the use @p type of the attribute use.
165 *
166 * @see UseType
167 */
168 void setUseType(UseType type);
169
170 /**
171 * Returns the use type of the attribute use.
172 */
173 UseType useType() const;
174
175 /**
176 * Returns whether the attribute use is required.
177 *
178 * @see <a href="http://www.w3.org/TR/xmlschema11-1/#au-required">Required Definition</a>
179 */
180 bool isRequired() const;
181
182 /**
183 * Sets the @p attribute the attribute use is referring to.
184 * That is either a local definition as child of a complexType
185 * or attributeGroup object, or a reference defined by the
186 * 'ref' attribute.
187 *
188 * @see <a href="http://www.w3.org/TR/xmlschema11-1/#au-attribute_declaration">Attribute Declaration</a>
189 */
190 void setAttribute(const XsdAttribute::Ptr &attribute);
191
192 /**
193 * Returns the attribute the attribute use is referring to.
194 */
195 XsdAttribute::Ptr attribute() const;
196
197 /**
198 * Sets the value @p constraint of the attribute use.
199 *
200 * @see http://www.w3.org/TR/xmlschema11-1/#vc_au
201 */
202 void setValueConstraint(const ValueConstraint::Ptr &constraint);
203
204 /**
205 * Returns the value constraint of the attribute use.
206 */
207 ValueConstraint::Ptr valueConstraint() const;
208
209 private:
210 UseType m_useType;
211 XsdAttribute::Ptr m_attribute;
212 ValueConstraint::Ptr m_valueConstraint;
213 };
214}
215
216QT_END_NAMESPACE
217
218#endif
219

source code of qtxmlpatterns/src/xmlpatterns/schema/qxsdattributeuse_p.h