[556] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
---|
| 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
| 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 qt-info@nokia.com.
|
---|
| 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "qxsdschemaresolver_p.h"
|
---|
| 43 |
|
---|
| 44 | #include "qderivedinteger_p.h"
|
---|
| 45 | #include "qderivedstring_p.h"
|
---|
| 46 | #include "qqnamevalue_p.h"
|
---|
| 47 | #include "qxsdattributereference_p.h"
|
---|
| 48 | #include "qxsdparticlechecker_p.h"
|
---|
| 49 | #include "qxsdreference_p.h"
|
---|
| 50 | #include "qxsdschemacontext_p.h"
|
---|
| 51 | #include "qxsdschemahelper_p.h"
|
---|
| 52 | #include "qxsdschemaparsercontext_p.h"
|
---|
| 53 | #include "qxsdschematypesfactory_p.h"
|
---|
| 54 |
|
---|
| 55 | QT_BEGIN_NAMESPACE
|
---|
| 56 |
|
---|
| 57 | using namespace QPatternist;
|
---|
| 58 |
|
---|
| 59 | XsdSchemaResolver::XsdSchemaResolver(const QExplicitlySharedDataPointer<XsdSchemaContext> &context, const XsdSchemaParserContext *parserContext)
|
---|
| 60 | : m_context(context)
|
---|
| 61 | , m_checker(parserContext->checker())
|
---|
| 62 | , m_namePool(parserContext->namePool())
|
---|
| 63 | , m_schema(parserContext->schema())
|
---|
| 64 | {
|
---|
| 65 | m_keyReferences.reserve(20);
|
---|
| 66 | m_simpleRestrictionBases.reserve(20);
|
---|
| 67 | m_simpleListTypes.reserve(20);
|
---|
| 68 | m_simpleUnionTypes.reserve(20);
|
---|
| 69 | m_elementTypes.reserve(20);
|
---|
| 70 | m_complexBaseTypes.reserve(20);
|
---|
| 71 | m_attributeTypes.reserve(20);
|
---|
| 72 | m_alternativeTypes.reserve(20);
|
---|
| 73 | m_alternativeTypeElements.reserve(20);
|
---|
| 74 | m_substitutionGroupAffiliations.reserve(20);
|
---|
| 75 |
|
---|
| 76 | m_predefinedSchemaTypes = m_context->schemaTypeFactory()->types().values();
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | XsdSchemaResolver::~XsdSchemaResolver()
|
---|
| 80 | {
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | void XsdSchemaResolver::resolve()
|
---|
| 84 | {
|
---|
| 85 | m_checker->addComponentLocationHash(m_componentLocationHash);
|
---|
| 86 |
|
---|
| 87 | // resolve the base types for all types
|
---|
| 88 | resolveSimpleRestrictionBaseTypes();
|
---|
| 89 | resolveComplexBaseTypes();
|
---|
| 90 |
|
---|
| 91 | // do the basic checks which depend on having a base type available
|
---|
| 92 | m_checker->basicCheck();
|
---|
| 93 |
|
---|
| 94 | // resolve further types that only map a type name to a type object
|
---|
| 95 | resolveSimpleListType();
|
---|
| 96 | resolveSimpleUnionTypes();
|
---|
| 97 | resolveElementTypes();
|
---|
| 98 | resolveAttributeTypes();
|
---|
| 99 | resolveAlternativeTypes();
|
---|
| 100 |
|
---|
| 101 | // resolve objects that do not need information about inheritance
|
---|
| 102 | resolveKeyReferences();
|
---|
| 103 | resolveSubstitutionGroupAffiliations();
|
---|
| 104 |
|
---|
| 105 | // resolve objects that do need information about inheritance
|
---|
| 106 | resolveSimpleRestrictions();
|
---|
| 107 | resolveSimpleContentComplexTypes();
|
---|
| 108 |
|
---|
| 109 | // resolve objects which replace place holders
|
---|
| 110 | resolveTermReferences();
|
---|
| 111 | resolveAttributeTermReferences();
|
---|
| 112 |
|
---|
| 113 | // resolve additional objects that do need information about inheritance
|
---|
| 114 | resolveAttributeInheritance();
|
---|
| 115 | resolveComplexContentComplexTypes();
|
---|
| 116 | resolveSubstitutionGroups();
|
---|
| 117 |
|
---|
| 118 | resolveEnumerationFacetValues();
|
---|
| 119 |
|
---|
| 120 | checkRedefinedGroups();
|
---|
| 121 | checkRedefinedAttributeGroups();
|
---|
| 122 |
|
---|
| 123 | // check the constraining facets before we resolve them
|
---|
| 124 | m_checker->checkConstrainingFacets();
|
---|
| 125 |
|
---|
| 126 | // add it again, as we may have added new components in the meantime
|
---|
| 127 | m_checker->addComponentLocationHash(m_componentLocationHash);
|
---|
| 128 |
|
---|
| 129 | m_checker->check();
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | void XsdSchemaResolver::addKeyReference(const XsdElement::Ptr &element, const XsdIdentityConstraint::Ptr &keyRef, const QXmlName &reference, const QSourceLocation &location)
|
---|
| 133 | {
|
---|
| 134 | KeyReference item;
|
---|
| 135 | item.element = element;
|
---|
| 136 | item.keyRef = keyRef;
|
---|
| 137 | item.reference = reference;
|
---|
| 138 | item.location = location;
|
---|
| 139 |
|
---|
| 140 | m_keyReferences.append(item);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | void XsdSchemaResolver::addSimpleRestrictionBase(const XsdSimpleType::Ptr &simpleType, const QXmlName &baseName, const QSourceLocation &location)
|
---|
| 144 | {
|
---|
| 145 | SimpleRestrictionBase item;
|
---|
| 146 | item.simpleType = simpleType;
|
---|
| 147 | item.baseName = baseName;
|
---|
| 148 | item.location = location;
|
---|
| 149 |
|
---|
| 150 | m_simpleRestrictionBases.append(item);
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | void XsdSchemaResolver::removeSimpleRestrictionBase(const XsdSimpleType::Ptr &type)
|
---|
| 154 | {
|
---|
| 155 | for (int i = 0; i < m_simpleRestrictionBases.count(); ++i) {
|
---|
| 156 | if (m_simpleRestrictionBases.at(i).simpleType == type) {
|
---|
| 157 | m_simpleRestrictionBases.remove(i);
|
---|
| 158 | break;
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | void XsdSchemaResolver::addSimpleListType(const XsdSimpleType::Ptr &simpleType, const QXmlName &typeName, const QSourceLocation &location)
|
---|
| 164 | {
|
---|
| 165 | SimpleListType item;
|
---|
| 166 | item.simpleType = simpleType;
|
---|
| 167 | item.typeName = typeName;
|
---|
| 168 | item.location = location;
|
---|
| 169 |
|
---|
| 170 | m_simpleListTypes.append(item);
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | void XsdSchemaResolver::addSimpleUnionTypes(const XsdSimpleType::Ptr &simpleType, const QList<QXmlName> &typeNames, const QSourceLocation &location)
|
---|
| 174 | {
|
---|
| 175 | SimpleUnionType item;
|
---|
| 176 | item.simpleType = simpleType;
|
---|
| 177 | item.typeNames = typeNames;
|
---|
| 178 | item.location = location;
|
---|
| 179 |
|
---|
| 180 | m_simpleUnionTypes.append(item);
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | void XsdSchemaResolver::addElementType(const XsdElement::Ptr &element, const QXmlName &typeName, const QSourceLocation &location)
|
---|
| 184 | {
|
---|
| 185 | ElementType item;
|
---|
| 186 | item.element = element;
|
---|
| 187 | item.typeName = typeName;
|
---|
| 188 | item.location = location;
|
---|
| 189 |
|
---|
| 190 | m_elementTypes.append(item);
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | void XsdSchemaResolver::addComplexBaseType(const XsdComplexType::Ptr &complexType, const QXmlName &baseName, const QSourceLocation &location, const XsdFacet::Hash &facets)
|
---|
| 194 | {
|
---|
| 195 | ComplexBaseType item;
|
---|
| 196 | item.complexType = complexType;
|
---|
| 197 | item.baseName = baseName;
|
---|
| 198 | item.location = location;
|
---|
| 199 | item.facets = facets;
|
---|
| 200 |
|
---|
| 201 | m_complexBaseTypes.append(item);
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | void XsdSchemaResolver::removeComplexBaseType(const XsdComplexType::Ptr &type)
|
---|
| 205 | {
|
---|
| 206 | for (int i = 0; i < m_complexBaseTypes.count(); ++i) {
|
---|
| 207 | if (m_complexBaseTypes.at(i).complexType == type) {
|
---|
| 208 | m_complexBaseTypes.remove(i);
|
---|
| 209 | break;
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 | }
|
---|
| 213 |
|
---|
| 214 | void XsdSchemaResolver::addComplexContentType(const XsdComplexType::Ptr &complexType, const XsdParticle::Ptr &content, bool mixed)
|
---|
| 215 | {
|
---|
| 216 | ComplexContentType item;
|
---|
| 217 | item.complexType = complexType;
|
---|
| 218 | item.explicitContent = content;
|
---|
| 219 | item.effectiveMixed = mixed;
|
---|
| 220 | m_complexContentTypes.append(item);
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | void XsdSchemaResolver::addAttributeType(const XsdAttribute::Ptr &attribute, const QXmlName &typeName, const QSourceLocation &location)
|
---|
| 224 | {
|
---|
| 225 | AttributeType item;
|
---|
| 226 | item.attribute = attribute;
|
---|
| 227 | item.typeName = typeName;
|
---|
| 228 | item.location = location;
|
---|
| 229 |
|
---|
| 230 | m_attributeTypes.append(item);
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | void XsdSchemaResolver::addAlternativeType(const XsdAlternative::Ptr &alternative, const QXmlName &typeName, const QSourceLocation &location)
|
---|
| 234 | {
|
---|
| 235 | AlternativeType item;
|
---|
| 236 | item.alternative = alternative;
|
---|
| 237 | item.typeName = typeName;
|
---|
| 238 | item.location = location;
|
---|
| 239 |
|
---|
| 240 | m_alternativeTypes.append(item);
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | void XsdSchemaResolver::addAlternativeType(const XsdAlternative::Ptr &alternative, const XsdElement::Ptr &element)
|
---|
| 244 | {
|
---|
| 245 | AlternativeTypeElement item;
|
---|
| 246 | item.alternative = alternative;
|
---|
| 247 | item.element = element;
|
---|
| 248 |
|
---|
| 249 | m_alternativeTypeElements.append(item);
|
---|
| 250 | }
|
---|
| 251 |
|
---|
| 252 | void XsdSchemaResolver::addSubstitutionGroupAffiliation(const XsdElement::Ptr &element, const QList<QXmlName> &elementNames, const QSourceLocation &location)
|
---|
| 253 | {
|
---|
| 254 | SubstitutionGroupAffiliation item;
|
---|
| 255 | item.element = element;
|
---|
| 256 | item.elementNames = elementNames;
|
---|
| 257 | item.location = location;
|
---|
| 258 |
|
---|
| 259 | m_substitutionGroupAffiliations.append(item);
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | void XsdSchemaResolver::addSubstitutionGroupType(const XsdElement::Ptr &element)
|
---|
| 263 | {
|
---|
| 264 | m_substitutionGroupTypes.append(element);
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | void XsdSchemaResolver::addComponentLocationHash(const ComponentLocationHash &hash)
|
---|
| 268 | {
|
---|
| 269 | m_componentLocationHash.unite(hash);
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | void XsdSchemaResolver::addEnumerationFacetValue(const AtomicValue::Ptr &facetValue, const NamespaceSupport &namespaceSupport)
|
---|
| 273 | {
|
---|
| 274 | m_enumerationFacetValues.insert(facetValue, namespaceSupport);
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | void XsdSchemaResolver::addRedefinedGroups(const XsdModelGroup::Ptr &redefinedGroup, const XsdModelGroup::Ptr &group)
|
---|
| 278 | {
|
---|
| 279 | RedefinedGroups item;
|
---|
| 280 | item.redefinedGroup = redefinedGroup;
|
---|
| 281 | item.group = group;
|
---|
| 282 |
|
---|
| 283 | m_redefinedGroups.append(item);
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | void XsdSchemaResolver::addRedefinedAttributeGroups(const XsdAttributeGroup::Ptr &redefinedGroup, const XsdAttributeGroup::Ptr &group)
|
---|
| 287 | {
|
---|
| 288 | RedefinedAttributeGroups item;
|
---|
| 289 | item.redefinedGroup = redefinedGroup;
|
---|
| 290 | item.group = group;
|
---|
| 291 |
|
---|
| 292 | m_redefinedAttributeGroups.append(item);
|
---|
| 293 | }
|
---|
| 294 |
|
---|
| 295 | void XsdSchemaResolver::addAllGroupCheck(const XsdReference::Ptr &reference)
|
---|
| 296 | {
|
---|
| 297 | m_allGroups.insert(reference);
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | void XsdSchemaResolver::copyDataTo(const XsdSchemaResolver::Ptr &other) const
|
---|
| 301 | {
|
---|
| 302 | other->m_keyReferences << m_keyReferences;
|
---|
| 303 | other->m_simpleRestrictionBases << m_simpleRestrictionBases;
|
---|
| 304 | other->m_simpleListTypes << m_simpleListTypes;
|
---|
| 305 | other->m_simpleUnionTypes << m_simpleUnionTypes;
|
---|
| 306 | other->m_elementTypes << m_elementTypes;
|
---|
| 307 | other->m_complexBaseTypes << m_complexBaseTypes;
|
---|
| 308 | other->m_complexContentTypes << m_complexContentTypes;
|
---|
| 309 | other->m_attributeTypes << m_attributeTypes;
|
---|
| 310 | other->m_alternativeTypes << m_alternativeTypes;
|
---|
| 311 | other->m_alternativeTypeElements << m_alternativeTypeElements;
|
---|
| 312 | other->m_substitutionGroupAffiliations << m_substitutionGroupAffiliations;
|
---|
| 313 | other->m_substitutionGroupTypes << m_substitutionGroupTypes;
|
---|
| 314 | }
|
---|
| 315 |
|
---|
| 316 | QXmlName XsdSchemaResolver::baseTypeNameOfType(const SchemaType::Ptr &type) const
|
---|
| 317 | {
|
---|
| 318 | for (int i = 0; i < m_simpleRestrictionBases.count(); ++i) {
|
---|
| 319 | if (m_simpleRestrictionBases.at(i).simpleType == type)
|
---|
| 320 | return m_simpleRestrictionBases.at(i).baseName;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | for (int i = 0; i < m_complexBaseTypes.count(); ++i) {
|
---|
| 324 | if (m_complexBaseTypes.at(i).complexType == type)
|
---|
| 325 | return m_complexBaseTypes.at(i).baseName;
|
---|
| 326 | }
|
---|
| 327 |
|
---|
| 328 | return QXmlName();
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | QXmlName XsdSchemaResolver::typeNameOfAttribute(const XsdAttribute::Ptr &attribute) const
|
---|
| 332 | {
|
---|
| 333 | for (int i = 0; i < m_attributeTypes.count(); ++i) {
|
---|
| 334 | if (m_attributeTypes.at(i).attribute == attribute)
|
---|
| 335 | return m_attributeTypes.at(i).typeName;
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | return QXmlName();
|
---|
| 339 | }
|
---|
| 340 |
|
---|
| 341 | void XsdSchemaResolver::setDefaultOpenContent(const XsdComplexType::OpenContent::Ptr &openContent, bool appliesToEmpty)
|
---|
| 342 | {
|
---|
| 343 | m_defaultOpenContent = openContent;
|
---|
| 344 | m_defaultOpenContentAppliesToEmpty = appliesToEmpty;
|
---|
| 345 | }
|
---|
| 346 |
|
---|
| 347 | void XsdSchemaResolver::resolveKeyReferences()
|
---|
| 348 | {
|
---|
| 349 | for (int i = 0; i < m_keyReferences.count(); ++i) {
|
---|
| 350 | const KeyReference ref = m_keyReferences.at(i);
|
---|
| 351 |
|
---|
| 352 | const XsdIdentityConstraint::Ptr constraint = m_schema->identityConstraint(ref.reference);
|
---|
| 353 | if (!constraint) {
|
---|
| 354 | m_context->error(QtXmlPatterns::tr("%1 references unknown %2 or %3 element %4.")
|
---|
| 355 | .arg(formatKeyword(ref.keyRef->displayName(m_namePool)))
|
---|
| 356 | .arg(formatElement("key"))
|
---|
| 357 | .arg(formatElement("unique"))
|
---|
| 358 | .arg(formatKeyword(m_namePool, ref.reference)),
|
---|
| 359 | XsdSchemaContext::XSDError, ref.location);
|
---|
| 360 | return;
|
---|
| 361 | }
|
---|
| 362 |
|
---|
| 363 | if (constraint->category() != XsdIdentityConstraint::Key && constraint->category() != XsdIdentityConstraint::Unique) { // only key and unique can be referenced
|
---|
| 364 | m_context->error(QtXmlPatterns::tr("%1 references identity constraint %2 that is no %3 or %4 element.")
|
---|
| 365 | .arg(formatKeyword(ref.keyRef->displayName(m_namePool)))
|
---|
| 366 | .arg(formatKeyword(m_namePool, ref.reference))
|
---|
| 367 | .arg(formatElement("key"))
|
---|
| 368 | .arg(formatElement("unique")),
|
---|
| 369 | XsdSchemaContext::XSDError, ref.location);
|
---|
| 370 | return;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | if (constraint->fields().count() != ref.keyRef->fields().count()) {
|
---|
| 374 | m_context->error(QtXmlPatterns::tr("%1 has a different number of fields from the identity constraint %2 that it references.")
|
---|
| 375 | .arg(formatKeyword(ref.keyRef->displayName(m_namePool)))
|
---|
| 376 | .arg(formatKeyword(m_namePool, ref.reference)),
|
---|
| 377 | XsdSchemaContext::XSDError, ref.location);
|
---|
| 378 | return;
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | ref.keyRef->setReferencedKey(constraint);
|
---|
| 382 | }
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | void XsdSchemaResolver::resolveSimpleRestrictionBaseTypes()
|
---|
| 386 | {
|
---|
| 387 | // iterate over all simple types that are derived by restriction
|
---|
| 388 | for (int i = 0; i < m_simpleRestrictionBases.count(); ++i) {
|
---|
| 389 | const SimpleRestrictionBase item = m_simpleRestrictionBases.at(i);
|
---|
| 390 |
|
---|
| 391 | // find the base type
|
---|
| 392 | SchemaType::Ptr type = m_schema->type(item.baseName);
|
---|
| 393 | if (!type) {
|
---|
| 394 | // maybe it's a basic type...
|
---|
| 395 | type = m_context->schemaTypeFactory()->createSchemaType(item.baseName);
|
---|
| 396 | if (!type) {
|
---|
| 397 | m_context->error(QtXmlPatterns::tr("Base type %1 of %2 element cannot be resolved.")
|
---|
| 398 | .arg(formatType(m_namePool, item.baseName))
|
---|
| 399 | .arg(formatElement("restriction")),
|
---|
| 400 | XsdSchemaContext::XSDError, item.location);
|
---|
| 401 | return;
|
---|
| 402 | }
|
---|
| 403 | }
|
---|
| 404 |
|
---|
| 405 | item.simpleType->setWxsSuperType(type);
|
---|
| 406 | }
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | void XsdSchemaResolver::resolveSimpleRestrictions()
|
---|
| 410 | {
|
---|
| 411 | XsdSimpleType::List simpleTypes;
|
---|
| 412 |
|
---|
| 413 | // first collect the global simple types
|
---|
| 414 | const SchemaType::List types = m_schema->types();
|
---|
| 415 | for (int i = 0; i < types.count(); ++i) {
|
---|
| 416 | if (types.at(i)->isSimpleType() && (types.at(i)->derivationMethod() == SchemaType::DerivationRestriction))
|
---|
| 417 | simpleTypes.append(types.at(i));
|
---|
| 418 | }
|
---|
| 419 |
|
---|
| 420 | // then collect all anonymous simple types
|
---|
| 421 | const SchemaType::List anonymousTypes = m_schema->anonymousTypes();
|
---|
| 422 | for (int i = 0; i < anonymousTypes.count(); ++i) {
|
---|
| 423 | if (anonymousTypes.at(i)->isSimpleType() && (anonymousTypes.at(i)->derivationMethod() == SchemaType::DerivationRestriction))
|
---|
| 424 | simpleTypes.append(anonymousTypes.at(i));
|
---|
| 425 | }
|
---|
| 426 |
|
---|
| 427 | QSet<XsdSimpleType::Ptr> visitedTypes;
|
---|
| 428 | for (int i = 0; i < simpleTypes.count(); ++i) {
|
---|
| 429 | resolveSimpleRestrictions(simpleTypes.at(i), visitedTypes);
|
---|
| 430 | }
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | void XsdSchemaResolver::resolveSimpleRestrictions(const XsdSimpleType::Ptr &simpleType, QSet<XsdSimpleType::Ptr> &visitedTypes)
|
---|
| 434 | {
|
---|
| 435 | if (visitedTypes.contains(simpleType))
|
---|
| 436 | return;
|
---|
| 437 | else
|
---|
| 438 | visitedTypes.insert(simpleType);
|
---|
| 439 |
|
---|
| 440 | if (simpleType->derivationMethod() != XsdSimpleType::DerivationRestriction)
|
---|
| 441 | return;
|
---|
| 442 |
|
---|
| 443 | // as xs:NMTOKENS, xs:ENTITIES and xs:IDREFS are provided by our XsdSchemaTypesFactory, they are
|
---|
| 444 | // setup correctly already and shouldn't be handled here
|
---|
| 445 | if (m_predefinedSchemaTypes.contains(simpleType))
|
---|
| 446 | return;
|
---|
| 447 |
|
---|
| 448 | const SchemaType::Ptr baseType = simpleType->wxsSuperType();
|
---|
| 449 | Q_ASSERT(baseType);
|
---|
| 450 |
|
---|
| 451 | if (baseType->isDefinedBySchema())
|
---|
| 452 | resolveSimpleRestrictions(XsdSimpleType::Ptr(baseType), visitedTypes);
|
---|
| 453 |
|
---|
| 454 | simpleType->setCategory(baseType->category());
|
---|
| 455 |
|
---|
| 456 | if (simpleType->category() == XsdSimpleType::SimpleTypeAtomic) {
|
---|
| 457 | QSet<AnySimpleType::Ptr> visitedPrimitiveTypes;
|
---|
| 458 | const AnySimpleType::Ptr primitiveType = findPrimitiveType(baseType, visitedPrimitiveTypes);
|
---|
| 459 | simpleType->setPrimitiveType(primitiveType);
|
---|
| 460 | } else if (simpleType->category() == XsdSimpleType::SimpleTypeList) {
|
---|
| 461 | const XsdSimpleType::Ptr simpleBaseType = baseType;
|
---|
| 462 | simpleType->setItemType(simpleBaseType->itemType());
|
---|
| 463 | } else if (simpleType->category() == XsdSimpleType::SimpleTypeUnion) {
|
---|
| 464 | const XsdSimpleType::Ptr simpleBaseType = baseType;
|
---|
| 465 | simpleType->setMemberTypes(simpleBaseType->memberTypes());
|
---|
| 466 | }
|
---|
| 467 | }
|
---|
| 468 |
|
---|
| 469 | void XsdSchemaResolver::resolveSimpleListType()
|
---|
| 470 | {
|
---|
| 471 | // iterate over all simple types where the item type shall be resolved
|
---|
| 472 | for (int i = 0; i < m_simpleListTypes.count(); ++i) {
|
---|
| 473 | const SimpleListType item = m_simpleListTypes.at(i);
|
---|
| 474 |
|
---|
| 475 | // try to resolve the name
|
---|
| 476 | SchemaType::Ptr type = m_schema->type(item.typeName);
|
---|
| 477 | if (!type) {
|
---|
| 478 | // maybe it's a basic type...
|
---|
| 479 | type = m_context->schemaTypeFactory()->createSchemaType(item.typeName);
|
---|
| 480 | if (!type) {
|
---|
| 481 | m_context->error(QtXmlPatterns::tr("Item type %1 of %2 element cannot be resolved.")
|
---|
| 482 | .arg(formatType(m_namePool, item.typeName))
|
---|
| 483 | .arg(formatElement("list")),
|
---|
| 484 | XsdSchemaContext::XSDError, item.location);
|
---|
| 485 | return;
|
---|
| 486 | }
|
---|
| 487 | }
|
---|
| 488 |
|
---|
| 489 | item.simpleType->setItemType(type);
|
---|
| 490 | }
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 | void XsdSchemaResolver::resolveSimpleUnionTypes()
|
---|
| 494 | {
|
---|
| 495 | // iterate over all simple types where the union member types shall be resolved
|
---|
| 496 | for (int i = 0; i < m_simpleUnionTypes.count(); ++i) {
|
---|
| 497 | const SimpleUnionType item = m_simpleUnionTypes.at(i);
|
---|
| 498 |
|
---|
| 499 | AnySimpleType::List memberTypes;
|
---|
| 500 |
|
---|
| 501 | // iterate over all union member type names
|
---|
| 502 | const QList<QXmlName> typeNames = item.typeNames;
|
---|
| 503 | for (int j = 0; j < typeNames.count(); ++j) {
|
---|
| 504 | const QXmlName typeName = typeNames.at(j);
|
---|
| 505 |
|
---|
| 506 | // try to resolve the name
|
---|
| 507 | SchemaType::Ptr type = m_schema->type(typeName);
|
---|
| 508 | if (!type) {
|
---|
| 509 | // maybe it's a basic type...
|
---|
| 510 | type = m_context->schemaTypeFactory()->createSchemaType(typeName);
|
---|
| 511 | if (!type) {
|
---|
| 512 | m_context->error(QtXmlPatterns::tr("Member type %1 of %2 element cannot be resolved.")
|
---|
| 513 | .arg(formatType(m_namePool, typeName))
|
---|
| 514 | .arg(formatElement("union")),
|
---|
| 515 | XsdSchemaContext::XSDError, item.location);
|
---|
| 516 | return;
|
---|
| 517 | }
|
---|
| 518 | }
|
---|
| 519 |
|
---|
| 520 | memberTypes.append(type);
|
---|
| 521 | }
|
---|
| 522 |
|
---|
| 523 | // append the types that have been defined as <simpleType> children
|
---|
| 524 | memberTypes << item.simpleType->memberTypes();
|
---|
| 525 |
|
---|
| 526 | item.simpleType->setMemberTypes(memberTypes);
|
---|
| 527 | }
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 | void XsdSchemaResolver::resolveElementTypes()
|
---|
| 531 | {
|
---|
| 532 | for (int i = 0; i < m_elementTypes.count(); ++i) {
|
---|
| 533 | const ElementType item = m_elementTypes.at(i);
|
---|
| 534 |
|
---|
| 535 | SchemaType::Ptr type = m_schema->type(item.typeName);
|
---|
| 536 | if (!type) {
|
---|
| 537 | // maybe it's a basic type...
|
---|
| 538 | type = m_context->schemaTypeFactory()->createSchemaType(item.typeName);
|
---|
| 539 | if (!type) {
|
---|
| 540 | m_context->error(QtXmlPatterns::tr("Type %1 of %2 element cannot be resolved.")
|
---|
| 541 | .arg(formatType(m_namePool, item.typeName))
|
---|
| 542 | .arg(formatElement("element")),
|
---|
| 543 | XsdSchemaContext::XSDError, item.location);
|
---|
| 544 | return;
|
---|
| 545 | }
|
---|
| 546 | }
|
---|
| 547 |
|
---|
| 548 | item.element->setType(type);
|
---|
| 549 | }
|
---|
| 550 | }
|
---|
| 551 |
|
---|
| 552 | void XsdSchemaResolver::resolveComplexBaseTypes()
|
---|
| 553 | {
|
---|
| 554 | for (int i = 0; i < m_complexBaseTypes.count(); ++i) {
|
---|
| 555 | const ComplexBaseType item = m_complexBaseTypes.at(i);
|
---|
| 556 |
|
---|
| 557 | SchemaType::Ptr type = m_schema->type(item.baseName);
|
---|
| 558 | if (!type) {
|
---|
| 559 | // maybe it's a basic type...
|
---|
| 560 | type = m_context->schemaTypeFactory()->createSchemaType(item.baseName);
|
---|
| 561 | if (!type) {
|
---|
| 562 | m_context->error(QtXmlPatterns::tr("Base type %1 of complex type cannot be resolved.").arg(formatType(m_namePool, item.baseName)), XsdSchemaContext::XSDError, item.location);
|
---|
| 563 | return;
|
---|
| 564 | }
|
---|
| 565 | }
|
---|
| 566 |
|
---|
| 567 | if (item.complexType->contentType()->variety() == XsdComplexType::ContentType::Simple) {
|
---|
| 568 | if (type->isComplexType() && type->isDefinedBySchema()) {
|
---|
| 569 | const XsdComplexType::Ptr baseType = type;
|
---|
| 570 | if (baseType->contentType()->variety() != XsdComplexType::ContentType::Simple) {
|
---|
| 571 | m_context->error(QtXmlPatterns::tr("%1 cannot have complex base type that has a %2.")
|
---|
| 572 | .arg(formatElement("simpleContent"))
|
---|
| 573 | .arg(formatElement("complexContent")),
|
---|
| 574 | XsdSchemaContext::XSDError, item.location);
|
---|
| 575 | return;
|
---|
| 576 | }
|
---|
| 577 | }
|
---|
| 578 | }
|
---|
| 579 |
|
---|
| 580 | item.complexType->setWxsSuperType(type);
|
---|
| 581 | }
|
---|
| 582 | }
|
---|
| 583 |
|
---|
| 584 | void XsdSchemaResolver::resolveSimpleContentComplexTypes()
|
---|
| 585 | {
|
---|
| 586 | XsdComplexType::List complexTypes;
|
---|
| 587 |
|
---|
| 588 | // first collect the global complex types
|
---|
| 589 | const SchemaType::List types = m_schema->types();
|
---|
| 590 | for (int i = 0; i < types.count(); ++i) {
|
---|
| 591 | if (types.at(i)->isComplexType() && types.at(i)->isDefinedBySchema())
|
---|
| 592 | complexTypes.append(types.at(i));
|
---|
| 593 | }
|
---|
| 594 |
|
---|
| 595 | // then collect all anonymous simple types
|
---|
| 596 | const SchemaType::List anonymousTypes = m_schema->anonymousTypes();
|
---|
| 597 | for (int i = 0; i < anonymousTypes.count(); ++i) {
|
---|
| 598 | if (anonymousTypes.at(i)->isComplexType() && anonymousTypes.at(i)->isDefinedBySchema())
|
---|
| 599 | complexTypes.append(anonymousTypes.at(i));
|
---|
| 600 | }
|
---|
| 601 |
|
---|
| 602 | QSet<XsdComplexType::Ptr> visitedTypes;
|
---|
| 603 | for (int i = 0; i < complexTypes.count(); ++i) {
|
---|
| 604 | if (XsdComplexType::Ptr(complexTypes.at(i))->contentType()->variety() == XsdComplexType::ContentType::Simple)
|
---|
| 605 | resolveSimpleContentComplexTypes(complexTypes.at(i), visitedTypes);
|
---|
| 606 | }
|
---|
| 607 | }
|
---|
| 608 |
|
---|
| 609 | void XsdSchemaResolver::resolveSimpleContentComplexTypes(const XsdComplexType::Ptr &complexType, QSet<XsdComplexType::Ptr> &visitedTypes)
|
---|
| 610 | {
|
---|
| 611 | if (visitedTypes.contains(complexType))
|
---|
| 612 | return;
|
---|
| 613 | else
|
---|
| 614 | visitedTypes.insert(complexType);
|
---|
| 615 |
|
---|
| 616 | const SchemaType::Ptr baseType = complexType->wxsSuperType();
|
---|
| 617 |
|
---|
| 618 | // at this point simple types have been resolved already, so we care about
|
---|
| 619 | // complex types here only
|
---|
| 620 |
|
---|
| 621 | // http://www.w3.org/TR/xmlschema11-1/#dcl.ctd.ctsc
|
---|
| 622 | // 1
|
---|
| 623 | if (baseType->isComplexType() && baseType->isDefinedBySchema()) {
|
---|
| 624 | const XsdComplexType::Ptr complexBaseType = baseType;
|
---|
| 625 |
|
---|
| 626 | resolveSimpleContentComplexTypes(complexBaseType, visitedTypes);
|
---|
| 627 |
|
---|
| 628 | if (complexBaseType->contentType()->variety() == XsdComplexType::ContentType::Simple) {
|
---|
| 629 | if (complexType->derivationMethod() == XsdComplexType::DerivationRestriction) {
|
---|
| 630 | if (complexType->contentType()->simpleType()) {
|
---|
| 631 | // 1.1 contains the content of the <simpleType> already
|
---|
| 632 | } else {
|
---|
| 633 | // 1.2
|
---|
| 634 | const XsdSimpleType::Ptr anonType(new XsdSimpleType());
|
---|
[769] | 635 | XsdSimpleType::TypeCategory baseCategory = complexBaseType->contentType()->simpleType()->category();
|
---|
| 636 | anonType->setCategory(baseCategory);
|
---|
| 637 |
|
---|
| 638 | if (baseCategory == XsdSimpleType::SimpleTypeList) {
|
---|
| 639 | const XsdSimpleType::Ptr baseSimpleType = complexBaseType->contentType()->simpleType();
|
---|
| 640 | anonType->setItemType(baseSimpleType->itemType());
|
---|
| 641 | }
|
---|
| 642 |
|
---|
[556] | 643 | anonType->setDerivationMethod(XsdSimpleType::DerivationRestriction);
|
---|
| 644 | anonType->setWxsSuperType(complexBaseType->contentType()->simpleType());
|
---|
| 645 | anonType->setFacets(complexTypeFacets(complexType));
|
---|
| 646 |
|
---|
| 647 | QSet<AnySimpleType::Ptr> visitedPrimitiveTypes;
|
---|
| 648 | const AnySimpleType::Ptr primitiveType = findPrimitiveType(anonType->wxsSuperType(), visitedPrimitiveTypes);
|
---|
| 649 | anonType->setPrimitiveType(primitiveType);
|
---|
| 650 |
|
---|
| 651 | complexType->contentType()->setSimpleType(anonType);
|
---|
| 652 |
|
---|
| 653 | m_schema->addAnonymousType(anonType);
|
---|
| 654 | m_componentLocationHash.insert(anonType, m_componentLocationHash.value(complexType));
|
---|
| 655 | }
|
---|
| 656 | } else if (complexBaseType->derivationMethod() == XsdComplexType::DerivationExtension) { // 3
|
---|
| 657 | complexType->contentType()->setSimpleType(complexBaseType->contentType()->simpleType());
|
---|
| 658 | }
|
---|
| 659 | } else if (complexBaseType->contentType()->variety() == XsdComplexType::ContentType::Mixed &&
|
---|
| 660 | complexType->derivationMethod() == XsdComplexType::DerivationRestriction &&
|
---|
| 661 | XsdSchemaHelper::isParticleEmptiable(complexBaseType->contentType()->particle())) { // 2
|
---|
| 662 | // simple type was already set in parser
|
---|
| 663 |
|
---|
| 664 | const XsdSimpleType::Ptr anonType(new XsdSimpleType());
|
---|
| 665 | anonType->setCategory(complexType->contentType()->simpleType()->category());
|
---|
| 666 | anonType->setDerivationMethod(XsdSimpleType::DerivationRestriction);
|
---|
| 667 | anonType->setWxsSuperType(complexType->contentType()->simpleType());
|
---|
| 668 | anonType->setFacets(complexTypeFacets(complexType));
|
---|
| 669 |
|
---|
| 670 | QSet<AnySimpleType::Ptr> visitedPrimitiveTypes;
|
---|
| 671 | const AnySimpleType::Ptr primitiveType = findPrimitiveType(anonType->wxsSuperType(), visitedPrimitiveTypes);
|
---|
| 672 | anonType->setPrimitiveType(primitiveType);
|
---|
| 673 |
|
---|
| 674 | complexType->contentType()->setSimpleType(anonType);
|
---|
| 675 |
|
---|
| 676 | m_schema->addAnonymousType(anonType);
|
---|
| 677 | m_componentLocationHash.insert(anonType, m_componentLocationHash.value(complexType));
|
---|
| 678 | } else {
|
---|
| 679 | complexType->contentType()->setSimpleType(BuiltinTypes::xsAnySimpleType);
|
---|
| 680 | }
|
---|
| 681 | } else if (baseType->isSimpleType()) { // 4
|
---|
| 682 | complexType->contentType()->setSimpleType(baseType);
|
---|
| 683 | } else { // 5
|
---|
| 684 | complexType->contentType()->setSimpleType(BuiltinTypes::xsAnySimpleType);
|
---|
| 685 | }
|
---|
| 686 | }
|
---|
| 687 |
|
---|
| 688 | void XsdSchemaResolver::resolveComplexContentComplexTypes()
|
---|
| 689 | {
|
---|
| 690 | XsdComplexType::List complexTypes;
|
---|
| 691 |
|
---|
| 692 | // first collect the global complex types
|
---|
| 693 | const SchemaType::List types = m_schema->types();
|
---|
| 694 | for (int i = 0; i < types.count(); ++i) {
|
---|
| 695 | if (types.at(i)->isComplexType() && types.at(i)->isDefinedBySchema())
|
---|
| 696 | complexTypes.append(types.at(i));
|
---|
| 697 | }
|
---|
| 698 |
|
---|
| 699 | // then collect all anonymous simple types
|
---|
| 700 | const SchemaType::List anonymousTypes = m_schema->anonymousTypes();
|
---|
| 701 | for (int i = 0; i < anonymousTypes.count(); ++i) {
|
---|
| 702 | if (anonymousTypes.at(i)->isComplexType() && anonymousTypes.at(i)->isDefinedBySchema())
|
---|
| 703 | complexTypes.append(anonymousTypes.at(i));
|
---|
| 704 | }
|
---|
| 705 |
|
---|
| 706 | QSet<XsdComplexType::Ptr> visitedTypes;
|
---|
| 707 | for (int i = 0; i < complexTypes.count(); ++i) {
|
---|
| 708 | if (XsdComplexType::Ptr(complexTypes.at(i))->contentType()->variety() != XsdComplexType::ContentType::Simple)
|
---|
| 709 | resolveComplexContentComplexTypes(complexTypes.at(i), visitedTypes);
|
---|
| 710 | }
|
---|
| 711 | }
|
---|
| 712 |
|
---|
| 713 | void XsdSchemaResolver::resolveComplexContentComplexTypes(const XsdComplexType::Ptr &complexType, QSet<XsdComplexType::Ptr> &visitedTypes)
|
---|
| 714 | {
|
---|
| 715 | if (visitedTypes.contains(complexType))
|
---|
| 716 | return;
|
---|
| 717 | else
|
---|
| 718 | visitedTypes.insert(complexType);
|
---|
| 719 |
|
---|
| 720 | ComplexContentType item;
|
---|
| 721 | bool foundCorrespondingItem = false;
|
---|
| 722 | for (int i = 0; i < m_complexContentTypes.count(); ++i) {
|
---|
| 723 | if (m_complexContentTypes.at(i).complexType == complexType) {
|
---|
| 724 | item = m_complexContentTypes.at(i);
|
---|
| 725 | foundCorrespondingItem = true;
|
---|
| 726 | break;
|
---|
| 727 | }
|
---|
| 728 | }
|
---|
| 729 |
|
---|
| 730 | if (!foundCorrespondingItem)
|
---|
| 731 | return;
|
---|
| 732 |
|
---|
| 733 | const SchemaType::Ptr baseType = complexType->wxsSuperType();
|
---|
| 734 |
|
---|
| 735 | // at this point simple types have been resolved already, so we care about
|
---|
| 736 | // complex types here only
|
---|
| 737 | if (baseType->isComplexType() && baseType->isDefinedBySchema())
|
---|
| 738 | resolveComplexContentComplexTypes(XsdComplexType::Ptr(baseType), visitedTypes);
|
---|
| 739 |
|
---|
| 740 |
|
---|
| 741 | // @see http://www.w3.org/TR/xmlschema11-1/#dcl.ctd.ctcc.common
|
---|
| 742 |
|
---|
| 743 | // 3
|
---|
| 744 | XsdParticle::Ptr effectiveContent;
|
---|
| 745 | if (!item.explicitContent) { // 3.1
|
---|
| 746 | if (item.effectiveMixed == true) { // 3.1.1
|
---|
| 747 | const XsdParticle::Ptr particle(new XsdParticle());
|
---|
| 748 | particle->setMinimumOccurs(1);
|
---|
| 749 | particle->setMaximumOccurs(1);
|
---|
| 750 | particle->setMaximumOccursUnbounded(false);
|
---|
| 751 |
|
---|
| 752 | const XsdModelGroup::Ptr sequence(new XsdModelGroup());
|
---|
| 753 | sequence->setCompositor(XsdModelGroup::SequenceCompositor);
|
---|
| 754 | particle->setTerm(sequence);
|
---|
| 755 |
|
---|
| 756 | effectiveContent = particle;
|
---|
| 757 | } else { // 3.1.2
|
---|
| 758 | effectiveContent = XsdParticle::Ptr();
|
---|
| 759 | }
|
---|
| 760 | } else { // 3.2
|
---|
| 761 | effectiveContent = item.explicitContent;
|
---|
| 762 | }
|
---|
| 763 |
|
---|
| 764 | // 4
|
---|
| 765 | XsdComplexType::ContentType::Ptr explicitContentType(new XsdComplexType::ContentType());
|
---|
| 766 | if (item.complexType->derivationMethod() == XsdComplexType::DerivationRestriction) { // 4.1
|
---|
| 767 | if (!effectiveContent) { // 4.1.1
|
---|
| 768 | explicitContentType->setVariety(XsdComplexType::ContentType::Empty);
|
---|
| 769 | } else { // 4.1.2
|
---|
| 770 | if (item.effectiveMixed == true)
|
---|
| 771 | explicitContentType->setVariety(XsdComplexType::ContentType::Mixed);
|
---|
| 772 | else
|
---|
| 773 | explicitContentType->setVariety(XsdComplexType::ContentType::ElementOnly);
|
---|
| 774 |
|
---|
| 775 | explicitContentType->setParticle(effectiveContent);
|
---|
| 776 | }
|
---|
| 777 | } else if (item.complexType->derivationMethod() == XsdComplexType::DerivationExtension) { // 4.2
|
---|
| 778 | const SchemaType::Ptr baseType = item.complexType->wxsSuperType();
|
---|
| 779 | if (baseType->isSimpleType() || (baseType->isComplexType() && baseType->isDefinedBySchema() && (XsdComplexType::Ptr(baseType)->contentType()->variety() == XsdComplexType::ContentType::Empty ||
|
---|
| 780 | XsdComplexType::Ptr(baseType)->contentType()->variety() == XsdComplexType::ContentType::Simple))) { // 4.2.1
|
---|
| 781 | if (!effectiveContent) {
|
---|
| 782 | explicitContentType->setVariety(XsdComplexType::ContentType::Empty);
|
---|
| 783 | } else {
|
---|
| 784 | if (item.effectiveMixed == true)
|
---|
| 785 | explicitContentType->setVariety(XsdComplexType::ContentType::Mixed);
|
---|
| 786 | else
|
---|
| 787 | explicitContentType->setVariety(XsdComplexType::ContentType::ElementOnly);
|
---|
| 788 |
|
---|
| 789 | explicitContentType->setParticle(effectiveContent);
|
---|
| 790 | }
|
---|
| 791 | } else if (baseType->isComplexType() && baseType->isDefinedBySchema() && (XsdComplexType::Ptr(baseType)->contentType()->variety() == XsdComplexType::ContentType::ElementOnly ||
|
---|
| 792 | XsdComplexType::Ptr(baseType)->contentType()->variety() == XsdComplexType::ContentType::Mixed) && !effectiveContent) { // 4.2.2
|
---|
| 793 | const XsdComplexType::Ptr complexBaseType(baseType);
|
---|
| 794 |
|
---|
| 795 | explicitContentType = complexBaseType->contentType();
|
---|
| 796 | } else { // 4.2.3
|
---|
| 797 | explicitContentType->setVariety(item.effectiveMixed ? XsdComplexType::ContentType::Mixed : XsdComplexType::ContentType::ElementOnly);
|
---|
| 798 |
|
---|
| 799 | XsdParticle::Ptr baseParticle;
|
---|
| 800 | if (baseType == BuiltinTypes::xsAnyType) {
|
---|
| 801 | // we need a workaround here, since the xsAnyType is no real (aka XsdComplexType) complex type...
|
---|
| 802 |
|
---|
| 803 | baseParticle = XsdParticle::Ptr(new XsdParticle());
|
---|
| 804 | baseParticle->setMinimumOccurs(1);
|
---|
| 805 | baseParticle->setMaximumOccurs(1);
|
---|
| 806 | baseParticle->setMaximumOccursUnbounded(false);
|
---|
| 807 |
|
---|
| 808 | const XsdModelGroup::Ptr group(new XsdModelGroup());
|
---|
| 809 | group->setCompositor(XsdModelGroup::SequenceCompositor);
|
---|
| 810 |
|
---|
| 811 | const XsdParticle::Ptr particle(new XsdParticle());
|
---|
| 812 | particle->setMinimumOccurs(0);
|
---|
| 813 | particle->setMaximumOccursUnbounded(true);
|
---|
| 814 |
|
---|
| 815 | const XsdWildcard::Ptr wildcard(new XsdWildcard());
|
---|
| 816 | wildcard->namespaceConstraint()->setVariety(XsdWildcard::NamespaceConstraint::Any);
|
---|
| 817 | wildcard->setProcessContents(XsdWildcard::Lax);
|
---|
| 818 |
|
---|
| 819 | particle->setTerm(wildcard);
|
---|
| 820 | XsdParticle::List particles;
|
---|
| 821 | particles.append(particle);
|
---|
| 822 | group->setParticles(particles);
|
---|
| 823 | baseParticle->setTerm(group);
|
---|
| 824 | } else {
|
---|
| 825 | const XsdComplexType::Ptr complexBaseType(baseType);
|
---|
| 826 | baseParticle = complexBaseType->contentType()->particle();
|
---|
| 827 | }
|
---|
| 828 | if (baseParticle && baseParticle->term()->isModelGroup() && (XsdModelGroup::Ptr(baseParticle->term())->compositor() == XsdModelGroup::AllCompositor) &&
|
---|
| 829 | (!item.explicitContent)) { // 4.2.3.1
|
---|
| 830 |
|
---|
| 831 | explicitContentType->setParticle(baseParticle);
|
---|
| 832 | } else if (baseParticle && baseParticle->term()->isModelGroup() && (XsdModelGroup::Ptr(baseParticle->term())->compositor() == XsdModelGroup::AllCompositor) &&
|
---|
| 833 | (effectiveContent->term()->isModelGroup() && (XsdModelGroup::Ptr(effectiveContent->term())->compositor() == XsdModelGroup::AllCompositor))) { // 4.2.3.2
|
---|
| 834 | const XsdParticle::Ptr particle(new XsdParticle());
|
---|
| 835 | particle->setMinimumOccurs(effectiveContent->minimumOccurs());
|
---|
| 836 | particle->setMaximumOccurs(1);
|
---|
| 837 | particle->setMaximumOccursUnbounded(false);
|
---|
| 838 |
|
---|
| 839 | const XsdModelGroup::Ptr group(new XsdModelGroup());
|
---|
| 840 | group->setCompositor(XsdModelGroup::AllCompositor);
|
---|
| 841 | XsdParticle::List particles = XsdModelGroup::Ptr(baseParticle->term())->particles();
|
---|
| 842 | particles << XsdModelGroup::Ptr(effectiveContent->term())->particles();
|
---|
| 843 | group->setParticles(particles);
|
---|
| 844 | particle->setTerm(group);
|
---|
| 845 |
|
---|
| 846 | explicitContentType->setParticle(particle);
|
---|
| 847 | } else { // 4.2.3.3
|
---|
| 848 | const XsdParticle::Ptr particle(new XsdParticle());
|
---|
| 849 | particle->setMinimumOccurs(1);
|
---|
| 850 | particle->setMaximumOccurs(1);
|
---|
| 851 | particle->setMaximumOccursUnbounded(false);
|
---|
| 852 |
|
---|
| 853 | const XsdModelGroup::Ptr group(new XsdModelGroup());
|
---|
| 854 | group->setCompositor(XsdModelGroup::SequenceCompositor);
|
---|
| 855 |
|
---|
| 856 | if (effectiveContent && effectiveContent->term()->isModelGroup() && XsdModelGroup::Ptr(effectiveContent->term())->compositor() == XsdModelGroup::AllCompositor) {
|
---|
| 857 | m_context->error(QtXmlPatterns::tr("Content model of complex type %1 contains %2 element so it cannot be derived by extension from a non-empty type.")
|
---|
| 858 | .arg(formatType(m_namePool, complexType)).arg(formatKeyword("all")), XsdSchemaContext::XSDError, sourceLocation(complexType));
|
---|
| 859 | return;
|
---|
| 860 | }
|
---|
| 861 |
|
---|
| 862 | if (baseParticle && baseParticle->term()->isModelGroup() && XsdModelGroup::Ptr(baseParticle->term())->compositor() == XsdModelGroup::AllCompositor) {
|
---|
| 863 | m_context->error(QtXmlPatterns::tr("Complex type %1 cannot be derived by extension from %2 as the latter contains %3 element in its content model.")
|
---|
| 864 | .arg(formatType(m_namePool, complexType))
|
---|
| 865 | .arg(formatType(m_namePool, baseType))
|
---|
| 866 | .arg(formatKeyword("all")), XsdSchemaContext::XSDError, sourceLocation(complexType));
|
---|
| 867 | return;
|
---|
| 868 | }
|
---|
| 869 |
|
---|
| 870 | XsdParticle::List particles;
|
---|
| 871 | if (baseParticle)
|
---|
| 872 | particles << baseParticle;
|
---|
| 873 | if (effectiveContent)
|
---|
| 874 | particles << effectiveContent;
|
---|
| 875 | group->setParticles(particles);
|
---|
| 876 | particle->setTerm(group);
|
---|
| 877 |
|
---|
| 878 | explicitContentType->setParticle(particle);
|
---|
| 879 | }
|
---|
| 880 |
|
---|
| 881 | if (baseType->isDefinedBySchema()) { // xs:anyType has no open content
|
---|
| 882 | const XsdComplexType::Ptr complexBaseType(baseType);
|
---|
| 883 | explicitContentType->setOpenContent(complexBaseType->contentType()->openContent());
|
---|
| 884 | }
|
---|
| 885 | }
|
---|
| 886 | }
|
---|
| 887 |
|
---|
| 888 | // 5
|
---|
| 889 | XsdComplexType::OpenContent::Ptr wildcardElement;
|
---|
| 890 | if (item.complexType->contentType()->openContent()) { // 5.1
|
---|
| 891 | wildcardElement = item.complexType->contentType()->openContent();
|
---|
| 892 | } else {
|
---|
| 893 | if (m_defaultOpenContent) { // 5.2
|
---|
| 894 | if ((explicitContentType->variety() != XsdComplexType::ContentType::Empty) || // 5.2.1
|
---|
| 895 | (explicitContentType->variety() == XsdComplexType::ContentType::Empty && m_defaultOpenContentAppliesToEmpty)) { // 5.2.2
|
---|
| 896 | wildcardElement = m_defaultOpenContent;
|
---|
| 897 | }
|
---|
| 898 | }
|
---|
| 899 | }
|
---|
| 900 |
|
---|
| 901 | // 6
|
---|
| 902 | if (!wildcardElement) { // 6.1
|
---|
| 903 | item.complexType->setContentType(explicitContentType);
|
---|
| 904 | } else {
|
---|
| 905 | if (wildcardElement->mode() == XsdComplexType::OpenContent::None) { // 6.2
|
---|
| 906 | const XsdComplexType::ContentType::Ptr contentType(new XsdComplexType::ContentType());
|
---|
| 907 | contentType->setVariety(explicitContentType->variety());
|
---|
| 908 | contentType->setParticle(explicitContentType->particle());
|
---|
| 909 |
|
---|
| 910 | item.complexType->setContentType(contentType);
|
---|
| 911 | } else { // 6.3
|
---|
| 912 | const XsdComplexType::ContentType::Ptr contentType(new XsdComplexType::ContentType());
|
---|
| 913 |
|
---|
| 914 | if (explicitContentType->variety() == XsdComplexType::ContentType::Empty)
|
---|
| 915 | contentType->setVariety(XsdComplexType::ContentType::ElementOnly);
|
---|
| 916 | else
|
---|
| 917 | contentType->setVariety(explicitContentType->variety());
|
---|
| 918 |
|
---|
| 919 | if (explicitContentType->variety() == XsdComplexType::ContentType::Empty) {
|
---|
| 920 | const XsdParticle::Ptr particle(new XsdParticle());
|
---|
| 921 | particle->setMinimumOccurs(1);
|
---|
| 922 | particle->setMaximumOccurs(1);
|
---|
| 923 | const XsdModelGroup::Ptr sequence(new XsdModelGroup());
|
---|
| 924 | sequence->setCompositor(XsdModelGroup::SequenceCompositor);
|
---|
| 925 | particle->setTerm(sequence);
|
---|
| 926 | contentType->setParticle(particle);
|
---|
| 927 | } else {
|
---|
| 928 | contentType->setParticle(explicitContentType->particle());
|
---|
| 929 | }
|
---|
| 930 |
|
---|
| 931 | const XsdComplexType::OpenContent::Ptr openContent(new XsdComplexType::OpenContent());
|
---|
| 932 | if (wildcardElement)
|
---|
| 933 | openContent->setMode(wildcardElement->mode());
|
---|
| 934 | else
|
---|
| 935 | openContent->setMode(XsdComplexType::OpenContent::Interleave);
|
---|
| 936 |
|
---|
| 937 | if (wildcardElement)
|
---|
| 938 | openContent->setWildcard(wildcardElement->wildcard());
|
---|
| 939 |
|
---|
| 940 | item.complexType->setContentType(contentType);
|
---|
| 941 | }
|
---|
| 942 | }
|
---|
| 943 | }
|
---|
| 944 |
|
---|
| 945 | void XsdSchemaResolver::resolveAttributeTypes()
|
---|
| 946 | {
|
---|
| 947 | for (int i = 0; i < m_attributeTypes.count(); ++i) {
|
---|
| 948 | const AttributeType item = m_attributeTypes.at(i);
|
---|
| 949 |
|
---|
| 950 | SchemaType::Ptr type = m_schema->type(item.typeName);
|
---|
| 951 | if (!type) {
|
---|
| 952 | // maybe it's a basic type...
|
---|
| 953 | type = m_context->schemaTypeFactory()->createSchemaType(item.typeName);
|
---|
| 954 | if (!type) {
|
---|
| 955 | m_context->error(QtXmlPatterns::tr("Type %1 of %2 element cannot be resolved.")
|
---|
| 956 | .arg(formatType(m_namePool, item.typeName))
|
---|
| 957 | .arg(formatElement("attribute")),
|
---|
| 958 | XsdSchemaContext::XSDError, item.location);
|
---|
| 959 | return;
|
---|
| 960 | }
|
---|
| 961 | }
|
---|
| 962 |
|
---|
| 963 | if (!type->isSimpleType() && type->category() != SchemaType::None) {
|
---|
| 964 | m_context->error(QtXmlPatterns::tr("Type of %1 element must be a simple type, %2 is not.")
|
---|
| 965 | .arg(formatElement("attribute"))
|
---|
| 966 | .arg(formatType(m_namePool, item.typeName)),
|
---|
| 967 | XsdSchemaContext::XSDError, item.location);
|
---|
| 968 | return;
|
---|
| 969 | }
|
---|
| 970 |
|
---|
| 971 | item.attribute->setType(type);
|
---|
| 972 | }
|
---|
| 973 | }
|
---|
| 974 |
|
---|
| 975 | void XsdSchemaResolver::resolveAlternativeTypes()
|
---|
| 976 | {
|
---|
| 977 | for (int i = 0; i < m_alternativeTypes.count(); ++i) {
|
---|
| 978 | const AlternativeType item = m_alternativeTypes.at(i);
|
---|
| 979 |
|
---|
| 980 | SchemaType::Ptr type = m_schema->type(item.typeName);
|
---|
| 981 | if (!type) {
|
---|
| 982 | // maybe it's a basic type...
|
---|
| 983 | type = m_context->schemaTypeFactory()->createSchemaType(item.typeName);
|
---|
| 984 | if (!type) {
|
---|
| 985 | m_context->error(QtXmlPatterns::tr("Type %1 of %2 element cannot be resolved.")
|
---|
| 986 | .arg(formatType(m_namePool, item.typeName))
|
---|
| 987 | .arg(formatElement("alternative")),
|
---|
| 988 | XsdSchemaContext::XSDError, item.location);
|
---|
| 989 | return;
|
---|
| 990 | }
|
---|
| 991 | }
|
---|
| 992 |
|
---|
| 993 | item.alternative->setType(type);
|
---|
| 994 | }
|
---|
| 995 |
|
---|
| 996 | for (int i = 0; i < m_alternativeTypeElements.count(); ++i) {
|
---|
| 997 | const AlternativeTypeElement item = m_alternativeTypeElements.at(i);
|
---|
| 998 | item.alternative->setType(item.element->type());
|
---|
| 999 | }
|
---|
| 1000 | }
|
---|
| 1001 |
|
---|
| 1002 | bool hasCircularSubstitutionGroup(const XsdElement::Ptr ¤t, const XsdElement::Ptr &head, const NamePool::Ptr &namePool)
|
---|
| 1003 | {
|
---|
| 1004 | if (current == head)
|
---|
| 1005 | return true;
|
---|
| 1006 | else {
|
---|
| 1007 | const XsdElement::List elements = current->substitutionGroupAffiliations();
|
---|
| 1008 | for (int i = 0; i < elements.count(); ++i) {
|
---|
| 1009 | if (hasCircularSubstitutionGroup(elements.at(i), head, namePool))
|
---|
| 1010 | return true;
|
---|
| 1011 | }
|
---|
| 1012 | }
|
---|
| 1013 |
|
---|
| 1014 | return false;
|
---|
| 1015 | }
|
---|
| 1016 |
|
---|
| 1017 | void XsdSchemaResolver::resolveSubstitutionGroupAffiliations()
|
---|
| 1018 | {
|
---|
| 1019 | for (int i = 0; i < m_substitutionGroupAffiliations.count(); ++i) {
|
---|
| 1020 | const SubstitutionGroupAffiliation item = m_substitutionGroupAffiliations.at(i);
|
---|
| 1021 |
|
---|
| 1022 | XsdElement::List affiliations;
|
---|
| 1023 | for (int j = 0; j < item.elementNames.count(); ++j) {
|
---|
| 1024 | const XsdElement::Ptr element = m_schema->element(item.elementNames.at(j));
|
---|
| 1025 | if (!element) {
|
---|
| 1026 | m_context->error(QtXmlPatterns::tr("Substitution group %1 of %2 element cannot be resolved.")
|
---|
| 1027 | .arg(formatKeyword(m_namePool, item.elementNames.at(j)))
|
---|
| 1028 | .arg(formatElement("element")),
|
---|
| 1029 | XsdSchemaContext::XSDError, item.location);
|
---|
| 1030 | return;
|
---|
| 1031 | }
|
---|
| 1032 |
|
---|
| 1033 | // @see http://www.w3.org/TR/xmlschema11-1/#e-props-correct 5)
|
---|
| 1034 | if (hasCircularSubstitutionGroup(element, item.element, m_namePool)) {
|
---|
| 1035 | m_context->error(QtXmlPatterns::tr("Substitution group %1 has circular definition.").arg(formatKeyword(m_namePool, item.elementNames.at(j))), XsdSchemaContext::XSDError, item.location);
|
---|
| 1036 | return;
|
---|
| 1037 | }
|
---|
| 1038 |
|
---|
| 1039 | affiliations.append(element);
|
---|
| 1040 | }
|
---|
| 1041 |
|
---|
| 1042 | item.element->setSubstitutionGroupAffiliations(affiliations);
|
---|
| 1043 | }
|
---|
| 1044 |
|
---|
| 1045 | for (int i = 0; i < m_substitutionGroupTypes.count(); ++i) {
|
---|
| 1046 | const XsdElement::Ptr element = m_substitutionGroupTypes.at(i);
|
---|
| 1047 | element->setType(element->substitutionGroupAffiliations().first()->type());
|
---|
| 1048 | }
|
---|
| 1049 | }
|
---|
| 1050 |
|
---|
| 1051 | bool isSubstGroupHeadOf(const XsdElement::Ptr &head, const XsdElement::Ptr &element, const NamePool::Ptr &namePool)
|
---|
| 1052 | {
|
---|
| 1053 | if (head->name(namePool) == element->name(namePool))
|
---|
| 1054 | return true;
|
---|
| 1055 |
|
---|
| 1056 | const XsdElement::List affiliations = element->substitutionGroupAffiliations();
|
---|
| 1057 | for (int i = 0; i < affiliations.count(); ++i) {
|
---|
| 1058 | if (isSubstGroupHeadOf(head, affiliations.at(i), namePool))
|
---|
| 1059 | return true;
|
---|
| 1060 | }
|
---|
| 1061 |
|
---|
| 1062 | return false;
|
---|
| 1063 | }
|
---|
| 1064 |
|
---|
| 1065 | void XsdSchemaResolver::resolveSubstitutionGroups()
|
---|
| 1066 | {
|
---|
| 1067 | const XsdElement::List elements = m_schema->elements();
|
---|
| 1068 | for (int i = 0; i < elements.count(); ++i) {
|
---|
| 1069 | const XsdElement::Ptr element = elements.at(i);
|
---|
| 1070 |
|
---|
| 1071 | // the element is always itself in the substitution group
|
---|
| 1072 | element->addSubstitutionGroup(element);
|
---|
| 1073 |
|
---|
| 1074 | for (int j = 0; j < elements.count(); ++j) {
|
---|
| 1075 | if (i == j)
|
---|
| 1076 | continue;
|
---|
| 1077 |
|
---|
| 1078 | if (isSubstGroupHeadOf(element, elements.at(j), m_namePool))
|
---|
| 1079 | element->addSubstitutionGroup(elements.at(j));
|
---|
| 1080 | }
|
---|
| 1081 | }
|
---|
| 1082 | }
|
---|
| 1083 |
|
---|
| 1084 | void XsdSchemaResolver::resolveTermReferences()
|
---|
| 1085 | {
|
---|
| 1086 | // first the global complex types
|
---|
| 1087 | const SchemaType::List types = m_schema->types();
|
---|
| 1088 | for (int i = 0; i < types.count(); ++i) {
|
---|
| 1089 | if (!(types.at(i)->isComplexType()) || !types.at(i)->isDefinedBySchema())
|
---|
| 1090 | continue;
|
---|
| 1091 |
|
---|
| 1092 | const XsdComplexType::Ptr complexType = types.at(i);
|
---|
| 1093 | if (complexType->contentType()->variety() != XsdComplexType::ContentType::ElementOnly && complexType->contentType()->variety() != XsdComplexType::ContentType::Mixed)
|
---|
| 1094 | continue;
|
---|
| 1095 |
|
---|
| 1096 | resolveTermReference(complexType->contentType()->particle(), QSet<QXmlName>());
|
---|
| 1097 | }
|
---|
| 1098 |
|
---|
| 1099 | // then all anonymous complex types
|
---|
| 1100 | const SchemaType::List anonymousTypes = m_schema->anonymousTypes();
|
---|
| 1101 | for (int i = 0; i < anonymousTypes.count(); ++i) {
|
---|
| 1102 | if (!(anonymousTypes.at(i)->isComplexType()) || !anonymousTypes.at(i)->isDefinedBySchema())
|
---|
| 1103 | continue;
|
---|
| 1104 |
|
---|
| 1105 | const XsdComplexType::Ptr complexType = anonymousTypes.at(i);
|
---|
| 1106 | if (complexType->contentType()->variety() != XsdComplexType::ContentType::ElementOnly && complexType->contentType()->variety() != XsdComplexType::ContentType::Mixed)
|
---|
| 1107 | continue;
|
---|
| 1108 |
|
---|
| 1109 | resolveTermReference(complexType->contentType()->particle(), QSet<QXmlName>());
|
---|
| 1110 | }
|
---|
| 1111 |
|
---|
| 1112 | const XsdModelGroup::List groups = m_schema->elementGroups();
|
---|
| 1113 | for (int i = 0; i < groups.count(); ++i) {
|
---|
| 1114 | const XsdParticle::Ptr particle(new XsdParticle());
|
---|
| 1115 | particle->setTerm(groups.at(i));
|
---|
| 1116 | resolveTermReference(particle, QSet<QXmlName>());
|
---|
| 1117 | }
|
---|
| 1118 | }
|
---|
| 1119 |
|
---|
| 1120 | void XsdSchemaResolver::resolveTermReference(const XsdParticle::Ptr &particle, QSet<QXmlName> visitedGroups)
|
---|
| 1121 | {
|
---|
| 1122 | if (!particle)
|
---|
| 1123 | return;
|
---|
| 1124 |
|
---|
| 1125 | const XsdTerm::Ptr term = particle->term();
|
---|
| 1126 |
|
---|
| 1127 | // if it is a model group, we iterate over it recursive...
|
---|
| 1128 | if (term->isModelGroup()) {
|
---|
| 1129 | const XsdModelGroup::Ptr modelGroup = term;
|
---|
| 1130 | const XsdParticle::List particles = modelGroup->particles();
|
---|
| 1131 |
|
---|
| 1132 | for (int i = 0; i < particles.count(); ++i) {
|
---|
| 1133 | resolveTermReference(particles.at(i), visitedGroups);
|
---|
| 1134 | }
|
---|
| 1135 |
|
---|
| 1136 | // check for unique names of elements inside all compositor
|
---|
| 1137 | if (modelGroup->compositor() != XsdModelGroup::ChoiceCompositor) {
|
---|
| 1138 | for (int i = 0; i < particles.count(); ++i) {
|
---|
| 1139 | const XsdParticle::Ptr particle = particles.at(i);
|
---|
| 1140 | const XsdTerm::Ptr term = particle->term();
|
---|
| 1141 |
|
---|
| 1142 | if (!(term->isElement()))
|
---|
| 1143 | continue;
|
---|
| 1144 |
|
---|
| 1145 | for (int j = 0; j < particles.count(); ++j) {
|
---|
| 1146 | const XsdParticle::Ptr otherParticle = particles.at(j);
|
---|
| 1147 | const XsdTerm::Ptr otherTerm = otherParticle->term();
|
---|
| 1148 |
|
---|
| 1149 | if (otherTerm->isElement() && i != j) {
|
---|
| 1150 | const XsdElement::Ptr element = term;
|
---|
| 1151 | const XsdElement::Ptr otherElement = otherTerm;
|
---|
| 1152 |
|
---|
| 1153 | if (element->name(m_namePool) == otherElement->name(m_namePool)) {
|
---|
| 1154 | if (modelGroup->compositor() == XsdModelGroup::AllCompositor) {
|
---|
| 1155 | m_context->error(QtXmlPatterns::tr("Duplicated element names %1 in %2 element.")
|
---|
| 1156 | .arg(formatKeyword(element->displayName(m_namePool)))
|
---|
| 1157 | .arg(formatElement("all")),
|
---|
| 1158 | XsdSchemaContext::XSDError, sourceLocation(modelGroup));
|
---|
| 1159 | return;
|
---|
| 1160 | } else if (modelGroup->compositor() == XsdModelGroup::SequenceCompositor) {
|
---|
| 1161 | if (element->type() != otherElement->type()) { // not same variety
|
---|
| 1162 | m_context->error(QtXmlPatterns::tr("Duplicated element names %1 in %2 element.")
|
---|
| 1163 | .arg(formatKeyword(element->displayName(m_namePool)))
|
---|
| 1164 | .arg(formatElement("sequence")),
|
---|
| 1165 | XsdSchemaContext::XSDError, sourceLocation(modelGroup));
|
---|
| 1166 | return;
|
---|
| 1167 | }
|
---|
| 1168 | }
|
---|
| 1169 | }
|
---|
| 1170 | }
|
---|
| 1171 | }
|
---|
| 1172 | }
|
---|
| 1173 | }
|
---|
| 1174 |
|
---|
| 1175 | return;
|
---|
| 1176 | }
|
---|
| 1177 |
|
---|
| 1178 | // ...otherwise we have reached the end of recursion...
|
---|
| 1179 | if (!term->isReference())
|
---|
| 1180 | return;
|
---|
| 1181 |
|
---|
| 1182 | // ...or we have reached a reference term that must be resolved
|
---|
| 1183 | const XsdReference::Ptr reference = term;
|
---|
| 1184 | switch (reference->type()) {
|
---|
| 1185 | case XsdReference::Element:
|
---|
| 1186 | {
|
---|
| 1187 | const XsdElement::Ptr element = m_schema->element(reference->referenceName());
|
---|
| 1188 | if (element) {
|
---|
| 1189 | particle->setTerm(element);
|
---|
| 1190 | } else {
|
---|
| 1191 | m_context->error(QtXmlPatterns::tr("Reference %1 of %2 element cannot be resolved.")
|
---|
| 1192 | .arg(formatKeyword(m_namePool, reference->referenceName()))
|
---|
| 1193 | .arg(formatElement("element")),
|
---|
| 1194 | XsdSchemaContext::XSDError, reference->sourceLocation());
|
---|
| 1195 | return;
|
---|
| 1196 | }
|
---|
| 1197 | }
|
---|
| 1198 | break;
|
---|
| 1199 | case XsdReference::ModelGroup:
|
---|
| 1200 | {
|
---|
| 1201 | const XsdModelGroup::Ptr modelGroup = m_schema->elementGroup(reference->referenceName());
|
---|
| 1202 | if (modelGroup) {
|
---|
| 1203 | if (visitedGroups.contains(modelGroup->name(m_namePool))) {
|
---|
| 1204 | m_context->error(QtXmlPatterns::tr("Circular group reference for %1.").arg(formatKeyword(modelGroup->displayName(m_namePool))),
|
---|
| 1205 | XsdSchemaContext::XSDError, reference->sourceLocation());
|
---|
| 1206 | } else {
|
---|
| 1207 | visitedGroups.insert(modelGroup->name(m_namePool));
|
---|
| 1208 | }
|
---|
| 1209 |
|
---|
| 1210 | particle->setTerm(modelGroup);
|
---|
| 1211 |
|
---|
| 1212 | // start recursive iteration here as well to get all references resolved
|
---|
| 1213 | const XsdParticle::List particles = modelGroup->particles();
|
---|
| 1214 | for (int i = 0; i < particles.count(); ++i) {
|
---|
| 1215 | resolveTermReference(particles.at(i), visitedGroups);
|
---|
| 1216 | }
|
---|
| 1217 |
|
---|
| 1218 | if (modelGroup->compositor() == XsdModelGroup::AllCompositor) {
|
---|
| 1219 | if (m_allGroups.contains(reference)) {
|
---|
| 1220 | m_context->error(QtXmlPatterns::tr("%1 element is not allowed in this scope").arg(formatElement("all.")),
|
---|
| 1221 | XsdSchemaContext::XSDError, reference->sourceLocation());
|
---|
| 1222 | return;
|
---|
| 1223 | }
|
---|
| 1224 | if (particle->maximumOccursUnbounded() || particle->maximumOccurs() != 1) {
|
---|
| 1225 | m_context->error(QtXmlPatterns::tr("%1 element cannot have %2 attribute with value other than %3.")
|
---|
| 1226 | .arg(formatElement("all"))
|
---|
| 1227 | .arg(formatAttribute("maxOccurs"))
|
---|
| 1228 | .arg(formatData("1")),
|
---|
| 1229 | XsdSchemaContext::XSDError, reference->sourceLocation());
|
---|
| 1230 | return;
|
---|
| 1231 | }
|
---|
| 1232 | if (particle->minimumOccurs() != 0 && particle->minimumOccurs() != 1) {
|
---|
| 1233 | m_context->error(QtXmlPatterns::tr("%1 element cannot have %2 attribute with value other than %3 or %4.")
|
---|
| 1234 | .arg(formatElement("all"))
|
---|
| 1235 | .arg(formatAttribute("minOccurs"))
|
---|
| 1236 | .arg(formatData("0"))
|
---|
| 1237 | .arg(formatData("1")),
|
---|
| 1238 | XsdSchemaContext::XSDError, reference->sourceLocation());
|
---|
| 1239 | return;
|
---|
| 1240 | }
|
---|
| 1241 | }
|
---|
| 1242 | } else {
|
---|
| 1243 | m_context->error(QtXmlPatterns::tr("Reference %1 of %2 element cannot be resolved.")
|
---|
| 1244 | .arg(formatKeyword(m_namePool, reference->referenceName()))
|
---|
| 1245 | .arg(formatElement("group")),
|
---|
| 1246 | XsdSchemaContext::XSDError, reference->sourceLocation());
|
---|
| 1247 | return;
|
---|
| 1248 | }
|
---|
| 1249 | }
|
---|
| 1250 | break;
|
---|
| 1251 | }
|
---|
| 1252 | }
|
---|
| 1253 |
|
---|
| 1254 | void XsdSchemaResolver::resolveAttributeTermReferences()
|
---|
| 1255 | {
|
---|
| 1256 | // first all global attribute groups
|
---|
| 1257 | const XsdAttributeGroup::List attributeGroups = m_schema->attributeGroups();
|
---|
| 1258 | for (int i = 0; i < attributeGroups.count(); ++i) {
|
---|
| 1259 | XsdWildcard::Ptr wildcard = attributeGroups.at(i)->wildcard();
|
---|
| 1260 | const XsdAttributeUse::List uses = resolveAttributeTermReferences(attributeGroups.at(i)->attributeUses(), wildcard, QSet<QXmlName>());
|
---|
| 1261 | attributeGroups.at(i)->setAttributeUses(uses);
|
---|
| 1262 | attributeGroups.at(i)->setWildcard(wildcard);
|
---|
| 1263 | }
|
---|
| 1264 |
|
---|
| 1265 | // then the global complex types
|
---|
| 1266 | const SchemaType::List types = m_schema->types();
|
---|
| 1267 | for (int i = 0; i < types.count(); ++i) {
|
---|
| 1268 | if (!(types.at(i)->isComplexType()) || !types.at(i)->isDefinedBySchema())
|
---|
| 1269 | continue;
|
---|
| 1270 |
|
---|
| 1271 | const XsdComplexType::Ptr complexType = types.at(i);
|
---|
| 1272 | const XsdAttributeUse::List attributeUses = complexType->attributeUses();
|
---|
| 1273 |
|
---|
| 1274 | XsdWildcard::Ptr wildcard = complexType->attributeWildcard();
|
---|
| 1275 | const XsdAttributeUse::List uses = resolveAttributeTermReferences(attributeUses, wildcard, QSet<QXmlName>());
|
---|
| 1276 | complexType->setAttributeUses(uses);
|
---|
| 1277 | complexType->setAttributeWildcard(wildcard);
|
---|
| 1278 | }
|
---|
| 1279 |
|
---|
| 1280 | // and afterwards all anonymous complex types
|
---|
| 1281 | const SchemaType::List anonymousTypes = m_schema->anonymousTypes();
|
---|
| 1282 | for (int i = 0; i < anonymousTypes.count(); ++i) {
|
---|
| 1283 | if (!(anonymousTypes.at(i)->isComplexType()) || !anonymousTypes.at(i)->isDefinedBySchema())
|
---|
| 1284 | continue;
|
---|
| 1285 |
|
---|
| 1286 | const XsdComplexType::Ptr complexType = anonymousTypes.at(i);
|
---|
| 1287 | const XsdAttributeUse::List attributeUses = complexType->attributeUses();
|
---|
| 1288 |
|
---|
| 1289 | XsdWildcard::Ptr wildcard = complexType->attributeWildcard();
|
---|
| 1290 | const XsdAttributeUse::List uses = resolveAttributeTermReferences(attributeUses, wildcard, QSet<QXmlName>());
|
---|
| 1291 | complexType->setAttributeUses(uses);
|
---|
| 1292 | complexType->setAttributeWildcard(wildcard);
|
---|
| 1293 | }
|
---|
| 1294 | }
|
---|
| 1295 |
|
---|
| 1296 | XsdAttributeUse::List XsdSchemaResolver::resolveAttributeTermReferences(const XsdAttributeUse::List &attributeUses, XsdWildcard::Ptr &wildcard, QSet<QXmlName> visitedAttributeGroups)
|
---|
| 1297 | {
|
---|
| 1298 | XsdAttributeUse::List resolvedAttributeUses;
|
---|
| 1299 |
|
---|
| 1300 | for (int i = 0; i < attributeUses.count(); ++i) {
|
---|
| 1301 | const XsdAttributeUse::Ptr attributeUse = attributeUses.at(i);
|
---|
| 1302 | if (attributeUse->isAttributeUse()) {
|
---|
| 1303 | // it is a real attribute use, so no need to resolve it
|
---|
| 1304 | resolvedAttributeUses.append(attributeUse);
|
---|
| 1305 | } else if (attributeUse->isReference()) {
|
---|
| 1306 | // it is just a reference, so resolve it to the real attribute use
|
---|
| 1307 |
|
---|
| 1308 | const XsdAttributeReference::Ptr reference = attributeUse;
|
---|
| 1309 | if (reference->type() == XsdAttributeReference::AttributeUse) {
|
---|
| 1310 |
|
---|
| 1311 | // lookup the real attribute
|
---|
| 1312 | const XsdAttribute::Ptr attribute = m_schema->attribute(reference->referenceName());
|
---|
| 1313 | if (!attribute) {
|
---|
| 1314 | m_context->error(QtXmlPatterns::tr("Reference %1 of %2 element cannot be resolved.")
|
---|
| 1315 | .arg(formatKeyword(m_namePool, reference->referenceName()))
|
---|
| 1316 | .arg(formatElement("attribute")),
|
---|
| 1317 | XsdSchemaContext::XSDError, reference->sourceLocation());
|
---|
| 1318 | return XsdAttributeUse::List();
|
---|
| 1319 | }
|
---|
| 1320 |
|
---|
| 1321 | // if both, reference and definition have a fixed or default value set, then they must be equal
|
---|
| 1322 | if (attribute->valueConstraint() && attributeUse->valueConstraint()) {
|
---|
| 1323 | if (attribute->valueConstraint()->value() != attributeUse->valueConstraint()->value()) {
|
---|
| 1324 | m_context->error(QtXmlPatterns::tr("%1 or %2 attribute of reference %3 does not match with the attribute declaration %4.")
|
---|
| 1325 | .arg(formatAttribute("fixed"))
|
---|
| 1326 | .arg(formatAttribute("default"))
|
---|
| 1327 | .arg(formatKeyword(m_namePool, reference->referenceName()))
|
---|
| 1328 | .arg(formatKeyword(attribute->displayName(m_namePool))),
|
---|
| 1329 | XsdSchemaContext::XSDError, reference->sourceLocation());
|
---|
| 1330 | return XsdAttributeUse::List();
|
---|
| 1331 | }
|
---|
| 1332 | }
|
---|
| 1333 |
|
---|
| 1334 | attributeUse->setAttribute(attribute);
|
---|
| 1335 | if (!attributeUse->valueConstraint() && attribute->valueConstraint())
|
---|
| 1336 | attributeUse->setValueConstraint(XsdAttributeUse::ValueConstraint::fromAttributeValueConstraint(attribute->valueConstraint()));
|
---|
| 1337 |
|
---|
| 1338 | resolvedAttributeUses.append(attributeUse);
|
---|
| 1339 | } else if (reference->type() == XsdAttributeReference::AttributeGroup) {
|
---|
| 1340 | const XsdAttributeGroup::Ptr attributeGroup = m_schema->attributeGroup(reference->referenceName());
|
---|
| 1341 | if (!attributeGroup) {
|
---|
| 1342 | m_context->error(QtXmlPatterns::tr("Reference %1 of %2 element cannot be resolved.")
|
---|
| 1343 | .arg(formatKeyword(m_namePool, reference->referenceName()))
|
---|
| 1344 | .arg(formatElement("attributeGroup")),
|
---|
| 1345 | XsdSchemaContext::XSDError, reference->sourceLocation());
|
---|
| 1346 | return XsdAttributeUse::List();
|
---|
| 1347 | }
|
---|
| 1348 | if (visitedAttributeGroups.contains(attributeGroup->name(m_namePool))) {
|
---|
| 1349 | m_context->error(QtXmlPatterns::tr("Attribute group %1 has circular reference.").arg(formatKeyword(m_namePool, reference->referenceName())),
|
---|
| 1350 | XsdSchemaContext::XSDError, reference->sourceLocation());
|
---|
| 1351 | return XsdAttributeUse::List();
|
---|
| 1352 | } else {
|
---|
| 1353 | visitedAttributeGroups.insert(attributeGroup->name(m_namePool));
|
---|
| 1354 | }
|
---|
| 1355 |
|
---|
| 1356 | // resolve attribute wildcards as defined in http://www.w3.org/TR/xmlschema11-1/#declare-attributeGroup-wildcard
|
---|
| 1357 | XsdWildcard::Ptr childWildcard;
|
---|
| 1358 | resolvedAttributeUses << resolveAttributeTermReferences(attributeGroup->attributeUses(), childWildcard, visitedAttributeGroups);
|
---|
| 1359 | if (!childWildcard) {
|
---|
| 1360 | if (attributeGroup->wildcard()) {
|
---|
| 1361 | if (wildcard) {
|
---|
| 1362 | const XsdWildcard::ProcessContents contents = wildcard->processContents();
|
---|
| 1363 | wildcard = XsdSchemaHelper::wildcardIntersection(wildcard, attributeGroup->wildcard());
|
---|
| 1364 | wildcard->setProcessContents(contents);
|
---|
| 1365 | } else {
|
---|
| 1366 | wildcard = attributeGroup->wildcard();
|
---|
| 1367 | }
|
---|
| 1368 | }
|
---|
| 1369 | } else {
|
---|
| 1370 | XsdWildcard::Ptr newWildcard;
|
---|
| 1371 | if (attributeGroup->wildcard()) {
|
---|
| 1372 | const XsdWildcard::ProcessContents contents = attributeGroup->wildcard()->processContents();
|
---|
| 1373 | newWildcard = XsdSchemaHelper::wildcardIntersection(attributeGroup->wildcard(), childWildcard);
|
---|
| 1374 | newWildcard->setProcessContents(contents);
|
---|
| 1375 | } else {
|
---|
| 1376 | newWildcard = childWildcard;
|
---|
| 1377 | }
|
---|
| 1378 |
|
---|
| 1379 | if (wildcard) {
|
---|
| 1380 | const XsdWildcard::ProcessContents contents = wildcard->processContents();
|
---|
| 1381 | wildcard = XsdSchemaHelper::wildcardIntersection(wildcard, newWildcard);
|
---|
| 1382 | wildcard->setProcessContents(contents);
|
---|
| 1383 | } else {
|
---|
| 1384 | wildcard = newWildcard;
|
---|
| 1385 | }
|
---|
| 1386 | }
|
---|
| 1387 | }
|
---|
| 1388 | }
|
---|
| 1389 | }
|
---|
| 1390 |
|
---|
| 1391 | return resolvedAttributeUses;
|
---|
| 1392 | }
|
---|
| 1393 |
|
---|
| 1394 | void XsdSchemaResolver::resolveAttributeInheritance()
|
---|
| 1395 | {
|
---|
| 1396 | // collect the global and anonymous complex types
|
---|
| 1397 | SchemaType::List types = m_schema->types();
|
---|
| 1398 | types << m_schema->anonymousTypes();
|
---|
| 1399 |
|
---|
| 1400 | QSet<XsdComplexType::Ptr> visitedTypes;
|
---|
| 1401 | for (int i = 0; i < types.count(); ++i) {
|
---|
| 1402 | if (!(types.at(i)->isComplexType()) || !types.at(i)->isDefinedBySchema())
|
---|
| 1403 | continue;
|
---|
| 1404 |
|
---|
| 1405 | const XsdComplexType::Ptr complexType = types.at(i);
|
---|
| 1406 |
|
---|
| 1407 | resolveAttributeInheritance(complexType, visitedTypes);
|
---|
| 1408 | }
|
---|
| 1409 | }
|
---|
| 1410 |
|
---|
| 1411 | bool isValidWildcardRestriction(const XsdWildcard::Ptr &wildcard, const XsdWildcard::Ptr &baseWildcard)
|
---|
| 1412 | {
|
---|
| 1413 | if (wildcard->namespaceConstraint()->variety() == baseWildcard->namespaceConstraint()->variety()) {
|
---|
| 1414 | if (!XsdSchemaHelper::checkWildcardProcessContents(baseWildcard, wildcard))
|
---|
| 1415 | return false;
|
---|
| 1416 | }
|
---|
| 1417 |
|
---|
| 1418 | if (wildcard->namespaceConstraint()->variety() == XsdWildcard::NamespaceConstraint::Any &&
|
---|
| 1419 | baseWildcard->namespaceConstraint()->variety() != XsdWildcard::NamespaceConstraint::Any ) {
|
---|
| 1420 | return false;
|
---|
| 1421 | }
|
---|
| 1422 | if (baseWildcard->namespaceConstraint()->variety() == XsdWildcard::NamespaceConstraint::Not &&
|
---|
| 1423 | wildcard->namespaceConstraint()->variety() == XsdWildcard::NamespaceConstraint::Enumeration) {
|
---|
| 1424 | if (!baseWildcard->namespaceConstraint()->namespaces().intersect(wildcard->namespaceConstraint()->namespaces()).isEmpty())
|
---|
| 1425 | return false;
|
---|
| 1426 | }
|
---|
| 1427 | if (baseWildcard->namespaceConstraint()->variety() == XsdWildcard::NamespaceConstraint::Enumeration &&
|
---|
| 1428 | wildcard->namespaceConstraint()->variety() == XsdWildcard::NamespaceConstraint::Enumeration) {
|
---|
| 1429 | if (!wildcard->namespaceConstraint()->namespaces().subtract(baseWildcard->namespaceConstraint()->namespaces()).isEmpty())
|
---|
| 1430 | return false;
|
---|
| 1431 | }
|
---|
| 1432 |
|
---|
| 1433 | return true;
|
---|
| 1434 | }
|
---|
| 1435 |
|
---|
| 1436 | /*
|
---|
| 1437 | * Since we inherit the attributes from our base class we have to walk up in the
|
---|
| 1438 | * inheritance hierarchy first and resolve the attribute inheritance top-down.
|
---|
| 1439 | */
|
---|
| 1440 | void XsdSchemaResolver::resolveAttributeInheritance(const XsdComplexType::Ptr &complexType, QSet<XsdComplexType::Ptr> &visitedTypes)
|
---|
| 1441 | {
|
---|
| 1442 | if (visitedTypes.contains(complexType))
|
---|
| 1443 | return;
|
---|
| 1444 | else
|
---|
| 1445 | visitedTypes.insert(complexType);
|
---|
| 1446 |
|
---|
| 1447 | const SchemaType::Ptr baseType = complexType->wxsSuperType();
|
---|
| 1448 | Q_ASSERT(baseType);
|
---|
| 1449 |
|
---|
| 1450 | if (!(baseType->isComplexType()) || !baseType->isDefinedBySchema())
|
---|
| 1451 | return;
|
---|
| 1452 |
|
---|
| 1453 | const XsdComplexType::Ptr complexBaseType = baseType;
|
---|
| 1454 |
|
---|
| 1455 | resolveAttributeInheritance(complexBaseType, visitedTypes);
|
---|
| 1456 |
|
---|
| 1457 | // @see http://www.w3.org/TR/xmlschema11-1/#dcl.ctd.attuses
|
---|
| 1458 |
|
---|
| 1459 | // 1 and 2 (the attribute groups have been resolved here already)
|
---|
| 1460 | const XsdAttributeUse::List uses = complexBaseType->attributeUses();
|
---|
| 1461 |
|
---|
| 1462 | if (complexType->derivationMethod() == XsdComplexType::DerivationRestriction) { // 3.2
|
---|
| 1463 | const XsdAttributeUse::List currentUses = complexType->attributeUses();
|
---|
| 1464 |
|
---|
| 1465 | // 3.2.1 and 3.2.2 As we also keep the prohibited attributes as objects, the algorithm below
|
---|
| 1466 | // handles both the same way
|
---|
| 1467 |
|
---|
| 1468 | // add only these attribute uses of the base type that match one of the following criteria:
|
---|
| 1469 | // 1: there is no attribute use with the same name in type
|
---|
| 1470 | // 2: there is no attribute with the same name marked as prohibited in type
|
---|
| 1471 | for (int j = 0; j < uses.count(); ++j) {
|
---|
| 1472 | const XsdAttributeUse::Ptr use = uses.at(j);
|
---|
| 1473 | bool found = false;
|
---|
| 1474 | for (int k = 0; k < currentUses.count(); ++k) {
|
---|
| 1475 | if (use->attribute()->name(m_namePool) == currentUses.at(k)->attribute()->name(m_namePool)) {
|
---|
| 1476 | found = true;
|
---|
| 1477 |
|
---|
| 1478 | // check if prohibited usage is violated
|
---|
| 1479 | if ((use->useType() == XsdAttributeUse::ProhibitedUse) && (currentUses.at(k)->useType() != XsdAttributeUse::ProhibitedUse)) {
|
---|
| 1480 | m_context->error(QtXmlPatterns::tr("%1 attribute in %2 must have %3 use like in base type %4.")
|
---|
| 1481 | .arg(formatAttribute(use->attribute()->displayName(m_namePool)))
|
---|
| 1482 | .arg(formatType(m_namePool, complexType))
|
---|
| 1483 | .arg(formatData("prohibited"))
|
---|
| 1484 | .arg(formatType(m_namePool, complexBaseType)),
|
---|
| 1485 | XsdSchemaContext::XSDError, sourceLocation(complexType));
|
---|
| 1486 | return;
|
---|
| 1487 | }
|
---|
| 1488 |
|
---|
| 1489 | break;
|
---|
| 1490 | }
|
---|
| 1491 | }
|
---|
| 1492 |
|
---|
| 1493 | if (!found && uses.at(j)->useType() != XsdAttributeUse::ProhibitedUse) {
|
---|
| 1494 | complexType->addAttributeUse(uses.at(j));
|
---|
| 1495 | }
|
---|
| 1496 | }
|
---|
| 1497 | } else if (complexType->derivationMethod() == XsdComplexType::DerivationExtension) { // 3.1
|
---|
| 1498 | QHash<QXmlName, XsdAttributeUse::Ptr> availableUses;
|
---|
| 1499 |
|
---|
| 1500 | // fill hash with attribute uses of current type for faster lookup
|
---|
| 1501 | {
|
---|
| 1502 | const XsdAttributeUse::List attributeUses = complexType->attributeUses();
|
---|
| 1503 |
|
---|
| 1504 | for (int i = 0; i < attributeUses.count(); ++i) {
|
---|
| 1505 | availableUses.insert(attributeUses.at(i)->attribute()->name(m_namePool), attributeUses.at(i));
|
---|
| 1506 | }
|
---|
| 1507 | }
|
---|
| 1508 |
|
---|
| 1509 | // just add the attribute uses of the base type
|
---|
| 1510 | for (int i = 0; i < uses.count(); ++i) {
|
---|
| 1511 | const XsdAttributeUse::Ptr currentAttributeUse = uses.at(i);
|
---|
| 1512 |
|
---|
| 1513 | // if the base type defines the attribute as prohibited but we override it in current type, then don't copy the prohibited attribute use
|
---|
| 1514 | if ((currentAttributeUse->useType() == XsdAttributeUse::ProhibitedUse) && availableUses.contains(currentAttributeUse->attribute()->name(m_namePool)))
|
---|
| 1515 | continue;
|
---|
| 1516 |
|
---|
| 1517 | complexType->addAttributeUse(uses.at(i));
|
---|
| 1518 | }
|
---|
| 1519 | }
|
---|
| 1520 |
|
---|
| 1521 | // handle attribute wildcards: @see http://www.w3.org/TR/xmlschema11-1/#dcl.ctd.anyatt
|
---|
| 1522 |
|
---|
| 1523 | // 1
|
---|
| 1524 | const XsdWildcard::Ptr completeWildcard(complexType->attributeWildcard());
|
---|
| 1525 |
|
---|
| 1526 | if (complexType->derivationMethod() == XsdComplexType::DerivationRestriction) {
|
---|
| 1527 | if (complexType->wxsSuperType()->isComplexType() && complexType->wxsSuperType()->isDefinedBySchema()) {
|
---|
| 1528 | const XsdComplexType::Ptr complexBaseType(complexType->wxsSuperType());
|
---|
| 1529 | if (complexType->attributeWildcard()) {
|
---|
| 1530 | if (complexBaseType->attributeWildcard()) {
|
---|
| 1531 | if (!isValidWildcardRestriction(complexType->attributeWildcard(), complexBaseType->attributeWildcard())) {
|
---|
| 1532 | m_context->error(QtXmlPatterns::tr("Attribute wildcard of %1 is not a valid restriction of attribute wildcard of base type %2.")
|
---|
| 1533 | .arg(formatType(m_namePool, complexType))
|
---|
| 1534 | .arg(formatType(m_namePool, complexBaseType)),
|
---|
| 1535 | XsdSchemaContext::XSDError, sourceLocation(complexType));
|
---|
| 1536 | return;
|
---|
| 1537 | }
|
---|
| 1538 | } else {
|
---|
| 1539 | m_context->error(QtXmlPatterns::tr("%1 has attribute wildcard but its base type %2 has not.")
|
---|
| 1540 | .arg(formatType(m_namePool, complexType))
|
---|
| 1541 | .arg(formatType(m_namePool, complexBaseType)),
|
---|
| 1542 | XsdSchemaContext::XSDError, sourceLocation(complexType));
|
---|
| 1543 | return;
|
---|
| 1544 | }
|
---|
| 1545 | }
|
---|
| 1546 | }
|
---|
| 1547 | complexType->setAttributeWildcard(completeWildcard); // 2.1
|
---|
| 1548 | } else if (complexType->derivationMethod() == XsdComplexType::DerivationExtension) {
|
---|
| 1549 | XsdWildcard::Ptr baseWildcard; // 2.2.1
|
---|
| 1550 | if (complexType->wxsSuperType()->isComplexType() && complexType->wxsSuperType()->isDefinedBySchema())
|
---|
| 1551 | baseWildcard = XsdComplexType::Ptr(complexType->wxsSuperType())->attributeWildcard(); // 2.2.1.1
|
---|
| 1552 | else
|
---|
| 1553 | baseWildcard = XsdWildcard::Ptr(); // 2.2.1.2
|
---|
| 1554 |
|
---|
| 1555 | if (!baseWildcard) {
|
---|
| 1556 | complexType->setAttributeWildcard(completeWildcard); // 2.2.2.1
|
---|
| 1557 | } else if (!completeWildcard) {
|
---|
| 1558 | complexType->setAttributeWildcard(baseWildcard); // 2.2.2.2
|
---|
| 1559 | } else {
|
---|
| 1560 | XsdWildcard::Ptr unionWildcard = XsdSchemaHelper::wildcardUnion(completeWildcard, baseWildcard);
|
---|
| 1561 | if (unionWildcard) {
|
---|
| 1562 | unionWildcard->setProcessContents(completeWildcard->processContents());
|
---|
| 1563 | complexType->setAttributeWildcard(unionWildcard); // 2.2.2.3
|
---|
| 1564 | } else {
|
---|
| 1565 | m_context->error(QtXmlPatterns::tr("Union of attribute wildcard of type %1 and attribute wildcard of its base type %2 is not expressible.")
|
---|
| 1566 | .arg(formatType(m_namePool, complexType))
|
---|
| 1567 | .arg(formatType(m_namePool, complexBaseType)),
|
---|
| 1568 | XsdSchemaContext::XSDError, sourceLocation(complexType));
|
---|
| 1569 | return;
|
---|
| 1570 | }
|
---|
| 1571 | }
|
---|
| 1572 | }
|
---|
| 1573 | }
|
---|
| 1574 |
|
---|
| 1575 | void XsdSchemaResolver::resolveEnumerationFacetValues()
|
---|
| 1576 | {
|
---|
| 1577 | XsdSimpleType::List simpleTypes;
|
---|
| 1578 |
|
---|
| 1579 | // first collect the global simple types
|
---|
| 1580 | const SchemaType::List types = m_schema->types();
|
---|
| 1581 | for (int i = 0; i < types.count(); ++i) {
|
---|
| 1582 | if (types.at(i)->isSimpleType())
|
---|
| 1583 | simpleTypes.append(types.at(i));
|
---|
| 1584 | }
|
---|
| 1585 |
|
---|
| 1586 | // then collect all anonymous simple types
|
---|
| 1587 | const SchemaType::List anonymousTypes = m_schema->anonymousTypes();
|
---|
| 1588 | for (int i = 0; i < anonymousTypes.count(); ++i) {
|
---|
| 1589 | if (anonymousTypes.at(i)->isSimpleType())
|
---|
| 1590 | simpleTypes.append(anonymousTypes.at(i));
|
---|
| 1591 | }
|
---|
| 1592 | // process all simple types
|
---|
| 1593 | for (int i = 0; i < simpleTypes.count(); ++i) {
|
---|
| 1594 | const XsdSimpleType::Ptr simpleType = simpleTypes.at(i);
|
---|
| 1595 |
|
---|
| 1596 | // we resolve the enumeration values only for xs:QName and xs:NOTATION based types
|
---|
| 1597 | if (BuiltinTypes::xsQName->wxsTypeMatches(simpleType) ||
|
---|
| 1598 | BuiltinTypes::xsNOTATION->wxsTypeMatches(simpleType)) {
|
---|
| 1599 | const XsdFacet::Hash facets = simpleType->facets();
|
---|
| 1600 | if (facets.contains(XsdFacet::Enumeration)) {
|
---|
| 1601 | AtomicValue::List newValues;
|
---|
| 1602 |
|
---|
| 1603 | const XsdFacet::Ptr facet = facets.value(XsdFacet::Enumeration);
|
---|
| 1604 | const AtomicValue::List values = facet->multiValue();
|
---|
| 1605 | for (int j = 0; j < values.count(); ++j) {
|
---|
| 1606 | const AtomicValue::Ptr value = values.at(j);
|
---|
| 1607 |
|
---|
| 1608 | Q_ASSERT(m_enumerationFacetValues.contains(value));
|
---|
| 1609 | const NamespaceSupport support( m_enumerationFacetValues.value(value) );
|
---|
| 1610 |
|
---|
| 1611 | const QString qualifiedName = value->as<DerivedString<TypeString> >()->stringValue();
|
---|
| 1612 | if (!XPathHelper::isQName(qualifiedName)) {
|
---|
| 1613 | m_context->error(QtXmlPatterns::tr("Enumeration facet contains invalid content: {%1} is not a value of type %2.")
|
---|
| 1614 | .arg(formatData(qualifiedName))
|
---|
| 1615 | .arg(formatType(m_namePool, BuiltinTypes::xsQName)),
|
---|
| 1616 | XsdSchemaContext::XSDError, sourceLocation(simpleType));
|
---|
| 1617 | return;
|
---|
| 1618 | }
|
---|
| 1619 |
|
---|
| 1620 | QXmlName qNameValue;
|
---|
| 1621 | bool result = support.processName(qualifiedName, NamespaceSupport::ElementName, qNameValue);
|
---|
| 1622 | if (!result) {
|
---|
| 1623 | m_context->error(QtXmlPatterns::tr("Namespace prefix of qualified name %1 is not defined.").arg(formatData(qualifiedName)),
|
---|
| 1624 | XsdSchemaContext::XSDError, sourceLocation(simpleType));
|
---|
| 1625 | return;
|
---|
| 1626 | }
|
---|
| 1627 |
|
---|
| 1628 | newValues.append(QNameValue::fromValue(m_namePool, qNameValue));
|
---|
| 1629 | }
|
---|
| 1630 | facet->setMultiValue(newValues);
|
---|
| 1631 | }
|
---|
| 1632 | }
|
---|
| 1633 | }
|
---|
| 1634 | }
|
---|
| 1635 |
|
---|
| 1636 | QSourceLocation XsdSchemaResolver::sourceLocation(const NamedSchemaComponent::Ptr component) const
|
---|
| 1637 | {
|
---|
| 1638 | if (m_componentLocationHash.contains(component)) {
|
---|
| 1639 | return m_componentLocationHash.value(component);
|
---|
| 1640 | } else {
|
---|
| 1641 | QSourceLocation location;
|
---|
| 1642 | location.setLine(1);
|
---|
| 1643 | location.setColumn(1);
|
---|
| 1644 | location.setUri(QString::fromLatin1("dummyUri"));
|
---|
| 1645 |
|
---|
| 1646 | return location;
|
---|
| 1647 | }
|
---|
| 1648 | }
|
---|
| 1649 |
|
---|
| 1650 | XsdFacet::Hash XsdSchemaResolver::complexTypeFacets(const XsdComplexType::Ptr &complexType) const
|
---|
| 1651 | {
|
---|
| 1652 | for (int i = 0; i < m_complexBaseTypes.count(); ++i) {
|
---|
| 1653 | if (m_complexBaseTypes.at(i).complexType == complexType)
|
---|
| 1654 | return m_complexBaseTypes.at(i).facets;
|
---|
| 1655 | }
|
---|
| 1656 |
|
---|
| 1657 | return XsdFacet::Hash();
|
---|
| 1658 | }
|
---|
| 1659 |
|
---|
| 1660 | void XsdSchemaResolver::checkRedefinedGroups()
|
---|
| 1661 | {
|
---|
| 1662 | for (int i = 0; i < m_redefinedGroups.count(); ++i) {
|
---|
| 1663 | const RedefinedGroups item = m_redefinedGroups.at(i);
|
---|
| 1664 |
|
---|
| 1665 | // create dummy particles...
|
---|
| 1666 | const XsdParticle::Ptr redefinedParticle(new XsdParticle());
|
---|
| 1667 | redefinedParticle->setTerm(item.redefinedGroup);
|
---|
| 1668 | const XsdParticle::Ptr particle(new XsdParticle());
|
---|
| 1669 | particle->setTerm(item.group);
|
---|
| 1670 |
|
---|
| 1671 | // so that we can pass them to XsdParticleChecker::subsumes()
|
---|
| 1672 | QString errorMsg;
|
---|
| 1673 | if (!XsdParticleChecker::subsumes(particle, redefinedParticle, m_context, errorMsg)) {
|
---|
| 1674 | m_context->error(QtXmlPatterns::tr("%1 element %2 is not a valid restriction of the %3 element it redefines: %4.")
|
---|
| 1675 | .arg(formatElement("group"))
|
---|
| 1676 | .arg(formatData(item.redefinedGroup->displayName(m_namePool)))
|
---|
| 1677 | .arg(formatElement("group"))
|
---|
| 1678 | .arg(errorMsg),
|
---|
| 1679 | XsdSchemaContext::XSDError, sourceLocation(item.redefinedGroup));
|
---|
| 1680 | return;
|
---|
| 1681 | }
|
---|
| 1682 | }
|
---|
| 1683 | }
|
---|
| 1684 |
|
---|
| 1685 | void XsdSchemaResolver::checkRedefinedAttributeGroups()
|
---|
| 1686 | {
|
---|
| 1687 | for (int i = 0; i < m_redefinedAttributeGroups.count(); ++i) {
|
---|
| 1688 | const RedefinedAttributeGroups item = m_redefinedAttributeGroups.at(i);
|
---|
| 1689 |
|
---|
| 1690 | QString errorMsg;
|
---|
| 1691 | if (!XsdSchemaHelper::isValidAttributeGroupRestriction(item.redefinedGroup, item.group, m_context, errorMsg)) {
|
---|
| 1692 | m_context->error(QtXmlPatterns::tr("%1 element %2 is not a valid restriction of the %3 element it redefines: %4.")
|
---|
| 1693 | .arg(formatElement("attributeGroup"))
|
---|
| 1694 | .arg(formatData(item.redefinedGroup->displayName(m_namePool)))
|
---|
| 1695 | .arg(formatElement("attributeGroup"))
|
---|
| 1696 | .arg(errorMsg),
|
---|
| 1697 | XsdSchemaContext::XSDError, sourceLocation(item.redefinedGroup));
|
---|
| 1698 | return;
|
---|
| 1699 | }
|
---|
| 1700 | }
|
---|
| 1701 | }
|
---|
| 1702 |
|
---|
| 1703 | AnySimpleType::Ptr XsdSchemaResolver::findPrimitiveType(const AnySimpleType::Ptr &type, QSet<AnySimpleType::Ptr> &visitedTypes)
|
---|
| 1704 | {
|
---|
| 1705 | if (visitedTypes.contains(type)) {
|
---|
| 1706 | // found invalid circular reference...
|
---|
| 1707 | return AnySimpleType::Ptr();
|
---|
| 1708 | } else {
|
---|
| 1709 | visitedTypes.insert(type);
|
---|
| 1710 | }
|
---|
| 1711 |
|
---|
| 1712 | const QXmlName typeName = type->name(m_namePool);
|
---|
| 1713 | if (typeName == BuiltinTypes::xsString->name(m_namePool) ||
|
---|
| 1714 | typeName == BuiltinTypes::xsBoolean->name(m_namePool) ||
|
---|
| 1715 | typeName == BuiltinTypes::xsFloat->name(m_namePool) ||
|
---|
| 1716 | typeName == BuiltinTypes::xsDouble->name(m_namePool) ||
|
---|
| 1717 | typeName == BuiltinTypes::xsDecimal->name(m_namePool) ||
|
---|
| 1718 | typeName == BuiltinTypes::xsDuration->name(m_namePool) ||
|
---|
| 1719 | typeName == BuiltinTypes::xsDateTime->name(m_namePool) ||
|
---|
| 1720 | typeName == BuiltinTypes::xsTime->name(m_namePool) ||
|
---|
| 1721 | typeName == BuiltinTypes::xsDate->name(m_namePool) ||
|
---|
| 1722 | typeName == BuiltinTypes::xsGYearMonth->name(m_namePool) ||
|
---|
| 1723 | typeName == BuiltinTypes::xsGYear->name(m_namePool) ||
|
---|
| 1724 | typeName == BuiltinTypes::xsGMonthDay->name(m_namePool) ||
|
---|
| 1725 | typeName == BuiltinTypes::xsGDay->name(m_namePool) ||
|
---|
| 1726 | typeName == BuiltinTypes::xsGMonth->name(m_namePool) ||
|
---|
| 1727 | typeName == BuiltinTypes::xsHexBinary->name(m_namePool) ||
|
---|
| 1728 | typeName == BuiltinTypes::xsBase64Binary->name(m_namePool) ||
|
---|
| 1729 | typeName == BuiltinTypes::xsAnyURI->name(m_namePool) ||
|
---|
| 1730 | typeName == BuiltinTypes::xsQName->name(m_namePool) ||
|
---|
| 1731 | typeName == BuiltinTypes::xsNOTATION->name(m_namePool) ||
|
---|
| 1732 | typeName == BuiltinTypes::xsAnySimpleType->name(m_namePool))
|
---|
| 1733 | return type;
|
---|
| 1734 | else {
|
---|
| 1735 | if (type->wxsSuperType())
|
---|
| 1736 | return findPrimitiveType(type->wxsSuperType(), visitedTypes);
|
---|
| 1737 | else {
|
---|
| 1738 | return AnySimpleType::Ptr();
|
---|
| 1739 | }
|
---|
| 1740 | }
|
---|
| 1741 | }
|
---|
| 1742 |
|
---|
| 1743 | QT_END_NAMESPACE
|
---|