PageRenderTime 27ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/ATF2/control-software/epics-3.14.8/extensions/src/ChannelArchiver/ThirdParty/xerces-c-src2_4_0/src/xercesc/validators/schema/ComplexTypeInfo.cpp

http://atf2flightsim.googlecode.com/
C++ | 1069 lines | 605 code | 121 blank | 343 comment | 149 complexity | b7925b907079be8389196a8dcf87be07 MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 2001 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution,
  20. * if any, must include the following acknowledgment:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowledgment may appear in the software itself,
  24. * if and wherever such third-party acknowledgments normally appear.
  25. *
  26. * 4. The names "Xerces" and "Apache Software Foundation" must
  27. * not be used to endorse or promote products derived from this
  28. * software without prior written permission. For written
  29. * permission, please contact apache\@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache",
  32. * nor may "Apache" appear in their name, without prior written
  33. * permission of the Apache Software Foundation.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation, and was
  51. * originally based on software copyright (c) 1999, International
  52. * Business Machines, Inc., http://www.ibm.com . For more information
  53. * on the Apache Software Foundation, please see
  54. * <http://www.apache.org/>.
  55. */
  56. /*
  57. * $Log: ComplexTypeInfo.cpp,v $
  58. * Revision 1.1.1.1 2009/03/14 06:43:13 whitegr
  59. * epics channel archiver
  60. *
  61. * Revision 1.20 2003/11/20 18:05:16 knoaman
  62. * PSVI: Use a copy of the content spec node when creating the content model.
  63. *
  64. * Revision 1.19 2003/11/13 23:20:47 peiyongz
  65. * initSize
  66. *
  67. * Revision 1.18 2003/11/10 21:54:51 neilg
  68. * implementation for new stateless means of traversing attribute definition lists
  69. *
  70. * Revision 1.17 2003/11/07 17:08:12 knoaman
  71. * For PSVI support, distinguish wildcard elements with namespace lists.
  72. *
  73. * Revision 1.16 2003/10/29 16:22:58 peiyongz
  74. * allow proper recreation of ContentModel from deserialization
  75. *
  76. * Revision 1.15 2003/10/21 10:23:53 amassari
  77. * When creating a new list of attributes, use the assigned memory manager
  78. *
  79. * Revision 1.14 2003/10/17 21:17:12 peiyongz
  80. * using XTemplateSerializer
  81. *
  82. * Revision 1.13 2003/10/14 15:22:28 peiyongz
  83. * Implementation of Serialization/Deserialization
  84. *
  85. * Revision 1.12 2003/10/10 16:25:40 peiyongz
  86. * Implementation of Serialization/Deserialization
  87. *
  88. * Revision 1.11 2003/10/08 21:33:48 peiyongz
  89. * Synchronize ContentSpec/ContentModel/FormattedModel
  90. *
  91. * Revision 1.10 2003/09/26 18:31:05 peiyongz
  92. * Synchronize ContentSpecNode and formattedModel
  93. *
  94. * Revision 1.9 2003/05/18 14:02:07 knoaman
  95. * Memory manager implementation: pass per instance manager.
  96. *
  97. * Revision 1.8 2003/05/16 21:43:21 knoaman
  98. * Memory manager implementation: Modify constructors to pass in the memory manager.
  99. *
  100. * Revision 1.7 2003/05/15 18:57:27 knoaman
  101. * Partial implementation of the configurable memory manager.
  102. *
  103. * Revision 1.6 2003/01/29 19:57:30 gareth
  104. * API to retrive local and uri part of the type name
  105. *
  106. * Revision 1.5 2002/12/19 14:04:05 gareth
  107. * get/set methods to see if the represented type is anonymous. Patch by Peter Volchek.
  108. *
  109. * Revision 1.4 2002/11/04 14:49:41 tng
  110. * C++ Namespace Support.
  111. *
  112. * Revision 1.3 2002/03/21 15:34:40 knoaman
  113. * Add support for reporting line/column numbers of schema errors.
  114. *
  115. * Revision 1.2 2002/02/06 22:29:24 knoaman
  116. * Remove unnecessary data/methods.
  117. *
  118. * Revision 1.1.1.1 2002/02/01 22:22:45 peiyongz
  119. * sane_include
  120. *
  121. * Revision 1.27 2002/01/15 19:09:16 knoaman
  122. * Fix for bug 5807.
  123. *
  124. * Revision 1.26 2002/01/02 15:20:22 tng
  125. * Schema Fix: should not store a temp value as the key in the element pool and the attribute pool.
  126. *
  127. * Revision 1.25 2001/12/17 21:38:59 tng
  128. * Fix dangling pointer.
  129. *
  130. * Revision 1.24 2001/11/21 14:30:13 knoaman
  131. * Fix for UPA checking.
  132. *
  133. * Revision 1.23 2001/11/15 17:10:19 knoaman
  134. * Particle derivation checking support.
  135. *
  136. * Revision 1.22 2001/11/07 21:50:28 tng
  137. * Fix comment log that lead to error.
  138. *
  139. * Revision 1.21 2001/11/07 21:12:15 tng
  140. * Performance: Create QName in ContentSpecNode only if it is a leaf/Any/PCDataNode.
  141. *
  142. * Revision 1.20 2001/10/12 18:08:57 tng
  143. * make sure the second node exists before calling getType
  144. *
  145. * Revision 1.19 2001/10/04 15:08:56 knoaman
  146. * Add support for circular import.
  147. *
  148. * Revision 1.18 2001/09/05 20:49:11 knoaman
  149. * Fix for complexTypes with mixed content model.
  150. *
  151. * Revision 1.17 2001/08/29 21:27:07 knoaman
  152. * no message
  153. *
  154. * Revision 1.16 2001/08/28 20:43:52 knoaman
  155. * Fix for content spec node adoption.
  156. *
  157. * Revision 1.15 2001/08/27 23:04:02 knoaman
  158. * Handle deletion of spec node tree created during UPA checking.
  159. *
  160. * Revision 1.14 2001/08/27 20:48:45 knoaman
  161. * Make the UPA rename before the content model expansion.
  162. *
  163. * Revision 1.13 2001/08/27 20:14:42 knoaman
  164. * Validate attributes in <all>, <redefine>, <group> and <attributeGroup> declarations.
  165. * Misc. fixes.
  166. *
  167. * Revision 1.12 2001/08/24 12:48:48 tng
  168. * Schema: AllContentModel
  169. *
  170. * Revision 1.11 2001/08/23 11:54:26 tng
  171. * Add newline at the end and various typo fixes.
  172. *
  173. * Revision 1.10 2001/08/21 18:14:55 knoaman
  174. * Defer creation of spec node.
  175. *
  176. * Revision 1.9 2001/08/21 16:06:11 tng
  177. * Schema: Unique Particle Attribution Constraint Checking.
  178. *
  179. * Revision 1.8 2001/08/09 15:23:16 knoaman
  180. * add support for <anyAttribute> declaration.
  181. *
  182. * Revision 1.7 2001/07/24 18:33:46 knoaman
  183. * Added support for <group> + extra constraint checking for complexType
  184. *
  185. * Revision 1.6 2001/06/05 13:59:53 knoaman
  186. * Fixes to include and import.
  187. *
  188. * Revision 1.5 2001/05/11 13:27:32 tng
  189. * Copyright update.
  190. *
  191. * Revision 1.4 2001/05/10 17:49:40 tng
  192. * Schema: SchemaValidator fixes
  193. *
  194. * Revision 1.3 2001/05/10 16:33:12 knoaman
  195. * Traverse Schema Part III + error messages.
  196. *
  197. * Revision 1.2 2001/05/03 20:34:41 tng
  198. * Schema: SchemaValidator update
  199. *
  200. * Revision 1.1 2001/04/19 17:43:14 knoaman
  201. * More schema implementation classes.
  202. *
  203. */
  204. // ---------------------------------------------------------------------------
  205. // Includes
  206. // ---------------------------------------------------------------------------
  207. #include <xercesc/framework/XMLBuffer.hpp>
  208. #include <xercesc/validators/schema/ComplexTypeInfo.hpp>
  209. #include <xercesc/validators/schema/SchemaAttDefList.hpp>
  210. #include <xercesc/validators/common/AllContentModel.hpp>
  211. #include <xercesc/validators/common/ContentSpecNode.hpp>
  212. #include <xercesc/validators/common/DFAContentModel.hpp>
  213. #include <xercesc/validators/common/MixedContentModel.hpp>
  214. #include <xercesc/validators/common/SimpleContentModel.hpp>
  215. #include <xercesc/validators/schema/XSDLocator.hpp>
  216. #include <xercesc/internal/XTemplateSerializer.hpp>
  217. XERCES_CPP_NAMESPACE_BEGIN
  218. // ---------------------------------------------------------------------------
  219. // ComplexTypeInfo: Constructors and Destructor
  220. // ---------------------------------------------------------------------------
  221. ComplexTypeInfo::ComplexTypeInfo(MemoryManager* const manager)
  222. : fAnonymous(false)
  223. , fAbstract(false)
  224. , fAdoptContentSpec(true)
  225. , fAttWithTypeId(false)
  226. , fPreprocessed(false)
  227. , fDerivedBy(0)
  228. , fBlockSet(0)
  229. , fFinalSet(0)
  230. , fScopeDefined(Grammar::TOP_LEVEL_SCOPE)
  231. , fElementId(XMLElementDecl::fgInvalidElemId)
  232. , fContentType(SchemaElementDecl::Empty)
  233. , fTypeName(0)
  234. , fTypeLocalName(0)
  235. , fTypeUri(0)
  236. , fBaseDatatypeValidator(0)
  237. , fDatatypeValidator(0)
  238. , fBaseComplexTypeInfo(0)
  239. , fContentSpec(0)
  240. , fAttWildCard(0)
  241. , fAttDefs(0)
  242. , fAttList(0)
  243. , fElements(0)
  244. , fContentModel(0)
  245. , fFormattedModel(0)
  246. , fContentSpecOrgURI(0)
  247. , fUniqueURI(0)
  248. , fContentSpecOrgURISize(16)
  249. , fSpecNodesToDelete(0)
  250. , fLocator(0)
  251. , fMemoryManager(manager)
  252. {
  253. }
  254. ComplexTypeInfo::~ComplexTypeInfo()
  255. {
  256. fMemoryManager->deallocate(fTypeName); //delete [] fTypeName;
  257. fMemoryManager->deallocate(fTypeLocalName); //delete [] fTypeLocalName;
  258. fMemoryManager->deallocate(fTypeUri); //delete [] fTypeUri;
  259. if (fAdoptContentSpec) {
  260. delete fContentSpec;
  261. }
  262. delete fAttWildCard;
  263. delete fAttDefs;
  264. delete fAttList;
  265. delete fElements;
  266. delete fSpecNodesToDelete;
  267. delete fLocator;
  268. delete fContentModel;
  269. fMemoryManager->deallocate(fFormattedModel); //delete [] fFormattedModel;
  270. fMemoryManager->deallocate(fContentSpecOrgURI); //delete [] fContentSpecOrgURI;
  271. }
  272. // ---------------------------------------------------------------------------
  273. // ComplexTypeInfo: Setter methods
  274. // ---------------------------------------------------------------------------
  275. void ComplexTypeInfo::addAttDef(SchemaAttDef* const toAdd) {
  276. // Fault in the att list if required
  277. if (!fAttDefs)
  278. faultInAttDefList();
  279. // Tell this guy the element id of its parent (us)
  280. toAdd->setElemId(getElementId());
  281. fAttDefs->put((void*)(toAdd->getAttName()->getLocalPart()),
  282. toAdd->getAttName()->getURI(), toAdd);
  283. // update and/or create fAttList
  284. if(!fAttList)
  285. ((ComplexTypeInfo*)this)->fAttList = new (fMemoryManager) SchemaAttDefList(fAttDefs,fMemoryManager);
  286. fAttList->addAttDef(toAdd);
  287. }
  288. void ComplexTypeInfo::setContentSpec(ContentSpecNode* const toAdopt) {
  289. if (fContentSpec && fAdoptContentSpec) {
  290. delete fContentSpec;
  291. }
  292. fContentSpec = toAdopt;
  293. //reset Content Model
  294. setContentModel(0);
  295. }
  296. void ComplexTypeInfo::setLocator(XSDLocator* const aLocator) {
  297. if (fLocator)
  298. delete fLocator;
  299. fLocator = aLocator;
  300. }
  301. // ---------------------------------------------------------------------------
  302. // ComplexTypeInfo: Getter methods
  303. // ---------------------------------------------------------------------------
  304. XMLAttDefList& ComplexTypeInfo::getAttDefList() const
  305. {
  306. if (!fAttList)
  307. {
  308. // If the att def list is not made yet, then fault it in too
  309. if (!fAttDefs)
  310. faultInAttDefList();
  311. ((ComplexTypeInfo*)this)->fAttList = new (fMemoryManager) SchemaAttDefList(fAttDefs, fMemoryManager);
  312. }
  313. // Reset it before we return it
  314. fAttList->Reset();
  315. return *fAttList;
  316. }
  317. const XMLCh*
  318. ComplexTypeInfo::getFormattedContentModel() const
  319. {
  320. //
  321. // If its not already built, then call the protected virtual method
  322. // to allow the derived class to build it (since only it knows.)
  323. // Otherwise, just return the previously formatted methods.
  324. //
  325. // Since we are faulting this in, within a const getter, we have to
  326. // cast off the const-ness.
  327. //
  328. if (!fFormattedModel)
  329. ((ComplexTypeInfo*)this)->fFormattedModel = formatContentModel();
  330. return fFormattedModel;
  331. }
  332. // ---------------------------------------------------------------------------
  333. // ComplexTypeInfo: Helper methods
  334. // ---------------------------------------------------------------------------
  335. XMLAttDef* ComplexTypeInfo::findAttr(const XMLCh* const qName
  336. , const unsigned int uriId
  337. , const XMLCh* const baseName
  338. , const XMLCh* const prefix
  339. , const XMLElementDecl::LookupOpts options
  340. , bool& wasAdded) const
  341. {
  342. SchemaAttDef* retVal = 0;
  343. // If no att list faulted in yet, then it cannot exist
  344. if (fAttDefs)
  345. retVal = fAttDefs->get(baseName, uriId);
  346. // Fault it in if not found and ask to add it
  347. if (!retVal && (options == XMLElementDecl::AddIfNotFound))
  348. {
  349. // Fault in the list itself if not already
  350. if (!fAttDefs)
  351. faultInAttDefList();
  352. // And add a default attribute for this name
  353. retVal = new (fMemoryManager) SchemaAttDef
  354. (
  355. prefix
  356. , baseName
  357. , uriId
  358. , XMLAttDef::CData
  359. , XMLAttDef::Implied
  360. , fMemoryManager
  361. );
  362. retVal->setElemId(getElementId());
  363. fAttDefs->put((void*)retVal->getAttName()->getLocalPart(), uriId, retVal);
  364. // update and/or create fAttList
  365. if(!fAttList)
  366. ((ComplexTypeInfo*)this)->fAttList = new (fMemoryManager) SchemaAttDefList(fAttDefs,fMemoryManager);
  367. fAttList->addAttDef(retVal);
  368. wasAdded = true;
  369. }
  370. else
  371. {
  372. wasAdded = false;
  373. }
  374. return retVal;
  375. }
  376. bool ComplexTypeInfo::resetDefs() {
  377. // If the collection hasn't been faulted in, then no att defs
  378. if (!fAttDefs)
  379. return false;
  380. //
  381. // Ok, run through them and clear the 'provided' flag on each of them.
  382. // This lets the scanner use them to track which has been provided and
  383. // which have not.
  384. //
  385. RefHash2KeysTableOfEnumerator<SchemaAttDef> enumDefs(fAttDefs);
  386. while (enumDefs.hasMoreElements())
  387. enumDefs.nextElement().setProvided(false);
  388. return true;
  389. }
  390. void ComplexTypeInfo::checkUniqueParticleAttribution (SchemaGrammar* const pGrammar,
  391. GrammarResolver* const pGrammarResolver,
  392. XMLStringPool* const pStringPool,
  393. XMLValidator* const pValidator)
  394. {
  395. if (fContentSpec) {
  396. ContentSpecNode* specNode = new (fMemoryManager) ContentSpecNode(*fContentSpec);
  397. XMLContentModel* cm = makeContentModel(true, specNode);
  398. if (cm) {
  399. cm->checkUniqueParticleAttribution(pGrammar, pGrammarResolver, pStringPool, pValidator, fContentSpecOrgURI);
  400. delete cm;
  401. }
  402. fSpecNodesToDelete->removeAllElements();
  403. }
  404. }
  405. // ---------------------------------------------------------------------------
  406. // ComplexTypeInfo: Private Helper methods
  407. // ---------------------------------------------------------------------------
  408. void ComplexTypeInfo::faultInAttDefList() const
  409. {
  410. // Use a hash modulus of 29 and tell it owns its elements
  411. ((ComplexTypeInfo*)this)->fAttDefs =
  412. new (fMemoryManager) RefHash2KeysTableOf<SchemaAttDef>(29, true, fMemoryManager);
  413. }
  414. XMLCh* ComplexTypeInfo::formatContentModel() const
  415. {
  416. XMLCh* newValue = 0;
  417. if (fContentType == SchemaElementDecl::Any)
  418. {
  419. newValue = XMLString::replicate(XMLUni::fgAnyString, fMemoryManager);
  420. }
  421. else if (fContentType == SchemaElementDecl::Empty)
  422. {
  423. newValue = XMLString::replicate(XMLUni::fgEmptyString, fMemoryManager);
  424. }
  425. else
  426. {
  427. //
  428. // Use a temp XML buffer to format into. Content models could be
  429. // pretty long, but very few will be longer than one K. The buffer
  430. // will expand to handle the more pathological ones.
  431. //
  432. const ContentSpecNode* specNode = fContentSpec;
  433. if (specNode) {
  434. XMLBuffer bufFmt(1023, fMemoryManager);
  435. specNode->formatSpec(bufFmt);
  436. newValue = XMLString::replicate
  437. (
  438. bufFmt.getRawBuffer()
  439. , fMemoryManager
  440. );
  441. }
  442. }
  443. return newValue;
  444. }
  445. XMLContentModel* ComplexTypeInfo::makeContentModel(const bool checkUPA, ContentSpecNode* const specNode)
  446. {
  447. if ((specNode || fContentSpec) && !fSpecNodesToDelete) {
  448. fSpecNodesToDelete = new (fMemoryManager) RefVectorOf<ContentSpecNode>(8, true, fMemoryManager);
  449. }
  450. // expand the content spec first
  451. ContentSpecNode* aSpecNode = specNode;
  452. XMLContentModel* retModel = 0;
  453. if (aSpecNode) {
  454. fContentSpecOrgURI = (unsigned int*) fMemoryManager->allocate
  455. (
  456. fContentSpecOrgURISize * sizeof(unsigned int)
  457. ); //new unsigned int[fContentSpecOrgURISize];
  458. aSpecNode = convertContentSpecTree(aSpecNode, checkUPA);
  459. retModel = buildContentModel(aSpecNode);
  460. fSpecNodesToDelete->addElement(aSpecNode);
  461. }
  462. else {
  463. // building content model for the complex type
  464. aSpecNode = new (fMemoryManager) ContentSpecNode(*fContentSpec);
  465. aSpecNode = convertContentSpecTree(aSpecNode, checkUPA);
  466. retModel = buildContentModel(aSpecNode);
  467. delete aSpecNode;
  468. }
  469. return retModel;
  470. }
  471. XMLContentModel* ComplexTypeInfo::buildContentModel(ContentSpecNode* const aSpecNode)
  472. {
  473. XMLContentModel* cmRet = 0;
  474. if (fContentType == SchemaElementDecl::Simple) {
  475. // just return nothing
  476. }
  477. else if (fContentType == SchemaElementDecl::Mixed_Simple)
  478. {
  479. //
  480. // Just create a mixel content model object. This type of
  481. // content model is optimized for mixed content validation.
  482. //
  483. cmRet = new (fMemoryManager) MixedContentModel(false, aSpecNode, false, fMemoryManager);
  484. }
  485. else if (fContentType == SchemaElementDecl::Mixed_Complex) {
  486. cmRet = createChildModel(aSpecNode, true);
  487. }
  488. else if (fContentType == SchemaElementDecl::Children)
  489. {
  490. //
  491. // This method will create an optimal model for the complexity
  492. // of the element's defined model. If its simple, it will create
  493. // a SimpleContentModel object. If its a simple list, it will
  494. // create a SimpleListContentModel object. If its complex, it
  495. // will create a DFAContentModel object.
  496. //
  497. cmRet = createChildModel(aSpecNode, false);
  498. }
  499. else
  500. {
  501. ThrowXML(RuntimeException, XMLExcepts::CM_MustBeMixedOrChildren);
  502. }
  503. return cmRet;
  504. }
  505. // ---------------------------------------------------------------------------
  506. // SchemaElementDecl: Private helper methods
  507. // ---------------------------------------------------------------------------
  508. XMLContentModel* ComplexTypeInfo::createChildModel(ContentSpecNode* specNode, const bool isMixed)
  509. {
  510. if(!specNode)
  511. ThrowXML(RuntimeException, XMLExcepts::CM_UnknownCMSpecType);
  512. ContentSpecNode::NodeTypes specType = specNode->getType();
  513. //
  514. // Do a sanity check that the node is does not have a PCDATA id. Since,
  515. // if it was, it should have already gotten taken by the Mixed model.
  516. //
  517. if (specNode->getElement()) {
  518. if (specNode->getElement()->getURI() == XMLElementDecl::fgPCDataElemId)
  519. ThrowXML(RuntimeException, XMLExcepts::CM_NoPCDATAHere);
  520. }
  521. //
  522. // According to the type of node, we will create the correct type of
  523. // content model.
  524. //
  525. if (((specType & 0x0f) == ContentSpecNode::Any) ||
  526. ((specType & 0x0f) == ContentSpecNode::Any_Other) ||
  527. ((specType & 0x0f) == ContentSpecNode::Any_NS)) {
  528. // let fall through to build a DFAContentModel
  529. }
  530. else if (isMixed)
  531. {
  532. if (specType == ContentSpecNode::All) {
  533. // All the nodes under an ALL must be additional ALL nodes and
  534. // ELEMENTs (or ELEMENTs under ZERO_OR_ONE nodes.)
  535. // We collapse the ELEMENTs into a single vector.
  536. return new (fMemoryManager) AllContentModel(specNode, true, fMemoryManager);
  537. }
  538. else if (specType == ContentSpecNode::ZeroOrOne) {
  539. // An ALL node can appear under a ZERO_OR_ONE node.
  540. if (specNode->getFirst()->getType() == ContentSpecNode::All) {
  541. return new (fMemoryManager) AllContentModel(specNode->getFirst(), true, fMemoryManager);
  542. }
  543. }
  544. // otherwise, let fall through to build a DFAContentModel
  545. }
  546. else if (specType == ContentSpecNode::Leaf)
  547. {
  548. // Create a simple content model
  549. return new (fMemoryManager) SimpleContentModel
  550. (
  551. false
  552. , specNode->getElement()
  553. , 0
  554. , ContentSpecNode::Leaf
  555. , fMemoryManager
  556. );
  557. }
  558. else if (((specType & 0x0f) == ContentSpecNode::Choice)
  559. || ((specType & 0x0f) == ContentSpecNode::Sequence))
  560. {
  561. //
  562. // Lets see if both of the children are leafs. If so, then it has to
  563. // be a simple content model
  564. //
  565. if ((specNode->getFirst()->getType() == ContentSpecNode::Leaf)
  566. && (specNode->getSecond())
  567. && (specNode->getSecond()->getType() == ContentSpecNode::Leaf))
  568. {
  569. return new (fMemoryManager) SimpleContentModel
  570. (
  571. false
  572. , specNode->getFirst()->getElement()
  573. , specNode->getSecond()->getElement()
  574. , specType
  575. , fMemoryManager
  576. );
  577. }
  578. }
  579. else if ((specType == ContentSpecNode::OneOrMore)
  580. || (specType == ContentSpecNode::ZeroOrMore)
  581. || (specType == ContentSpecNode::ZeroOrOne))
  582. {
  583. //
  584. // Its a repetition, so see if its one child is a leaf. If so its a
  585. // repetition of a single element, so we can do a simple content
  586. // model for that.
  587. //
  588. if (specNode->getFirst()->getType() == ContentSpecNode::Leaf)
  589. {
  590. return new (fMemoryManager) SimpleContentModel
  591. (
  592. false
  593. , specNode->getFirst()->getElement()
  594. , 0
  595. , specType
  596. , fMemoryManager
  597. );
  598. }
  599. else if (specNode->getFirst()->getType() == ContentSpecNode::All)
  600. return new (fMemoryManager) AllContentModel(specNode->getFirst(), false, fMemoryManager);
  601. }
  602. else if (specType == ContentSpecNode::All)
  603. return new (fMemoryManager) AllContentModel(specNode, false, fMemoryManager);
  604. else
  605. {
  606. ThrowXML(RuntimeException, XMLExcepts::CM_UnknownCMSpecType);
  607. }
  608. // Its not any simple type of content, so create a DFA based content model
  609. return new (fMemoryManager) DFAContentModel(false, specNode, isMixed, fMemoryManager);
  610. }
  611. ContentSpecNode*
  612. ComplexTypeInfo::convertContentSpecTree(ContentSpecNode* const curNode,
  613. const bool checkUPA) {
  614. if (!curNode)
  615. return 0;
  616. const ContentSpecNode::NodeTypes curType = curNode->getType();
  617. // When checking Unique Particle Attribution, rename leaf elements
  618. if (checkUPA) {
  619. if (curNode->getElement()) {
  620. fContentSpecOrgURI[fUniqueURI] = curNode->getElement()->getURI();
  621. curNode->getElement()->setURI(fUniqueURI);
  622. fUniqueURI++;
  623. }
  624. if (fUniqueURI == fContentSpecOrgURISize)
  625. resizeContentSpecOrgURI();
  626. }
  627. // Get the spec type of the passed node
  628. int minOccurs = curNode->getMinOccurs();
  629. int maxOccurs = curNode->getMaxOccurs();
  630. ContentSpecNode* retNode = curNode;
  631. if ((curType & 0x0f) == ContentSpecNode::Any
  632. || (curType & 0x0f) == ContentSpecNode::Any_Other
  633. || (curType & 0x0f) == ContentSpecNode::Any_NS
  634. || curType == ContentSpecNode::Leaf)
  635. {
  636. retNode = expandContentModel(curNode, minOccurs, maxOccurs);
  637. }
  638. else if (((curType & 0x0f) == ContentSpecNode::Choice)
  639. || (curType == ContentSpecNode::All)
  640. || ((curType & 0x0f) == ContentSpecNode::Sequence))
  641. {
  642. ContentSpecNode* childNode = curNode->getFirst();
  643. ContentSpecNode* leftNode = convertContentSpecTree(childNode, checkUPA);
  644. ContentSpecNode* rightNode = curNode->getSecond();
  645. if (!rightNode) {
  646. retNode = expandContentModel(leftNode, minOccurs, maxOccurs);
  647. curNode->setAdoptFirst(false);
  648. delete curNode;
  649. return retNode;
  650. }
  651. if (leftNode != childNode) {
  652. curNode->setAdoptFirst(false);
  653. curNode->setFirst(leftNode);
  654. curNode->setAdoptFirst(true);
  655. }
  656. childNode = rightNode;
  657. rightNode = convertContentSpecTree(childNode, checkUPA);
  658. if (rightNode != childNode) {
  659. curNode->setAdoptSecond(false);
  660. curNode->setSecond(rightNode);
  661. curNode->setAdoptSecond(true);
  662. }
  663. retNode = expandContentModel(curNode, minOccurs, maxOccurs);
  664. }
  665. return retNode;
  666. }
  667. ContentSpecNode* ComplexTypeInfo::expandContentModel(ContentSpecNode* const specNode,
  668. const int minOccurs,
  669. const int maxOccurs)
  670. {
  671. if (!specNode) {
  672. return 0;
  673. }
  674. ContentSpecNode* saveNode = specNode;
  675. ContentSpecNode* retNode = specNode;
  676. if (minOccurs == 1 && maxOccurs == 1) {
  677. }
  678. else if (minOccurs == 0 && maxOccurs == 1) {
  679. retNode = new (fMemoryManager) ContentSpecNode
  680. (
  681. ContentSpecNode::ZeroOrOne
  682. , retNode
  683. , 0
  684. , true
  685. , true
  686. , fMemoryManager
  687. );
  688. }
  689. else if (minOccurs == 0 && maxOccurs == -1) {
  690. retNode = new (fMemoryManager) ContentSpecNode
  691. (
  692. ContentSpecNode::ZeroOrMore
  693. , retNode
  694. , 0
  695. , true
  696. , true
  697. , fMemoryManager
  698. );
  699. }
  700. else if (minOccurs == 1 && maxOccurs == -1) {
  701. retNode = new (fMemoryManager) ContentSpecNode
  702. (
  703. ContentSpecNode::OneOrMore
  704. , retNode
  705. , 0
  706. , true
  707. , true
  708. , fMemoryManager
  709. );
  710. }
  711. else if (maxOccurs == -1) {
  712. retNode = new (fMemoryManager) ContentSpecNode
  713. (
  714. ContentSpecNode::OneOrMore
  715. , retNode
  716. , 0
  717. , true
  718. , true
  719. , fMemoryManager
  720. );
  721. for (int i=0; i < (int)(minOccurs-1); i++) {
  722. retNode = new (fMemoryManager) ContentSpecNode
  723. (
  724. ContentSpecNode::Sequence
  725. , saveNode
  726. , retNode
  727. , false
  728. , true
  729. , fMemoryManager
  730. );
  731. }
  732. }
  733. else {
  734. if (minOccurs == 0) {
  735. ContentSpecNode* optional = new (fMemoryManager) ContentSpecNode
  736. (
  737. ContentSpecNode::ZeroOrOne
  738. , saveNode
  739. , 0
  740. , true
  741. , true
  742. , fMemoryManager
  743. );
  744. retNode = optional;
  745. for (int i=0; i < (int)(maxOccurs-minOccurs-1); i++) {
  746. retNode = new (fMemoryManager) ContentSpecNode
  747. (
  748. ContentSpecNode::Sequence
  749. , retNode
  750. , optional
  751. , true
  752. , false
  753. , fMemoryManager
  754. );
  755. }
  756. }
  757. else {
  758. if (minOccurs > 1) {
  759. retNode = new (fMemoryManager) ContentSpecNode
  760. (
  761. ContentSpecNode::Sequence
  762. , retNode
  763. , saveNode
  764. , true
  765. , false
  766. , fMemoryManager
  767. );
  768. for (int i=1; i < (int)(minOccurs-1); i++) {
  769. retNode = new (fMemoryManager) ContentSpecNode
  770. (
  771. ContentSpecNode::Sequence
  772. , retNode
  773. , saveNode
  774. , true
  775. , false
  776. , fMemoryManager
  777. );
  778. }
  779. }
  780. int counter = maxOccurs-minOccurs;
  781. if (counter > 0) {
  782. ContentSpecNode* optional = new (fMemoryManager) ContentSpecNode
  783. (
  784. ContentSpecNode::ZeroOrOne
  785. , saveNode
  786. , 0
  787. , false
  788. , true
  789. , fMemoryManager
  790. );
  791. retNode = new (fMemoryManager) ContentSpecNode
  792. (
  793. ContentSpecNode::Sequence
  794. , retNode
  795. , optional
  796. , true
  797. , true
  798. , fMemoryManager
  799. );
  800. for (int j=1; j < counter; j++) {
  801. retNode = new (fMemoryManager) ContentSpecNode
  802. (
  803. ContentSpecNode::Sequence
  804. , retNode
  805. , optional
  806. , true
  807. , false
  808. , fMemoryManager
  809. );
  810. }
  811. }
  812. }
  813. }
  814. return retNode;
  815. }
  816. void ComplexTypeInfo::resizeContentSpecOrgURI() {
  817. unsigned int newSize = fContentSpecOrgURISize * 2;
  818. unsigned int* newContentSpecOrgURI = (unsigned int*) fMemoryManager->allocate
  819. (
  820. newSize * sizeof(unsigned int)
  821. ); //new unsigned int[newSize];
  822. // Copy the existing values
  823. unsigned int index = 0;
  824. for (; index < fContentSpecOrgURISize; index++)
  825. newContentSpecOrgURI[index] = fContentSpecOrgURI[index];
  826. for (; index < newSize; index++)
  827. newContentSpecOrgURI[index] = 0;
  828. // Delete the old array and udpate our members
  829. fMemoryManager->deallocate(fContentSpecOrgURI); //delete [] fContentSpecOrgURI;
  830. fContentSpecOrgURI = newContentSpecOrgURI;
  831. fContentSpecOrgURISize = newSize;
  832. }
  833. /***
  834. * Support for Serialization/De-serialization
  835. ***/
  836. IMPL_XSERIALIZABLE_TOCREATE(ComplexTypeInfo)
  837. void ComplexTypeInfo::serialize(XSerializeEngine& serEng)
  838. {
  839. if (serEng.isStoring())
  840. {
  841. serEng<<fAnonymous;
  842. serEng<<fAbstract;
  843. serEng<<fAdoptContentSpec;
  844. serEng<<fAttWithTypeId;
  845. serEng<<fPreprocessed;
  846. serEng<<fDerivedBy;
  847. serEng<<fBlockSet;
  848. serEng<<fFinalSet;
  849. serEng<<fScopeDefined;
  850. serEng<<fElementId;
  851. serEng<<fContentType;
  852. serEng.writeString(fTypeName);
  853. serEng.writeString(fTypeLocalName);
  854. serEng.writeString(fTypeUri);
  855. DatatypeValidator::storeDV(serEng, fBaseDatatypeValidator);
  856. DatatypeValidator::storeDV(serEng, fDatatypeValidator);
  857. serEng<<fBaseComplexTypeInfo;
  858. serEng<<fContentSpec;
  859. // we need to save a flag to specify
  860. // if this content spce has been expanded or not
  861. if (fContentModel)
  862. serEng<<true;
  863. else
  864. serEng<<false;
  865. serEng<<fAttWildCard;
  866. serEng<<fAttList;
  867. /***
  868. *
  869. * Serialize RefVectorOf<SchemaElementDecl>* fElements;
  870. * Serialize RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
  871. ***/
  872. XTemplateSerializer::storeObject(fElements, serEng);
  873. XTemplateSerializer::storeObject(fAttDefs, serEng);
  874. /***
  875. * Don't serialize
  876. *
  877. * fContentModel;
  878. * fFormattedModel;
  879. * fLocator;
  880. * fSpecNodesToDelete
  881. *
  882. * fContentSpecOrgURI: start of the array
  883. * fContentSpecOrgURISize: size of the array
  884. * fUniqueURI: the current last element in the array
  885. ***/
  886. }
  887. else
  888. {
  889. serEng>>fAnonymous;
  890. serEng>>fAbstract;
  891. serEng>>fAdoptContentSpec;
  892. serEng>>fAttWithTypeId;
  893. serEng>>fPreprocessed;
  894. serEng>>fDerivedBy;
  895. serEng>>fBlockSet;
  896. serEng>>fFinalSet;
  897. serEng>>fScopeDefined;
  898. serEng>>fElementId;
  899. serEng>>fContentType;
  900. serEng.readString(fTypeName);
  901. serEng.readString(fTypeLocalName);
  902. serEng.readString(fTypeUri);
  903. fBaseDatatypeValidator = DatatypeValidator::loadDV(serEng);
  904. fDatatypeValidator = DatatypeValidator::loadDV(serEng);
  905. serEng>>fBaseComplexTypeInfo;
  906. serEng>>fContentSpec;
  907. //read the expanded flag
  908. bool expanded = false;
  909. serEng>>expanded;
  910. if (expanded)
  911. {
  912. fContentModel = buildContentModel(fContentSpec);
  913. }
  914. //else
  915. // if contentSpec has NOT been expanded yet,
  916. // leave the building to makeContentModel
  917. serEng>>fAttWildCard;
  918. serEng>>fAttList;
  919. /***
  920. *
  921. * Deserialize RefVectorOf<SchemaElementDecl>* fElements;
  922. * Deserialize RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
  923. ***/
  924. XTemplateSerializer::loadObject(&fElements, 8, false, serEng);
  925. XTemplateSerializer::loadObject(&fAttDefs, 29, true, serEng);
  926. /***
  927. * Don't deserialize
  928. *
  929. * fFormattedModel;
  930. * fLocator;
  931. * fSpecNodesToDelete
  932. *
  933. * fContentSpecOrgURI: start of the array
  934. * fContentSpecOrgURISize: size of the array
  935. * fUniqueURI: the current last element in the array
  936. ***/
  937. fFormattedModel = 0;
  938. fLocator = 0;
  939. fSpecNodesToDelete = 0;
  940. fContentSpecOrgURI = 0;
  941. fContentSpecOrgURISize = 0;
  942. fUniqueURI = 0;
  943. }
  944. }
  945. XERCES_CPP_NAMESPACE_END
  946. /**
  947. * End of file ComplexTypeInfo.cpp
  948. */