1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: XSModel.cpp 674012 2008-07-04 11:18:21Z borisk $ |
---|
20 | */ |
---|
21 | |
---|
22 | #include <xercesc/framework/psvi/XSModel.hpp> |
---|
23 | #include <xercesc/framework/psvi/XSNamespaceItem.hpp> |
---|
24 | #include <xercesc/validators/schema/SchemaGrammar.hpp> |
---|
25 | #include <icxercesc/validators/common/GrammarResolver.hpp> |
---|
26 | #include <xercesc/validators/schema/XercesAttGroupInfo.hpp> |
---|
27 | #include <xercesc/validators/schema/XercesGroupInfo.hpp> |
---|
28 | #include <xercesc/internal/XSObjectFactory.hpp> |
---|
29 | #include <xercesc/framework/psvi/XSAttributeDeclaration.hpp> |
---|
30 | #include <xercesc/framework/psvi/XSElementDeclaration.hpp> |
---|
31 | #include <xercesc/framework/psvi/XSAttributeGroupDefinition.hpp> |
---|
32 | #include <xercesc/framework/psvi/XSNotationDeclaration.hpp> |
---|
33 | #include <xercesc/framework/psvi/XSAnnotation.hpp> |
---|
34 | #include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp> |
---|
35 | #include <xercesc/framework/psvi/XSModelGroupDefinition.hpp> |
---|
36 | |
---|
37 | XERCES_CPP_NAMESPACE_BEGIN |
---|
38 | |
---|
39 | // --------------------------------------------------------------------------- |
---|
40 | // XSModel: Constructors and Destructor |
---|
41 | // --------------------------------------------------------------------------- |
---|
42 | XSModel::XSModel( XMLGrammarPool *grammarPool |
---|
43 | , MemoryManager* const manager) |
---|
44 | : fMemoryManager(manager) |
---|
45 | , fNamespaceStringList(0) |
---|
46 | , fXSNamespaceItemList(0) |
---|
47 | , fURIStringPool(0) |
---|
48 | , fXSAnnotationList(0) |
---|
49 | , fHashNamespace(0) |
---|
50 | , fObjFactory(0) |
---|
51 | , fDeleteNamespace(0) |
---|
52 | , fParent(0) |
---|
53 | , fDeleteParent(false) |
---|
54 | , fAddedS4SGrammar(false) |
---|
55 | { |
---|
56 | fURIStringPool = grammarPool->getURIStringPool(); |
---|
57 | fObjFactory = new (fMemoryManager) XSObjectFactory(manager); |
---|
58 | |
---|
59 | // Populate XSNamedMaps by going through the components |
---|
60 | for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++) |
---|
61 | { |
---|
62 | switch (i+1) |
---|
63 | { |
---|
64 | case XSConstants::ATTRIBUTE_DECLARATION: |
---|
65 | case XSConstants::ELEMENT_DECLARATION: |
---|
66 | case XSConstants::TYPE_DEFINITION: |
---|
67 | case XSConstants::ATTRIBUTE_GROUP_DEFINITION: |
---|
68 | case XSConstants::MODEL_GROUP_DEFINITION: |
---|
69 | case XSConstants::NOTATION_DECLARATION: |
---|
70 | fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject> |
---|
71 | ( |
---|
72 | 20, // size |
---|
73 | 29, // modulus |
---|
74 | fURIStringPool, |
---|
75 | false, // adoptElems |
---|
76 | fMemoryManager |
---|
77 | ); |
---|
78 | break; |
---|
79 | default: |
---|
80 | // ATTRIBUTE_USE |
---|
81 | // MODEL_GROUP |
---|
82 | // PARTICLE |
---|
83 | // IDENTITY_CONSTRAINT |
---|
84 | // WILDCARD |
---|
85 | // ANNOTATION |
---|
86 | // FACET |
---|
87 | // MULTIVALUE |
---|
88 | fComponentMap[i] = 0; |
---|
89 | break; |
---|
90 | } |
---|
91 | fIdVector[i] = new (fMemoryManager) RefVectorOf<XSObject>(30, false, fMemoryManager); |
---|
92 | } |
---|
93 | |
---|
94 | fNamespaceStringList = new (manager) RefArrayVectorOf <XMLCh>(10, true, manager); |
---|
95 | fXSNamespaceItemList = new (manager) RefVectorOf <XSNamespaceItem>(10, true, manager); |
---|
96 | fXSAnnotationList = new (manager) RefVectorOf <XSAnnotation> (10, false, manager); |
---|
97 | fHashNamespace = new (manager) RefHashTableOf<XSNamespaceItem> (11, false, manager); |
---|
98 | |
---|
99 | // Loop through all grammars in the grammar pool to create the XSNamespaceItem's |
---|
100 | // which will have access to Annotation Information which can be used later when |
---|
101 | // we create all the XS components. |
---|
102 | XSNamespaceItem* namespaceItem = 0; |
---|
103 | RefHashTableOfEnumerator<Grammar> grammarEnum = grammarPool->getGrammarEnumerator(); |
---|
104 | while (grammarEnum.hasMoreElements()) |
---|
105 | { |
---|
106 | SchemaGrammar& sGrammar = (SchemaGrammar&) grammarEnum.nextElement(); |
---|
107 | if (sGrammar.getGrammarType() != Grammar::SchemaGrammarType || |
---|
108 | XMLString::equals(sGrammar.getTargetNamespace(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA)) |
---|
109 | continue; |
---|
110 | |
---|
111 | // NOTE: In the grammarpool, preprocessed grammars without targetnamespace |
---|
112 | // will use an empty string... |
---|
113 | XMLCh* NameSpace = XMLString::replicate(sGrammar.getTargetNamespace(), manager); |
---|
114 | fNamespaceStringList->addElement(NameSpace); |
---|
115 | namespaceItem = new (manager) XSNamespaceItem(this, &sGrammar, manager); |
---|
116 | fXSNamespaceItemList->addElement(namespaceItem); |
---|
117 | fHashNamespace->put(NameSpace, namespaceItem); |
---|
118 | } |
---|
119 | |
---|
120 | // Now loop through all of the NamespaceItem's |
---|
121 | // First, we add S4S namespace (irrespective of whether we have any grammars) |
---|
122 | namespaceItem = new (manager) XSNamespaceItem |
---|
123 | ( |
---|
124 | this, SchemaSymbols::fgURI_SCHEMAFORSCHEMA, manager |
---|
125 | ); |
---|
126 | |
---|
127 | fNamespaceStringList->addElement |
---|
128 | ( |
---|
129 | XMLString::replicate(SchemaSymbols::fgURI_SCHEMAFORSCHEMA,manager) |
---|
130 | ); |
---|
131 | fXSNamespaceItemList->addElement(namespaceItem); |
---|
132 | fHashNamespace->put |
---|
133 | ( |
---|
134 | (void*) SchemaSymbols::fgURI_SCHEMAFORSCHEMA |
---|
135 | , namespaceItem |
---|
136 | ); |
---|
137 | |
---|
138 | DatatypeValidatorFactory dvFactory(manager); |
---|
139 | addS4SToXSModel |
---|
140 | ( |
---|
141 | namespaceItem |
---|
142 | , dvFactory.getBuiltInRegistry() |
---|
143 | ); |
---|
144 | // don't include S4S (thus the -1) |
---|
145 | XMLSize_t numberOfNamespaces = fXSNamespaceItemList->size() -1; |
---|
146 | for (XMLSize_t j = 0; j < numberOfNamespaces; j++) |
---|
147 | addGrammarToXSModel(fXSNamespaceItemList->elementAt(j)); |
---|
148 | } |
---|
149 | |
---|
150 | XSModel::XSModel( XSModel *baseModel |
---|
151 | , GrammarResolver *grammarResolver |
---|
152 | , MemoryManager* const manager) |
---|
153 | : fMemoryManager(manager) |
---|
154 | , fNamespaceStringList(0) |
---|
155 | , fXSNamespaceItemList(0) |
---|
156 | , fURIStringPool(0) |
---|
157 | , fXSAnnotationList(0) |
---|
158 | , fHashNamespace(0) |
---|
159 | , fObjFactory(0) |
---|
160 | , fDeleteNamespace(0) |
---|
161 | , fParent(baseModel) |
---|
162 | , fDeleteParent(true) |
---|
163 | , fAddedS4SGrammar(false) |
---|
164 | { |
---|
165 | fURIStringPool = grammarResolver->getStringPool(); |
---|
166 | fObjFactory = new (manager) XSObjectFactory(manager); |
---|
167 | |
---|
168 | XMLSize_t i; |
---|
169 | // Populate XSNamedMaps by going through the components |
---|
170 | for (i=0; i<XSConstants::MULTIVALUE_FACET; i++) |
---|
171 | { |
---|
172 | switch (i+1) |
---|
173 | { |
---|
174 | case XSConstants::ATTRIBUTE_DECLARATION: |
---|
175 | case XSConstants::ELEMENT_DECLARATION: |
---|
176 | case XSConstants::TYPE_DEFINITION: |
---|
177 | case XSConstants::ATTRIBUTE_GROUP_DEFINITION: |
---|
178 | case XSConstants::MODEL_GROUP_DEFINITION: |
---|
179 | case XSConstants::NOTATION_DECLARATION: |
---|
180 | fComponentMap[i] = new (fMemoryManager) XSNamedMap<XSObject> |
---|
181 | ( |
---|
182 | 20, // size |
---|
183 | 29, // modulus |
---|
184 | fURIStringPool, |
---|
185 | false, // adoptElems |
---|
186 | fMemoryManager |
---|
187 | ); |
---|
188 | break; |
---|
189 | default: |
---|
190 | // ATTRIBUTE_USE |
---|
191 | // MODEL_GROUP |
---|
192 | // PARTICLE |
---|
193 | // IDENTITY_CONSTRAINT |
---|
194 | // WILDCARD |
---|
195 | // ANNOTATION |
---|
196 | // FACET |
---|
197 | // MULTIVALUE |
---|
198 | fComponentMap[i] = 0; |
---|
199 | break; |
---|
200 | } |
---|
201 | fIdVector[i] = new (fMemoryManager) RefVectorOf<XSObject>(30, false, fMemoryManager); |
---|
202 | } |
---|
203 | |
---|
204 | fNamespaceStringList = new (manager) RefArrayVectorOf <XMLCh>(10, true, manager); |
---|
205 | fXSNamespaceItemList = new (manager) RefVectorOf <XSNamespaceItem>(10, false, manager); |
---|
206 | fDeleteNamespace = new (manager) RefVectorOf <XSNamespaceItem>(10, true, manager); |
---|
207 | fXSAnnotationList = new (manager) RefVectorOf <XSAnnotation> (10, false, manager); |
---|
208 | fHashNamespace = new (manager) RefHashTableOf<XSNamespaceItem> (11, false, manager); |
---|
209 | |
---|
210 | if (fParent) |
---|
211 | { |
---|
212 | if (fParent->fAddedS4SGrammar) |
---|
213 | fAddedS4SGrammar = true; |
---|
214 | |
---|
215 | // Need to copy information from parent so it can be returned in this object... |
---|
216 | for (i=0; i<fParent->fXSNamespaceItemList->size(); i++) |
---|
217 | { |
---|
218 | XSNamespaceItem* namespaceItem = fParent->fXSNamespaceItemList->elementAt(i); |
---|
219 | fXSNamespaceItemList->addElement(namespaceItem); |
---|
220 | fNamespaceStringList->addElement |
---|
221 | ( |
---|
222 | XMLString::replicate |
---|
223 | ( |
---|
224 | namespaceItem->getSchemaNamespace(), manager |
---|
225 | ) |
---|
226 | ); |
---|
227 | } |
---|
228 | |
---|
229 | for (i=0; i<XSConstants::MULTIVALUE_FACET; i++) |
---|
230 | { |
---|
231 | switch (i+1) |
---|
232 | { |
---|
233 | case XSConstants::ATTRIBUTE_DECLARATION: |
---|
234 | case XSConstants::ELEMENT_DECLARATION: |
---|
235 | case XSConstants::TYPE_DEFINITION: |
---|
236 | case XSConstants::ATTRIBUTE_GROUP_DEFINITION: |
---|
237 | case XSConstants::MODEL_GROUP_DEFINITION: |
---|
238 | case XSConstants::NOTATION_DECLARATION: |
---|
239 | for (XMLSize_t j=0; j<fParent->fComponentMap[i]->getLength(); j++) |
---|
240 | { |
---|
241 | XSObject* copyObj = fParent->fComponentMap[i]->item(j); |
---|
242 | fComponentMap[i]->addElement(copyObj, |
---|
243 | copyObj->getName(), |
---|
244 | copyObj->getNamespace()); |
---|
245 | } |
---|
246 | break; |
---|
247 | } |
---|
248 | for (XMLSize_t j=0; j<fParent->fIdVector[i]->size(); j++) |
---|
249 | { |
---|
250 | fIdVector[i]->addElement(fParent->fIdVector[i]->elementAt(j)); |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | for (i=0; i<fParent->fXSAnnotationList->size(); i++) |
---|
255 | { |
---|
256 | fXSAnnotationList->addElement(fParent->fXSAnnotationList->elementAt(i)); |
---|
257 | } |
---|
258 | |
---|
259 | } // end of copying parent info |
---|
260 | |
---|
261 | // Now add information from the new grammars but first create the |
---|
262 | // XSNamespaceItem's so we can have access to the XSAnnotations... |
---|
263 | ValueVectorOf<SchemaGrammar*>* grammarsToAdd = grammarResolver->getGrammarsToAddToXSModel(); |
---|
264 | XMLSize_t numberOfNamespaces = fXSNamespaceItemList->size(); |
---|
265 | XMLSize_t numberOfNamespacesToAdd = 0; |
---|
266 | for (i=0; i < grammarsToAdd->size(); i++) |
---|
267 | { |
---|
268 | SchemaGrammar* lGrammar = grammarsToAdd->elementAt(i); |
---|
269 | if (lGrammar->getGrammarType() != Grammar::SchemaGrammarType || |
---|
270 | XMLString::equals(lGrammar->getTargetNamespace(), SchemaSymbols::fgURI_SCHEMAFORSCHEMA)) |
---|
271 | continue; |
---|
272 | |
---|
273 | XMLCh* NameSpace = XMLString::replicate(lGrammar->getTargetNamespace(), manager); |
---|
274 | fNamespaceStringList->addElement(NameSpace); |
---|
275 | |
---|
276 | XSNamespaceItem* namespaceItem = new (manager) XSNamespaceItem(this, lGrammar, manager); |
---|
277 | fXSNamespaceItemList->addElement(namespaceItem); |
---|
278 | fHashNamespace->put(NameSpace, namespaceItem); |
---|
279 | fDeleteNamespace->addElement(namespaceItem); |
---|
280 | ++numberOfNamespacesToAdd; |
---|
281 | } |
---|
282 | |
---|
283 | // Add S4S namespace if needed |
---|
284 | if (!fAddedS4SGrammar) |
---|
285 | { |
---|
286 | DatatypeValidatorFactory dvFactory(manager); |
---|
287 | |
---|
288 | XSNamespaceItem* namespaceItem = new (manager) XSNamespaceItem |
---|
289 | ( |
---|
290 | this, SchemaSymbols::fgURI_SCHEMAFORSCHEMA, manager |
---|
291 | ); |
---|
292 | |
---|
293 | fNamespaceStringList->addElement |
---|
294 | ( |
---|
295 | XMLString::replicate(SchemaSymbols::fgURI_SCHEMAFORSCHEMA,manager) |
---|
296 | ); |
---|
297 | fXSNamespaceItemList->addElement(namespaceItem); |
---|
298 | fHashNamespace->put |
---|
299 | ( |
---|
300 | (void*) SchemaSymbols::fgURI_SCHEMAFORSCHEMA , namespaceItem |
---|
301 | ); |
---|
302 | fDeleteNamespace->addElement(namespaceItem); |
---|
303 | addS4SToXSModel |
---|
304 | ( |
---|
305 | namespaceItem |
---|
306 | , dvFactory.getBuiltInRegistry() |
---|
307 | ); |
---|
308 | } |
---|
309 | |
---|
310 | // Now loop through all of the newly created NamespaceItem's |
---|
311 | for (i=numberOfNamespaces; i<(numberOfNamespaces+numberOfNamespacesToAdd); i++) |
---|
312 | { |
---|
313 | addGrammarToXSModel(fXSNamespaceItemList->elementAt(i)); |
---|
314 | } // end of namespaceItem loop |
---|
315 | } |
---|
316 | |
---|
317 | XSModel::~XSModel() |
---|
318 | { |
---|
319 | for (XMLSize_t i=0; i<XSConstants::MULTIVALUE_FACET; i++) |
---|
320 | { |
---|
321 | switch (i+1) |
---|
322 | { |
---|
323 | case XSConstants::ATTRIBUTE_DECLARATION: |
---|
324 | case XSConstants::ELEMENT_DECLARATION: |
---|
325 | case XSConstants::TYPE_DEFINITION: |
---|
326 | case XSConstants::ATTRIBUTE_GROUP_DEFINITION: |
---|
327 | case XSConstants::MODEL_GROUP_DEFINITION: |
---|
328 | case XSConstants::NOTATION_DECLARATION: |
---|
329 | delete fComponentMap[i]; |
---|
330 | break; |
---|
331 | } |
---|
332 | delete fIdVector[i]; |
---|
333 | } |
---|
334 | |
---|
335 | delete fNamespaceStringList; |
---|
336 | delete fXSNamespaceItemList; |
---|
337 | delete fXSAnnotationList; |
---|
338 | delete fHashNamespace; |
---|
339 | delete fObjFactory; |
---|
340 | |
---|
341 | if (fDeleteNamespace) |
---|
342 | delete fDeleteNamespace; |
---|
343 | |
---|
344 | if (fDeleteParent && fParent && fParent->fDeleteParent) |
---|
345 | delete fParent; |
---|
346 | } |
---|
347 | |
---|
348 | // --------------------------------------------------------------------------- |
---|
349 | // XSModel: Helper methods |
---|
350 | // --------------------------------------------------------------------------- |
---|
351 | void XSModel::addComponentToIdVector(XSObject* const component, |
---|
352 | XMLSize_t componentIndex) |
---|
353 | { |
---|
354 | component->setId(fIdVector[componentIndex]->size()); |
---|
355 | fIdVector[componentIndex]->addElement(component); |
---|
356 | } |
---|
357 | |
---|
358 | |
---|
359 | void XSModel::addComponentToNamespace(XSNamespaceItem* const namespaceItem, |
---|
360 | XSObject* const component, |
---|
361 | XMLSize_t componentIndex, |
---|
362 | bool addToXSModel) |
---|
363 | { |
---|
364 | namespaceItem->fComponentMap[componentIndex]->addElement |
---|
365 | ( |
---|
366 | component, component->getName(), namespaceItem->getSchemaNamespace() |
---|
367 | ); |
---|
368 | namespaceItem->fHashMap[componentIndex]->put |
---|
369 | ( |
---|
370 | (void *) component->getName(), component |
---|
371 | ); |
---|
372 | |
---|
373 | if (addToXSModel) |
---|
374 | { |
---|
375 | fComponentMap[componentIndex]->addElement |
---|
376 | ( |
---|
377 | component, component->getName(), namespaceItem->getSchemaNamespace() |
---|
378 | ); |
---|
379 | } |
---|
380 | } |
---|
381 | |
---|
382 | void |
---|
383 | XSModel::addS4SToXSModel(XSNamespaceItem* const namespaceItem, |
---|
384 | RefHashTableOf<DatatypeValidator>* const builtInDV) |
---|
385 | { |
---|
386 | addComponentToNamespace |
---|
387 | ( |
---|
388 | namespaceItem |
---|
389 | , fObjFactory->addOrFind |
---|
390 | ( |
---|
391 | ComplexTypeInfo::getAnyType |
---|
392 | ( |
---|
393 | fURIStringPool->getId(XMLUni::fgZeroLenString) |
---|
394 | ) |
---|
395 | , this |
---|
396 | ) |
---|
397 | , XSConstants::TYPE_DEFINITION - 1 |
---|
398 | ); |
---|
399 | |
---|
400 | // Loop through built-in simple types |
---|
401 | // First add 'anySimpleType' which is the base for the other built-ins |
---|
402 | DatatypeValidator* dv = builtInDV->get(SchemaSymbols::fgDT_ANYSIMPLETYPE); |
---|
403 | addComponentToNamespace |
---|
404 | ( |
---|
405 | namespaceItem |
---|
406 | , fObjFactory->addOrFind(dv, this, true) |
---|
407 | , XSConstants::TYPE_DEFINITION - 1 |
---|
408 | ); |
---|
409 | |
---|
410 | // add remaining built-in |
---|
411 | RefHashTableOfEnumerator<DatatypeValidator> simpleEnum = |
---|
412 | RefHashTableOfEnumerator<DatatypeValidator> (builtInDV, false, fMemoryManager); |
---|
413 | while (simpleEnum.hasMoreElements()) |
---|
414 | { |
---|
415 | DatatypeValidator& curSimple = simpleEnum.nextElement(); |
---|
416 | if (&curSimple == dv) |
---|
417 | continue; |
---|
418 | |
---|
419 | addComponentToNamespace |
---|
420 | ( |
---|
421 | namespaceItem |
---|
422 | , fObjFactory->addOrFind(&curSimple, this) |
---|
423 | , XSConstants::TYPE_DEFINITION - 1 |
---|
424 | ); |
---|
425 | } |
---|
426 | |
---|
427 | // Set flag to indicate that we have added S4S grammar info |
---|
428 | fAddedS4SGrammar = true; |
---|
429 | } |
---|
430 | |
---|
431 | |
---|
432 | void XSModel::addGrammarToXSModel(XSNamespaceItem* namespaceItem) |
---|
433 | { |
---|
434 | // Loop through top-level attribute declarations in the grammar... |
---|
435 | RefHashTableOf<XMLAttDef>* attDeclRegistry = namespaceItem->fGrammar->getAttributeDeclRegistry(); |
---|
436 | if(attDeclRegistry) { |
---|
437 | RefHashTableOfEnumerator<XMLAttDef> attrEnum = RefHashTableOfEnumerator<XMLAttDef> (attDeclRegistry, false, fMemoryManager); |
---|
438 | while (attrEnum.hasMoreElements()) |
---|
439 | { |
---|
440 | XSAttributeDeclaration* xsAttrDecl = fObjFactory->addOrFind |
---|
441 | ( |
---|
442 | (SchemaAttDef*) &(attrEnum.nextElement()), this |
---|
443 | ); |
---|
444 | |
---|
445 | addComponentToNamespace |
---|
446 | ( |
---|
447 | namespaceItem, xsAttrDecl, XSConstants::ATTRIBUTE_DECLARATION - 1 |
---|
448 | ); |
---|
449 | } // end of attribute loop |
---|
450 | } |
---|
451 | |
---|
452 | // Loop through top-level elements in the grammar... |
---|
453 | RefHash3KeysIdPoolEnumerator<SchemaElementDecl> elemEnum = namespaceItem->fGrammar->getElemEnumerator(); |
---|
454 | while (elemEnum.hasMoreElements()) |
---|
455 | { |
---|
456 | SchemaElementDecl& curElem = elemEnum.nextElement(); |
---|
457 | if (curElem.getEnclosingScope() == Grammar::TOP_LEVEL_SCOPE) |
---|
458 | { |
---|
459 | XSElementDeclaration* xsElemDecl = fObjFactory->addOrFind |
---|
460 | ( |
---|
461 | &curElem, this |
---|
462 | ); |
---|
463 | |
---|
464 | addComponentToNamespace |
---|
465 | ( |
---|
466 | namespaceItem, xsElemDecl, XSConstants::ELEMENT_DECLARATION -1 |
---|
467 | ); |
---|
468 | } |
---|
469 | } // end of element loop |
---|
470 | |
---|
471 | // Now loop through top-level User Defined simple type definitions in the grammar... |
---|
472 | DVHashTable* dvHT = namespaceItem->fGrammar->getDatatypeRegistry()->getUserDefinedRegistry(); |
---|
473 | if (dvHT) |
---|
474 | { |
---|
475 | RefHashTableOfEnumerator<DatatypeValidator> simpleUserEnum = RefHashTableOfEnumerator<DatatypeValidator> (dvHT, false, fMemoryManager); |
---|
476 | while (simpleUserEnum.hasMoreElements()) |
---|
477 | { |
---|
478 | DatatypeValidator& curSimple = simpleUserEnum.nextElement(); |
---|
479 | if (!curSimple.getAnonymous()) |
---|
480 | { |
---|
481 | addComponentToNamespace |
---|
482 | ( |
---|
483 | namespaceItem |
---|
484 | , fObjFactory->addOrFind(&curSimple, this) |
---|
485 | , XSConstants::TYPE_DEFINITION - 1 |
---|
486 | ); |
---|
487 | } |
---|
488 | } // end of simple User loop |
---|
489 | } |
---|
490 | |
---|
491 | // Loop through top-level COMPLEX type definitions in the grammar... |
---|
492 | RefHashTableOf<ComplexTypeInfo>* complexTypeRegistry = namespaceItem->fGrammar->getComplexTypeRegistry(); |
---|
493 | if(complexTypeRegistry) { |
---|
494 | RefHashTableOfEnumerator<ComplexTypeInfo> complexEnum = RefHashTableOfEnumerator<ComplexTypeInfo> (complexTypeRegistry, false, fMemoryManager); |
---|
495 | while (complexEnum.hasMoreElements()) |
---|
496 | { |
---|
497 | ComplexTypeInfo& curComplex = complexEnum.nextElement(); |
---|
498 | if (!curComplex.getAnonymous()) |
---|
499 | { |
---|
500 | addComponentToNamespace |
---|
501 | ( |
---|
502 | namespaceItem |
---|
503 | , fObjFactory->addOrFind(&curComplex, this) |
---|
504 | , XSConstants::TYPE_DEFINITION - 1 |
---|
505 | ); |
---|
506 | } |
---|
507 | } // end of type definition loop |
---|
508 | } |
---|
509 | |
---|
510 | // Loop through top-level attribute group definitions in the grammar... |
---|
511 | RefHashTableOf<XercesAttGroupInfo>* attGroupInfoRegistry = namespaceItem->fGrammar->getAttGroupInfoRegistry(); |
---|
512 | if(attGroupInfoRegistry) { |
---|
513 | RefHashTableOfEnumerator<XercesAttGroupInfo> attrGroupEnum = RefHashTableOfEnumerator<XercesAttGroupInfo> (attGroupInfoRegistry, false, fMemoryManager); |
---|
514 | while (attrGroupEnum.hasMoreElements()) |
---|
515 | { |
---|
516 | addComponentToNamespace |
---|
517 | ( |
---|
518 | namespaceItem |
---|
519 | , fObjFactory->createXSAttGroupDefinition |
---|
520 | ( |
---|
521 | &(attrGroupEnum.nextElement()), this |
---|
522 | ) |
---|
523 | , XSConstants::ATTRIBUTE_GROUP_DEFINITION - 1 |
---|
524 | ); |
---|
525 | } // end of attribute group loop |
---|
526 | } |
---|
527 | |
---|
528 | // Loop through top-level model group definitions in the grammar... |
---|
529 | RefHashTableOf<XercesGroupInfo>* groupInfoRegistry = namespaceItem->fGrammar->getGroupInfoRegistry(); |
---|
530 | if(groupInfoRegistry) { |
---|
531 | RefHashTableOfEnumerator<XercesGroupInfo> modelGroupEnum = RefHashTableOfEnumerator<XercesGroupInfo> (groupInfoRegistry, false, fMemoryManager); |
---|
532 | while (modelGroupEnum.hasMoreElements()) |
---|
533 | { |
---|
534 | addComponentToNamespace |
---|
535 | ( |
---|
536 | namespaceItem |
---|
537 | , fObjFactory->createXSModelGroupDefinition |
---|
538 | ( |
---|
539 | &(modelGroupEnum.nextElement()), this |
---|
540 | ) |
---|
541 | , XSConstants::MODEL_GROUP_DEFINITION - 1 |
---|
542 | ); |
---|
543 | } // end of model group loop |
---|
544 | } |
---|
545 | |
---|
546 | // Loop through notations in the grammar... |
---|
547 | NameIdPoolEnumerator<XMLNotationDecl> notationEnum = namespaceItem->fGrammar->getNotationEnumerator(); |
---|
548 | while (notationEnum.hasMoreElements()) |
---|
549 | { |
---|
550 | addComponentToNamespace |
---|
551 | ( |
---|
552 | namespaceItem |
---|
553 | , fObjFactory->addOrFind(&(notationEnum.nextElement()), this) |
---|
554 | , XSConstants::NOTATION_DECLARATION - 1 |
---|
555 | ); |
---|
556 | } // end of notation loop |
---|
557 | |
---|
558 | // Loop through annotations in the grammar... |
---|
559 | // As annotations are already created as XSAnnotations no need to create them |
---|
560 | // or store them in the XercesToXSMap. |
---|
561 | XSAnnotation* annot = namespaceItem->fGrammar->getAnnotation(); |
---|
562 | while (annot) |
---|
563 | { |
---|
564 | fXSAnnotationList->addElement(annot); |
---|
565 | namespaceItem->fXSAnnotationList->addElement(annot); |
---|
566 | addComponentToIdVector(annot, XSConstants::ANNOTATION -1); |
---|
567 | annot = annot->getNext(); |
---|
568 | } // end of annotation loop |
---|
569 | } |
---|
570 | |
---|
571 | |
---|
572 | |
---|
573 | |
---|
574 | // --------------------------------------------------------------------------- |
---|
575 | // XSModel: Access methods |
---|
576 | // --------------------------------------------------------------------------- |
---|
577 | /** |
---|
578 | * [schema components]: a list of top-level components, i.e. element |
---|
579 | * declarations, attribute declarations, etc. |
---|
580 | * @param objectType The type of the declaration, i.e. |
---|
581 | * <code>ELEMENT_DECLARATION</code>, |
---|
582 | * <code>TYPE_DEFINITION</code> and any other component type that |
---|
583 | * may be a property of a schema component. |
---|
584 | * @return A list of top-level definition of the specified type in |
---|
585 | * <code>objectType</code> or <code>null</code>. |
---|
586 | */ |
---|
587 | XSNamedMap <XSObject> *XSModel::getComponents(XSConstants::COMPONENT_TYPE objectType) |
---|
588 | { |
---|
589 | return fComponentMap[objectType -1]; |
---|
590 | } |
---|
591 | |
---|
592 | /** |
---|
593 | * Convenience method. Returns a list of top-level component declarations |
---|
594 | * that are defined within the specified namespace, i.e. element |
---|
595 | * declarations, attribute declarations, etc. |
---|
596 | * @param objectType The type of the declaration, i.e. |
---|
597 | * <code>ELEMENT_DECLARATION</code>. |
---|
598 | * @param compNamespace The namespace to which declaration belong or |
---|
599 | * <code>null</code> (for components with no target namespace). |
---|
600 | * @return A list of top-level definitions of the specified type in |
---|
601 | * <code>objectType</code> and defined in the specified |
---|
602 | * <code>namespace</code> or <code>null</code>. |
---|
603 | */ |
---|
604 | XSNamedMap <XSObject> *XSModel::getComponentsByNamespace(XSConstants::COMPONENT_TYPE objectType, |
---|
605 | const XMLCh *compNamespace) |
---|
606 | { |
---|
607 | XSNamespaceItem* namespaceItem; |
---|
608 | if (compNamespace) |
---|
609 | namespaceItem = getNamespaceItem(compNamespace); |
---|
610 | else |
---|
611 | namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString); |
---|
612 | |
---|
613 | if (namespaceItem) |
---|
614 | return namespaceItem->getComponents(objectType); |
---|
615 | |
---|
616 | return 0; |
---|
617 | } |
---|
618 | |
---|
619 | /** |
---|
620 | * [annotations]: a set of annotations. |
---|
621 | */ |
---|
622 | XSAnnotationList *XSModel::getAnnotations() |
---|
623 | { |
---|
624 | return fXSAnnotationList; |
---|
625 | } |
---|
626 | |
---|
627 | /** |
---|
628 | * Convenience method. Returns a top-level element declaration. |
---|
629 | * @param name The name of the declaration. |
---|
630 | * @param compNamespace The namespace of the declaration, null if absent. |
---|
631 | * @return A top-level element declaration or <code>null</code> if such |
---|
632 | * declaration does not exist. |
---|
633 | */ |
---|
634 | XSElementDeclaration *XSModel::getElementDeclaration(const XMLCh *name |
---|
635 | , const XMLCh *compNamespace) |
---|
636 | { |
---|
637 | XSNamespaceItem* namespaceItem; |
---|
638 | if (compNamespace) |
---|
639 | namespaceItem = getNamespaceItem(compNamespace); |
---|
640 | else |
---|
641 | namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString); |
---|
642 | |
---|
643 | if (namespaceItem) |
---|
644 | return namespaceItem->getElementDeclaration(name); |
---|
645 | |
---|
646 | return 0; |
---|
647 | } |
---|
648 | |
---|
649 | /** |
---|
650 | * Convenience method. Returns a top-level attribute declaration. |
---|
651 | * @param name The name of the declaration. |
---|
652 | * @param compNamespace The namespace of the declaration, null if absent. |
---|
653 | * @return A top-level attribute declaration or <code>null</code> if such |
---|
654 | * declaration does not exist. |
---|
655 | */ |
---|
656 | XSAttributeDeclaration *XSModel::getAttributeDeclaration(const XMLCh *name |
---|
657 | , const XMLCh *compNamespace) |
---|
658 | { |
---|
659 | XSNamespaceItem* namespaceItem; |
---|
660 | if (compNamespace) |
---|
661 | namespaceItem = getNamespaceItem(compNamespace); |
---|
662 | else |
---|
663 | namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString); |
---|
664 | |
---|
665 | if (namespaceItem) |
---|
666 | return namespaceItem->getAttributeDeclaration(name); |
---|
667 | |
---|
668 | return 0; |
---|
669 | } |
---|
670 | |
---|
671 | /** |
---|
672 | * Convenience method. Returns a top-level simple or complex type |
---|
673 | * definition. |
---|
674 | * @param name The name of the definition. |
---|
675 | * @param compNamespace The namespace of the declaration, null if absent. |
---|
676 | * @return An <code>XSTypeDefinition</code> or <code>null</code> if such |
---|
677 | * definition does not exist. |
---|
678 | */ |
---|
679 | XSTypeDefinition *XSModel::getTypeDefinition(const XMLCh *name |
---|
680 | , const XMLCh *compNamespace) |
---|
681 | { |
---|
682 | XSNamespaceItem* namespaceItem; |
---|
683 | if (compNamespace) |
---|
684 | namespaceItem = getNamespaceItem(compNamespace); |
---|
685 | else |
---|
686 | namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString); |
---|
687 | |
---|
688 | if (namespaceItem) |
---|
689 | return namespaceItem->getTypeDefinition(name); |
---|
690 | |
---|
691 | return 0; |
---|
692 | } |
---|
693 | |
---|
694 | /** |
---|
695 | * Convenience method. Returns a top-level attribute group definition. |
---|
696 | * @param name The name of the definition. |
---|
697 | * @param compNamespace The namespace of the declaration, null if absent. |
---|
698 | * @return A top-level attribute group definition or <code>null</code> if |
---|
699 | * such definition does not exist. |
---|
700 | */ |
---|
701 | XSAttributeGroupDefinition *XSModel::getAttributeGroup(const XMLCh *name |
---|
702 | , const XMLCh *compNamespace) |
---|
703 | { |
---|
704 | XSNamespaceItem* namespaceItem; |
---|
705 | if (compNamespace) |
---|
706 | namespaceItem = getNamespaceItem(compNamespace); |
---|
707 | else |
---|
708 | namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString); |
---|
709 | |
---|
710 | if (namespaceItem) |
---|
711 | return namespaceItem->getAttributeGroup(name); |
---|
712 | |
---|
713 | return 0; |
---|
714 | } |
---|
715 | |
---|
716 | /** |
---|
717 | * Convenience method. Returns a top-level model group definition. |
---|
718 | * @param name The name of the definition. |
---|
719 | * @param compNamespace The namespace of the declaration, null if absent. |
---|
720 | * @return A top-level model group definition definition or |
---|
721 | * <code>null</code> if such definition does not exist. |
---|
722 | */ |
---|
723 | XSModelGroupDefinition *XSModel::getModelGroupDefinition(const XMLCh *name |
---|
724 | , const XMLCh *compNamespace) |
---|
725 | { |
---|
726 | XSNamespaceItem* namespaceItem; |
---|
727 | if (compNamespace) |
---|
728 | namespaceItem = getNamespaceItem(compNamespace); |
---|
729 | else |
---|
730 | namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString); |
---|
731 | |
---|
732 | if (namespaceItem) |
---|
733 | return namespaceItem->getModelGroupDefinition(name); |
---|
734 | |
---|
735 | return 0; |
---|
736 | } |
---|
737 | |
---|
738 | /** |
---|
739 | * Convenience method. Returns a top-level notation declaration. |
---|
740 | * @param name The name of the declaration. |
---|
741 | * @param compNamespace The namespace of the declaration, null if absent. |
---|
742 | * @return A top-level notation declaration or <code>null</code> if such |
---|
743 | * declaration does not exist. |
---|
744 | */ |
---|
745 | XSNotationDeclaration *XSModel::getNotationDeclaration(const XMLCh *name |
---|
746 | , const XMLCh *compNamespace) |
---|
747 | { |
---|
748 | XSNamespaceItem* namespaceItem; |
---|
749 | if (compNamespace) |
---|
750 | namespaceItem = getNamespaceItem(compNamespace); |
---|
751 | else |
---|
752 | namespaceItem = getNamespaceItem(XMLUni::fgZeroLenString); |
---|
753 | |
---|
754 | if (namespaceItem) |
---|
755 | return namespaceItem->getNotationDeclaration(name); |
---|
756 | |
---|
757 | return 0; |
---|
758 | } |
---|
759 | |
---|
760 | /** |
---|
761 | * Optional. Return a component given a component type and a unique Id. |
---|
762 | * May not be supported for all component types. |
---|
763 | * @param compId unique Id of the component within its type |
---|
764 | * @param compType type of the component |
---|
765 | * @return the component of the given type with the given Id, or 0 |
---|
766 | * if no such component exists or this is unsupported for |
---|
767 | * this type of component. |
---|
768 | */ |
---|
769 | XSObject *XSModel::getXSObjectById(XMLSize_t compId |
---|
770 | , XSConstants::COMPONENT_TYPE compType) |
---|
771 | { |
---|
772 | if (compId < fIdVector[compType -1]->size()) |
---|
773 | return fIdVector[compType -1]->elementAt(compId); |
---|
774 | |
---|
775 | return 0; |
---|
776 | } |
---|
777 | |
---|
778 | XSNamespaceItem* XSModel::getNamespaceItem(const XMLCh* const key) |
---|
779 | { |
---|
780 | XSNamespaceItem* xsName = fHashNamespace->get(key); |
---|
781 | if (xsName) |
---|
782 | return xsName; |
---|
783 | if (fParent) |
---|
784 | return fParent->getNamespaceItem(key); |
---|
785 | return 0; |
---|
786 | } |
---|
787 | |
---|
788 | XSObject* XSModel::getXSObject(void* key) |
---|
789 | { |
---|
790 | XSObject* xsObj = fObjFactory->getObjectFromMap(key); |
---|
791 | |
---|
792 | if (!xsObj && fParent) |
---|
793 | xsObj = fParent->getXSObject(key); |
---|
794 | |
---|
795 | return xsObj; |
---|
796 | } |
---|
797 | |
---|
798 | |
---|
799 | XERCES_CPP_NAMESPACE_END |
---|