Qt 4.8
qxsdschemadebugger.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qxsdschemadebugger_p.h"
43 
45 
46 using namespace QPatternist;
47 
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 
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 
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 
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 
161 {
162  QStringList disallowedSubstGroup;
164  disallowedSubstGroup << QLatin1String("restriction");
166  disallowedSubstGroup << QLatin1String("extension");
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 
178 {
179  qDebug() << "Name:" << attribute->displayName(m_namePool);
180  qDebug() << "Type:" << attribute->type()->displayName(m_namePool);
181 }
182 
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 
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The complex type has further elements or attributes and text as content.
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual QString displayName(const NamePool::Ptr &namePool) const
ProcessContents processContents() const
XsdTerm::Ptr term() const
The model group contains elements only.
void dumpSchema(const XsdSchema::Ptr &schema)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
SchemaType::List anonymousTypes() const
Definition: qxsdschema.cpp:181
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
void dumpType(const SchemaType::Ptr &type)
virtual bool isWildcard() const
Definition: qxsdterm.cpp:58
XsdAttributeUse::List attributeUses() const
ContentType::Ptr contentType() const
XsdWildcard::Ptr attributeWildcard() const
SchemaType::Ptr type() const
virtual SchemaType::Ptr wxsSuperType() const
Q_CORE_EXPORT void qDebug(const char *,...)
unsigned int maximumOccurs() const
virtual bool isElement() const
Definition: qxsdterm.cpp:48
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void dumpParticle(const XsdParticle::Ptr &particle, int level=0)
unsigned int minimumOccurs() const
XsdSchemaDebugger(const NamePool::Ptr &namePool)
AnySimpleType::Ptr type() const
virtual bool isComplexType() const
Definition: qschematype.cpp:70
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The namespace for the internal API of QtXmlPatterns.
virtual QString displayName(const NamePool::Ptr &namePool) const
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
The complex type has only simple type content (e.g. text, number etc.)
QString join(const QString &sep) const
Joins all the string list&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
bool maximumOccursUnbounded() const
NamespaceConstraint::Ptr namespaceConstraint() const
static const struct @32 types[]
void dumpWildcard(const XsdWildcard::Ptr &wildcard)
void dumpAttribute(const XsdAttribute::Ptr &attribute)
void dumpInheritance(const SchemaType::Ptr &type, int level=0)
QString & fill(QChar c, int size=-1)
Sets every character in the string to character ch.
Definition: qstring.cpp:4641
AnySimpleType::Ptr primitiveType() const
XsdAttribute::List attributes() const
Definition: qxsdschema.cpp:110
virtual bool isModelGroup() const
Definition: qxsdterm.cpp:53
static const QTextHtmlElement elements[Html_NumElements]
BlockingConstraints disallowedSubstitutions() const
virtual bool isAbstract() const
void dumpElement(const XsdElement::Ptr &element)
virtual bool isDefinedBySchema() const
Definition: qschematype.cpp:75
SchemaType::List types() const
Definition: qxsdschema.cpp:131
The complex type has further elements or attributes but no text as content.
virtual QString displayName(const NamePool::Ptr &np) const
#define qPrintable(string)
Definition: qglobal.h:1750
virtual SchemaType::Ptr wxsSuperType() const =0
virtual QString displayName(const NamePool::Ptr &np) const =0
Returns a suitable display name for this type.
The complex type has no further content.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
XsdElement::List elements() const
Definition: qxsdschema.cpp:89