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