1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qxsdschemamerger_p.h"
|
---|
43 |
|
---|
44 | QT_BEGIN_NAMESPACE
|
---|
45 |
|
---|
46 | using namespace QPatternist;
|
---|
47 |
|
---|
48 | XsdSchemaMerger::XsdSchemaMerger(const XsdSchema::Ptr &schema, const XsdSchema::Ptr &otherSchema)
|
---|
49 | {
|
---|
50 | merge(schema, otherSchema);
|
---|
51 | }
|
---|
52 |
|
---|
53 | XsdSchema::Ptr XsdSchemaMerger::mergedSchema() const
|
---|
54 | {
|
---|
55 | return m_mergedSchema;
|
---|
56 | }
|
---|
57 |
|
---|
58 | void XsdSchemaMerger::merge(const XsdSchema::Ptr &schema, const XsdSchema::Ptr &otherSchema)
|
---|
59 | {
|
---|
60 | m_mergedSchema = XsdSchema::Ptr(new XsdSchema(otherSchema->namePool()));
|
---|
61 |
|
---|
62 | // first fill the merged schema with the values from schema
|
---|
63 | if (schema) {
|
---|
64 | const XsdElement::List elements = schema->elements();
|
---|
65 | for (int i = 0; i < elements.count(); ++i) {
|
---|
66 | m_mergedSchema->addElement(elements.at(i));
|
---|
67 | }
|
---|
68 |
|
---|
69 | const XsdAttribute::List attributes = schema->attributes();
|
---|
70 | for (int i = 0; i < attributes.count(); ++i) {
|
---|
71 | m_mergedSchema->addAttribute(attributes.at(i));
|
---|
72 | }
|
---|
73 |
|
---|
74 | const SchemaType::List types = schema->types();
|
---|
75 | for (int i = 0; i < types.count(); ++i) {
|
---|
76 | m_mergedSchema->addType(types.at(i));
|
---|
77 | }
|
---|
78 |
|
---|
79 | const SchemaType::List anonymousTypes = schema->anonymousTypes();
|
---|
80 | for (int i = 0; i < anonymousTypes.count(); ++i) {
|
---|
81 | m_mergedSchema->addAnonymousType(anonymousTypes.at(i));
|
---|
82 | }
|
---|
83 |
|
---|
84 | const XsdModelGroup::List elementGroups = schema->elementGroups();
|
---|
85 | for (int i = 0; i < elementGroups.count(); ++i) {
|
---|
86 | m_mergedSchema->addElementGroup(elementGroups.at(i));
|
---|
87 | }
|
---|
88 |
|
---|
89 | const XsdAttributeGroup::List attributeGroups = schema->attributeGroups();
|
---|
90 | for (int i = 0; i < attributeGroups.count(); ++i) {
|
---|
91 | m_mergedSchema->addAttributeGroup(attributeGroups.at(i));
|
---|
92 | }
|
---|
93 |
|
---|
94 | const XsdNotation::List notations = schema->notations();
|
---|
95 | for (int i = 0; i < notations.count(); ++i) {
|
---|
96 | m_mergedSchema->addNotation(notations.at(i));
|
---|
97 | }
|
---|
98 |
|
---|
99 | const XsdIdentityConstraint::List identityConstraints = schema->identityConstraints();
|
---|
100 | for (int i = 0; i < identityConstraints.count(); ++i) {
|
---|
101 | m_mergedSchema->addIdentityConstraint(identityConstraints.at(i));
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | // then merge in the values from the otherSchema
|
---|
106 | {
|
---|
107 | const XsdElement::List elements = otherSchema->elements();
|
---|
108 | for (int i = 0; i < elements.count(); ++i) {
|
---|
109 | if (!m_mergedSchema->element(elements.at(i)->name(otherSchema->namePool())))
|
---|
110 | m_mergedSchema->addElement(elements.at(i));
|
---|
111 | }
|
---|
112 |
|
---|
113 | const XsdAttribute::List attributes = otherSchema->attributes();
|
---|
114 | for (int i = 0; i < attributes.count(); ++i) {
|
---|
115 | if (!m_mergedSchema->attribute(attributes.at(i)->name(otherSchema->namePool())))
|
---|
116 | m_mergedSchema->addAttribute(attributes.at(i));
|
---|
117 | }
|
---|
118 |
|
---|
119 | const SchemaType::List types = otherSchema->types();
|
---|
120 | for (int i = 0; i < types.count(); ++i) {
|
---|
121 | if (!m_mergedSchema->type(types.at(i)->name(otherSchema->namePool())))
|
---|
122 | m_mergedSchema->addType(types.at(i));
|
---|
123 | }
|
---|
124 |
|
---|
125 | const SchemaType::List anonymousTypes = otherSchema->anonymousTypes();
|
---|
126 | for (int i = 0; i < anonymousTypes.count(); ++i) {
|
---|
127 | // add anonymous type as they are
|
---|
128 | m_mergedSchema->addAnonymousType(anonymousTypes.at(i));
|
---|
129 | }
|
---|
130 |
|
---|
131 | const XsdModelGroup::List elementGroups = otherSchema->elementGroups();
|
---|
132 | for (int i = 0; i < elementGroups.count(); ++i) {
|
---|
133 | if (!m_mergedSchema->elementGroup(elementGroups.at(i)->name(otherSchema->namePool())))
|
---|
134 | m_mergedSchema->addElementGroup(elementGroups.at(i));
|
---|
135 | }
|
---|
136 |
|
---|
137 | const XsdAttributeGroup::List attributeGroups = otherSchema->attributeGroups();
|
---|
138 | for (int i = 0; i < attributeGroups.count(); ++i) {
|
---|
139 | if (!m_mergedSchema->attributeGroup(attributeGroups.at(i)->name(otherSchema->namePool())))
|
---|
140 | m_mergedSchema->addAttributeGroup(attributeGroups.at(i));
|
---|
141 | }
|
---|
142 |
|
---|
143 | const XsdNotation::List notations = otherSchema->notations();
|
---|
144 | for (int i = 0; i < notations.count(); ++i) {
|
---|
145 | if (!m_mergedSchema->notation(notations.at(i)->name(otherSchema->namePool())))
|
---|
146 | m_mergedSchema->addNotation(notations.at(i));
|
---|
147 | }
|
---|
148 |
|
---|
149 | const XsdIdentityConstraint::List identityConstraints = otherSchema->identityConstraints();
|
---|
150 | for (int i = 0; i < identityConstraints.count(); ++i) {
|
---|
151 | if (!m_mergedSchema->identityConstraint(identityConstraints.at(i)->name(otherSchema->namePool())))
|
---|
152 | m_mergedSchema->addIdentityConstraint(identityConstraints.at(i));
|
---|
153 | }
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | QT_END_NAMESPACE
|
---|