1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qxsdschemadebugger_p.h"
|
---|
43 |
|
---|
44 | QT_BEGIN_NAMESPACE
|
---|
45 |
|
---|
46 | using namespace QPatternist;
|
---|
47 |
|
---|
48 | XsdSchemaDebugger::XsdSchemaDebugger(const NamePool::Ptr &namePool)
|
---|
49 | : m_namePool(namePool)
|
---|
50 | {
|
---|
51 | }
|
---|
52 |
|
---|
53 | void XsdSchemaDebugger::dumpParticle(const XsdParticle::Ptr &particle, int level)
|
---|
54 | {
|
---|
55 | QString prefix; prefix.fill(QLatin1Char(' '), level);
|
---|
56 |
|
---|
57 | qDebug("%s min=%s max=%s", qPrintable(prefix), qPrintable(QString::number(particle->minimumOccurs())),
|
---|
58 | qPrintable(particle->maximumOccursUnbounded() ? QLatin1String("unbounded") : QString::number(particle->maximumOccurs())));
|
---|
59 |
|
---|
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));
|
---|
70 | }
|
---|
71 |
|
---|
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());
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | void XsdSchemaDebugger::dumpInheritance(const SchemaType::Ptr &type, int level)
|
---|
81 | {
|
---|
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);
|
---|
86 | }
|
---|
87 |
|
---|
88 | void XsdSchemaDebugger::dumpWildcard(const XsdWildcard::Ptr &wildcard)
|
---|
89 | {
|
---|
90 | QVector<QString> varietyNames;
|
---|
91 | varietyNames.append(QLatin1String("Any"));
|
---|
92 | varietyNames.append(QLatin1String("Enumeration"));
|
---|
93 | varietyNames.append(QLatin1String("Not"));
|
---|
94 |
|
---|
95 | QVector<QString> processContentsNames;
|
---|
96 | processContentsNames.append(QLatin1String("Strict"));
|
---|
97 | processContentsNames.append(QLatin1String("Lax"));
|
---|
98 | processContentsNames.append(QLatin1String("Skip"));
|
---|
99 |
|
---|
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();
|
---|
105 | }
|
---|
106 |
|
---|
107 | void XsdSchemaDebugger::dumpType(const SchemaType::Ptr &type)
|
---|
108 | {
|
---|
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)));
|
---|
115 | else
|
---|
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)));
|
---|
128 | else
|
---|
129 | qDebug(" simple type: (none)");
|
---|
130 | }
|
---|
131 |
|
---|
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)));
|
---|
136 | }
|
---|
137 | qDebug(" has attribute wildcard: %s", complexType->attributeWildcard() ? "yes" : "no");
|
---|
138 | if (complexType->attributeWildcard()) {
|
---|
139 | dumpWildcard(complexType->attributeWildcard());
|
---|
140 | }
|
---|
141 |
|
---|
142 | if (complexType->contentType()->particle()) {
|
---|
143 | dumpParticle(complexType->contentType()->particle(), 5);
|
---|
144 | }
|
---|
145 | } else {
|
---|
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)));
|
---|
152 | else
|
---|
153 | qDebug(" primitive type: (none)");
|
---|
154 | }
|
---|
155 | dumpInheritance(type, 0);
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | void XsdSchemaDebugger::dumpElement(const XsdElement::Ptr &element)
|
---|
161 | {
|
---|
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");
|
---|
169 |
|
---|
170 |
|
---|
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("' "));
|
---|
175 | }
|
---|
176 |
|
---|
177 | void XsdSchemaDebugger::dumpAttribute(const XsdAttribute::Ptr &attribute)
|
---|
178 | {
|
---|
179 | qDebug() << "Name:" << attribute->displayName(m_namePool);
|
---|
180 | qDebug() << "Type:" << attribute->type()->displayName(m_namePool);
|
---|
181 | }
|
---|
182 |
|
---|
183 | void XsdSchemaDebugger::dumpSchema(const XsdSchema::Ptr &schema)
|
---|
184 | {
|
---|
185 | qDebug() << "------------------------------ Schema -------------------------------";
|
---|
186 |
|
---|
187 | // elements
|
---|
188 | {
|
---|
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));
|
---|
193 | }
|
---|
194 | }
|
---|
195 |
|
---|
196 | // attributes
|
---|
197 | {
|
---|
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));
|
---|
202 | }
|
---|
203 | }
|
---|
204 |
|
---|
205 | // types
|
---|
206 | {
|
---|
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));
|
---|
211 | }
|
---|
212 | }
|
---|
213 |
|
---|
214 | // anonymous types
|
---|
215 | {
|
---|
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));
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|
223 | qDebug() << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
|
---|
224 | }
|
---|
225 |
|
---|
226 | QT_END_NAMESPACE
|
---|