1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qxsdschemadebugger_p.h"
46 using namespace QPatternist;
48 XsdSchemaDebugger::XsdSchemaDebugger(const NamePool::Ptr &namePool)
49 : m_namePool(namePool)
53 void XsdSchemaDebugger::dumpParticle(const XsdParticle::Ptr &particle, int level)
55 QString prefix; prefix.fill(QLatin1Char(' '), level);
57 qDebug("%s min=%s max=%s", qPrintable(prefix), qPrintable(QString::number(particle->minimumOccurs())),
58 qPrintable(particle->maximumOccursUnbounded() ? QLatin1String("unbounded") : QString::number(particle->maximumOccurs())));
60 if (particle->term()->isElement()) {
61 qDebug("%selement (%s)", qPrintable(prefix), qPrintable(XsdElement::Ptr(particle->term())->displayName(m_namePool)));
62 } else if (particle->term()->isModelGroup()) {
63 const XsdModelGroup::Ptr group(particle->term());
64 if (group->compositor() == XsdModelGroup::SequenceCompositor) {
65 qDebug("%ssequence", qPrintable(prefix));
66 } else if (group->compositor() == XsdModelGroup::AllCompositor) {
67 qDebug("%sall", qPrintable(prefix));
68 } else if (group->compositor() == XsdModelGroup::ChoiceCompositor) {
69 qDebug("%schoice", qPrintable(prefix));
72 for (int i = 0; i < group->particles().count(); ++i)
73 dumpParticle(group->particles().at(i), level + 5);
74 } else if (particle->term()->isWildcard()) {
75 XsdWildcard::Ptr wildcard(particle->term());
76 qDebug("%swildcard (process=%d)", qPrintable(prefix), wildcard->processContents());
80 void XsdSchemaDebugger::dumpInheritance(const SchemaType::Ptr &type, int level)
82 QString prefix; prefix.fill(QLatin1Char(' '), level);
83 qDebug("%s-->%s", qPrintable(prefix), qPrintable(type->displayName(m_namePool)));
84 if (type->wxsSuperType())
85 dumpInheritance(type->wxsSuperType(), ++level);
88 void XsdSchemaDebugger::dumpWildcard(const XsdWildcard::Ptr &wildcard)
90 QVector<QString> varietyNames;
91 varietyNames.append(QLatin1String("Any"));
92 varietyNames.append(QLatin1String("Enumeration"));
93 varietyNames.append(QLatin1String("Not"));
95 QVector<QString> processContentsNames;
96 processContentsNames.append(QLatin1String("Strict"));
97 processContentsNames.append(QLatin1String("Lax"));
98 processContentsNames.append(QLatin1String("Skip"));
100 qDebug(" processContents: %s", qPrintable(processContentsNames.at((int)wildcard->processContents())));
101 const XsdWildcard::NamespaceConstraint::Ptr constraint = wildcard->namespaceConstraint();
102 qDebug(" variety: %s", qPrintable(varietyNames.at((int)constraint->variety())));
103 if (constraint->variety() != XsdWildcard::NamespaceConstraint::Any)
104 qDebug() << " namespaces:" << constraint->namespaces();
107 void XsdSchemaDebugger::dumpType(const SchemaType::Ptr &type)
109 if (type->isComplexType()) {
110 const XsdComplexType::Ptr complexType(type);
111 qDebug("\n+++ Complex Type +++");
112 qDebug("Name: %s (abstract: %s)", qPrintable(complexType->displayName(m_namePool)), complexType->isAbstract() ? "yes" : "no");
113 if (complexType->wxsSuperType())
114 qDebug(" base type: %s", qPrintable(complexType->wxsSuperType()->displayName(m_namePool)));
116 qDebug(" base type: (none)");
117 if (complexType->contentType()->variety() == XsdComplexType::ContentType::Empty)
118 qDebug(" content type: empty");
119 if (complexType->contentType()->variety() == XsdComplexType::ContentType::Simple)
120 qDebug(" content type: simple");
121 if (complexType->contentType()->variety() == XsdComplexType::ContentType::ElementOnly)
122 qDebug(" content type: element-only");
123 if (complexType->contentType()->variety() == XsdComplexType::ContentType::Mixed)
124 qDebug(" content type: mixed");
125 if (complexType->contentType()->variety() == XsdComplexType::ContentType::Simple) {
126 if (complexType->contentType()->simpleType())
127 qDebug(" simple type: %s", qPrintable(complexType->contentType()->simpleType()->displayName(m_namePool)));
129 qDebug(" simple type: (none)");
132 const XsdAttributeUse::List uses = complexType->attributeUses();
133 qDebug(" %d attributes", uses.count());
134 for (int i = 0; i < uses.count(); ++i) {
135 qDebug(" attr: %s", qPrintable(uses.at(i)->attribute()->displayName(m_namePool)));
137 qDebug(" has attribute wildcard: %s", complexType->attributeWildcard() ? "yes" : "no");
138 if (complexType->attributeWildcard()) {
139 dumpWildcard(complexType->attributeWildcard());
142 if (complexType->contentType()->particle()) {
143 dumpParticle(complexType->contentType()->particle(), 5);
146 qDebug("\n+++ Simple Type +++");
147 qDebug("Name: %s", qPrintable(type->displayName(m_namePool)));
148 if (type->isDefinedBySchema()) {
149 const XsdSimpleType::Ptr simpleType(type);
150 if (simpleType->primitiveType())
151 qDebug(" primitive type: %s", qPrintable(simpleType->primitiveType()->displayName(m_namePool)));
153 qDebug(" primitive type: (none)");
155 dumpInheritance(type, 0);
160 void XsdSchemaDebugger::dumpElement(const XsdElement::Ptr &element)
162 QStringList disallowedSubstGroup;
163 if (element->disallowedSubstitutions() & XsdElement::RestrictionConstraint)
164 disallowedSubstGroup << QLatin1String("restriction");
165 if (element->disallowedSubstitutions() & XsdElement::ExtensionConstraint)
166 disallowedSubstGroup << QLatin1String("extension");
167 if (element->disallowedSubstitutions() & XsdElement::SubstitutionConstraint)
168 disallowedSubstGroup << QLatin1String("substitution");
171 qDebug() << "Name:" << element->displayName(m_namePool);
172 qDebug() << "IsAbstract:" << (element->isAbstract() ? "yes" : "no");
173 qDebug() << "Type:" << element->type()->displayName(m_namePool);
174 qDebug() << "DisallowedSubstitutionGroups:" << disallowedSubstGroup.join(QLatin1String("' "));
177 void XsdSchemaDebugger::dumpAttribute(const XsdAttribute::Ptr &attribute)
179 qDebug() << "Name:" << attribute->displayName(m_namePool);
180 qDebug() << "Type:" << attribute->type()->displayName(m_namePool);
183 void XsdSchemaDebugger::dumpSchema(const XsdSchema::Ptr &schema)
185 qDebug() << "------------------------------ Schema -------------------------------";
189 qDebug() << "Global Elements:";
190 const XsdElement::List elements = schema->elements();
191 for (int i = 0; i < elements.count(); ++i) {
192 dumpElement(elements.at(i));
198 qDebug() << "Global Attributes:";
199 const XsdAttribute::List attributes = schema->attributes();
200 for (int i = 0; i < attributes.count(); ++i) {
201 dumpAttribute(attributes.at(i));
207 qDebug() << "Global Types:";
208 const SchemaType::List types = schema->types();
209 for (int i = 0; i < types.count(); ++i) {
210 dumpType(types.at(i));
216 qDebug() << "Anonymous Types:";
217 const SchemaType::List types = schema->anonymousTypes();
218 for (int i = 0; i < types.count(); ++i) {
219 dumpType(types.at(i));
223 qDebug() << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";