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#include "qxsdschemadebugger_p.h"
41
42QT_BEGIN_NAMESPACE
43
44using namespace QPatternist;
45
46XsdSchemaDebugger::XsdSchemaDebugger(const NamePool::Ptr &namePool)
47 : m_namePool(namePool)
48{
49}
50
51void XsdSchemaDebugger::dumpParticle(const XsdParticle::Ptr &particle, int level)
52{
53 QString prefix; prefix.fill(c: QLatin1Char(' '), size: level);
54
55 qDebug(msg: "%s min=%s max=%s", qPrintable(prefix), qPrintable(QString::number(particle->minimumOccurs())),
56 qPrintable(particle->maximumOccursUnbounded() ? QLatin1String("unbounded") : QString::number(particle->maximumOccurs())));
57
58 if (particle->term()->isElement()) {
59 qDebug(msg: "%selement (%s)", qPrintable(prefix), qPrintable(XsdElement::Ptr(particle->term())->displayName(m_namePool)));
60 } else if (particle->term()->isModelGroup()) {
61 const XsdModelGroup::Ptr group(particle->term());
62 if (group->compositor() == XsdModelGroup::SequenceCompositor) {
63 qDebug(msg: "%ssequence", qPrintable(prefix));
64 } else if (group->compositor() == XsdModelGroup::AllCompositor) {
65 qDebug(msg: "%sall", qPrintable(prefix));
66 } else if (group->compositor() == XsdModelGroup::ChoiceCompositor) {
67 qDebug(msg: "%schoice", qPrintable(prefix));
68 }
69
70 for (int i = 0; i < group->particles().count(); ++i)
71 dumpParticle(particle: group->particles().at(i), level: level + 5);
72 } else if (particle->term()->isWildcard()) {
73 XsdWildcard::Ptr wildcard(particle->term());
74 qDebug(msg: "%swildcard (process=%d)", qPrintable(prefix), wildcard->processContents());
75 }
76}
77
78void XsdSchemaDebugger::dumpInheritance(const SchemaType::Ptr &type, int level)
79{
80 QString prefix; prefix.fill(c: QLatin1Char(' '), size: level);
81 qDebug(msg: "%s-->%s", qPrintable(prefix), qPrintable(type->displayName(m_namePool)));
82 if (type->wxsSuperType())
83 dumpInheritance(type: type->wxsSuperType(), level: ++level);
84}
85
86void XsdSchemaDebugger::dumpWildcard(const XsdWildcard::Ptr &wildcard)
87{
88 QVector<QString> varietyNames;
89 varietyNames.append(t: QLatin1String("Any"));
90 varietyNames.append(t: QLatin1String("Enumeration"));
91 varietyNames.append(t: QLatin1String("Not"));
92
93 QVector<QString> processContentsNames;
94 processContentsNames.append(t: QLatin1String("Strict"));
95 processContentsNames.append(t: QLatin1String("Lax"));
96 processContentsNames.append(t: QLatin1String("Skip"));
97
98 qDebug(msg: " processContents: %s", qPrintable(processContentsNames.at((int)wildcard->processContents())));
99 const XsdWildcard::NamespaceConstraint::Ptr constraint = wildcard->namespaceConstraint();
100 qDebug(msg: " variety: %s", qPrintable(varietyNames.at((int)constraint->variety())));
101 if (constraint->variety() != XsdWildcard::NamespaceConstraint::Any)
102 qDebug() << " namespaces:" << constraint->namespaces();
103}
104
105void XsdSchemaDebugger::dumpType(const SchemaType::Ptr &type)
106{
107 if (type->isComplexType()) {
108 const XsdComplexType::Ptr complexType(type);
109 qDebug(msg: "\n+++ Complex Type +++");
110 qDebug(msg: "Name: %s (abstract: %s)", qPrintable(complexType->displayName(m_namePool)), complexType->isAbstract() ? "yes" : "no");
111 if (complexType->wxsSuperType())
112 qDebug(msg: " base type: %s", qPrintable(complexType->wxsSuperType()->displayName(m_namePool)));
113 else
114 qDebug(msg: " base type: (none)");
115 if (complexType->contentType()->variety() == XsdComplexType::ContentType::Empty)
116 qDebug(msg: " content type: empty");
117 if (complexType->contentType()->variety() == XsdComplexType::ContentType::Simple)
118 qDebug(msg: " content type: simple");
119 if (complexType->contentType()->variety() == XsdComplexType::ContentType::ElementOnly)
120 qDebug(msg: " content type: element-only");
121 if (complexType->contentType()->variety() == XsdComplexType::ContentType::Mixed)
122 qDebug(msg: " content type: mixed");
123 if (complexType->contentType()->variety() == XsdComplexType::ContentType::Simple) {
124 if (complexType->contentType()->simpleType())
125 qDebug(msg: " simple type: %s", qPrintable(complexType->contentType()->simpleType()->displayName(m_namePool)));
126 else
127 qDebug(msg: " simple type: (none)");
128 }
129
130 const XsdAttributeUse::List uses = complexType->attributeUses();
131 qDebug(msg: " %d attributes", uses.count());
132 for (int i = 0; i < uses.count(); ++i) {
133 qDebug(msg: " attr: %s", qPrintable(uses.at(i)->attribute()->displayName(m_namePool)));
134 }
135 qDebug(msg: " has attribute wildcard: %s", complexType->attributeWildcard() ? "yes" : "no");
136 if (complexType->attributeWildcard()) {
137 dumpWildcard(wildcard: complexType->attributeWildcard());
138 }
139
140 if (complexType->contentType()->particle()) {
141 dumpParticle(particle: complexType->contentType()->particle(), level: 5);
142 }
143 } else {
144 qDebug(msg: "\n+++ Simple Type +++");
145 qDebug(msg: "Name: %s", qPrintable(type->displayName(m_namePool)));
146 if (type->isDefinedBySchema()) {
147 const XsdSimpleType::Ptr simpleType(type);
148 if (simpleType->primitiveType())
149 qDebug(msg: " primitive type: %s", qPrintable(simpleType->primitiveType()->displayName(m_namePool)));
150 else
151 qDebug(msg: " primitive type: (none)");
152 }
153 dumpInheritance(type, level: 0);
154 }
155}
156
157
158void XsdSchemaDebugger::dumpElement(const XsdElement::Ptr &element)
159{
160 QStringList disallowedSubstGroup;
161 if (element->disallowedSubstitutions() & XsdElement::RestrictionConstraint)
162 disallowedSubstGroup << QLatin1String("restriction");
163 if (element->disallowedSubstitutions() & XsdElement::ExtensionConstraint)
164 disallowedSubstGroup << QLatin1String("extension");
165 if (element->disallowedSubstitutions() & XsdElement::SubstitutionConstraint)
166 disallowedSubstGroup << QLatin1String("substitution");
167
168
169 qDebug() << "Name:" << element->displayName(namePool: m_namePool);
170 qDebug() << "IsAbstract:" << (element->isAbstract() ? "yes" : "no");
171 qDebug() << "Type:" << element->type()->displayName(np: m_namePool);
172 qDebug() << "DisallowedSubstitutionGroups:" << disallowedSubstGroup.join(sep: QLatin1String("' "));
173}
174
175void XsdSchemaDebugger::dumpAttribute(const XsdAttribute::Ptr &attribute)
176{
177 qDebug() << "Name:" << attribute->displayName(namePool: m_namePool);
178 qDebug() << "Type:" << attribute->type()->displayName(np: m_namePool);
179}
180
181void XsdSchemaDebugger::dumpSchema(const XsdSchema::Ptr &schema)
182{
183 qDebug() << "------------------------------ Schema -------------------------------";
184
185 // elements
186 {
187 qDebug() << "Global Elements:";
188 const XsdElement::List elements = schema->elements();
189 for (int i = 0; i < elements.count(); ++i) {
190 dumpElement(element: elements.at(i));
191 }
192 }
193
194 // attributes
195 {
196 qDebug() << "Global Attributes:";
197 const XsdAttribute::List attributes = schema->attributes();
198 for (int i = 0; i < attributes.count(); ++i) {
199 dumpAttribute(attribute: attributes.at(i));
200 }
201 }
202
203 // types
204 {
205 qDebug() << "Global Types:";
206 const SchemaType::List types = schema->types();
207 for (int i = 0; i < types.count(); ++i) {
208 dumpType(type: types.at(i));
209 }
210 }
211
212 // anonymous types
213 {
214 qDebug() << "Anonymous Types:";
215 const SchemaType::List types = schema->anonymousTypes();
216 for (int i = 0; i < types.count(); ++i) {
217 dumpType(type: types.at(i));
218 }
219 }
220
221 qDebug() << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
222}
223
224QT_END_NAMESPACE
225

source code of qtxmlpatterns/src/xmlpatterns/schema/qxsdschemadebugger.cpp