PageRenderTime 52ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/ATF2/control-software/epics-3.14.8/extensions/src/ChannelArchiver/ThirdParty/xerces-c-src2_4_0/src/xercesc/internal/XSObjectFactory.cpp

http://atf2flightsim.googlecode.com/
C++ | 946 lines | 720 code | 103 blank | 123 comment | 144 complexity | 1681f67bf7d4cbda1bfee39084a693f1 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) 2003 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) 2001, 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: XSObjectFactory.cpp,v $
  58. * Revision 1.1.1.1 2009/03/14 06:42:20 whitegr
  59. * epics channel archiver
  60. *
  61. * Revision 1.8 2003/12/01 20:41:25 neilg
  62. * fix for infinite loop between XSComplexTypeDefinitions and XSElementDeclarations; from David Cargill
  63. *
  64. * Revision 1.7 2003/11/27 16:42:00 neilg
  65. * fixes for segfaults and infinite loops in schema component model implementation; thanks to David Cargill
  66. *
  67. * Revision 1.6 2003/11/25 17:50:15 knoaman
  68. * Fix AIX linking error
  69. *
  70. * Revision 1.5 2003/11/24 15:45:36 knoaman
  71. * PSVI: finish construction of XSSimpleTypeDefinition
  72. *
  73. * Revision 1.4 2003/11/23 16:49:26 knoaman
  74. * PSVI: create local elements of groups
  75. *
  76. * Revision 1.3 2003/11/23 16:21:40 knoaman
  77. * PSVI: create local elements of complex types
  78. *
  79. * Revision 1.2 2003/11/21 22:34:46 neilg
  80. * More schema component model implementation, thanks to David Cargill.
  81. * In particular, this cleans up and completes the XSModel, XSNamespaceItem,
  82. * XSAttributeDeclaration and XSAttributeGroup implementations.
  83. *
  84. * Revision 1.1 2003/11/21 17:11:24 knoaman
  85. * Initial revision
  86. *
  87. */
  88. // ---------------------------------------------------------------------------
  89. // Includes
  90. // ---------------------------------------------------------------------------
  91. #include <xercesc/internal/XSObjectFactory.hpp>
  92. #include <xercesc/framework/psvi/XSModel.hpp>
  93. #include <xercesc/framework/psvi/XSParticle.hpp>
  94. #include <xercesc/framework/psvi/XSModelGroup.hpp>
  95. #include <xercesc/framework/psvi/XSElementDeclaration.hpp>
  96. #include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
  97. #include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
  98. #include <xercesc/framework/psvi/XSModelGroupDefinition.hpp>
  99. #include <xercesc/framework/psvi/XSAttributeGroupDefinition.hpp>
  100. #include <xercesc/framework/psvi/XSWildcard.hpp>
  101. #include <xercesc/framework/psvi/XSNamespaceItem.hpp>
  102. #include <xercesc/framework/psvi/XSIDCDefinition.hpp>
  103. #include <xercesc/framework/psvi/XSAttributeUse.hpp>
  104. #include <xercesc/framework/psvi/XSAttributeDeclaration.hpp>
  105. #include <xercesc/framework/psvi/XSNotationDeclaration.hpp>
  106. #include <xercesc/framework/psvi/XSFacet.hpp>
  107. #include <xercesc/framework/psvi/XSMultiValueFacet.hpp>
  108. #include <xercesc/validators/common/ContentSpecNode.hpp>
  109. #include <xercesc/validators/datatype/DatatypeValidator.hpp>
  110. #include <xercesc/validators/schema/SchemaAttDefList.hpp>
  111. #include <xercesc/validators/schema/SchemaGrammar.hpp>
  112. #include <xercesc/validators/schema/XercesGroupInfo.hpp>
  113. #include <xercesc/validators/schema/XercesAttGroupInfo.hpp>
  114. #include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
  115. #include <xercesc/validators/schema/identity/IC_KeyRef.hpp>
  116. #include <xercesc/validators/schema/identity/XercesXPath.hpp>
  117. #include <xercesc/util/HashPtr.hpp>
  118. #include <xercesc/util/XMLStringTokenizer.hpp>
  119. XERCES_CPP_NAMESPACE_BEGIN
  120. // ---------------------------------------------------------------------------
  121. // XSObjectFactory: Constructors and Destructor
  122. // ---------------------------------------------------------------------------
  123. XSObjectFactory::XSObjectFactory(MemoryManager* const manager)
  124. : fMemoryManager(manager)
  125. , fXercesToXSMap(0)
  126. , fDeleteVector(0)
  127. {
  128. fDeleteVector = new (manager) RefVectorOf<XSObject>(20, true, manager);
  129. fXercesToXSMap = new (manager) RefHashTableOf<XSObject> (
  130. 109, false, new (manager) HashPtr(), manager);
  131. }
  132. XSObjectFactory::~XSObjectFactory()
  133. {
  134. delete fXercesToXSMap;
  135. delete fDeleteVector;
  136. }
  137. // ---------------------------------------------------------------------------
  138. // XSObjectFactory: factory methods
  139. // ---------------------------------------------------------------------------
  140. XSParticle*
  141. XSObjectFactory::createModelGroupParticle(const ContentSpecNode* const rootNode,
  142. XSModel* const xsModel)
  143. {
  144. ContentSpecNode::NodeTypes nodeType = rootNode->getType();
  145. if (nodeType == ContentSpecNode::All
  146. || nodeType == ContentSpecNode::ModelGroupChoice
  147. || nodeType == ContentSpecNode::ModelGroupSequence)
  148. {
  149. XSParticleList* particleList = new (fMemoryManager) RefVectorOf<XSParticle> (4, true, fMemoryManager);
  150. XSAnnotation* annot = getAnnotationFromModel(xsModel, rootNode);
  151. XSModelGroup* modelGroup = 0;
  152. if (nodeType == ContentSpecNode::All)
  153. {
  154. modelGroup = new (fMemoryManager) XSModelGroup(XSModelGroup::COMPOSITOR_ALL, particleList, annot, xsModel, fMemoryManager);
  155. buildAllParticles(rootNode, particleList, xsModel);
  156. }
  157. else
  158. {
  159. if (nodeType == ContentSpecNode::ModelGroupChoice)
  160. modelGroup = new (fMemoryManager) XSModelGroup(XSModelGroup::COMPOSITOR_CHOICE, particleList, annot, xsModel, fMemoryManager);
  161. else
  162. modelGroup = new (fMemoryManager) XSModelGroup(XSModelGroup::COMPOSITOR_SEQUENCE, particleList, annot, xsModel, fMemoryManager);
  163. buildChoiceSequenceParticles(rootNode->getFirst(), particleList, xsModel);
  164. buildChoiceSequenceParticles(rootNode->getSecond(), particleList, xsModel);
  165. }
  166. XSParticle* groupParticle = new (fMemoryManager) XSParticle
  167. (
  168. XSParticle::TERM_MODELGROUP
  169. , xsModel
  170. , modelGroup
  171. , rootNode->getMinOccurs()
  172. , rootNode->getMaxOccurs()
  173. , fMemoryManager
  174. );
  175. return groupParticle;
  176. }
  177. else
  178. return 0;
  179. }
  180. void XSObjectFactory::buildAllParticles(const ContentSpecNode* const rootNode,
  181. XSParticleList* const particleList,
  182. XSModel* const xsModel)
  183. {
  184. // Get the type of spec node our current node is
  185. const ContentSpecNode::NodeTypes nodeType = rootNode->getType();
  186. if (nodeType == ContentSpecNode::All)
  187. {
  188. const ContentSpecNode* rightNode = rootNode->getSecond();
  189. buildAllParticles(rootNode->getFirst(), particleList, xsModel);
  190. if (rightNode)
  191. buildAllParticles(rightNode, particleList, xsModel);
  192. }
  193. else if (nodeType == ContentSpecNode::Leaf)
  194. {
  195. XSParticle* elemParticle = createElementParticle(rootNode, xsModel);
  196. if (elemParticle)
  197. particleList->addElement(elemParticle);
  198. }
  199. }
  200. void XSObjectFactory::buildChoiceSequenceParticles(const ContentSpecNode* const rootNode,
  201. XSParticleList* const particleList,
  202. XSModel* const xsModel)
  203. {
  204. if (rootNode)
  205. {
  206. const ContentSpecNode::NodeTypes nodeType = rootNode->getType();
  207. if (nodeType == ContentSpecNode::Sequence)
  208. {
  209. buildChoiceSequenceParticles(rootNode->getFirst(), particleList, xsModel);
  210. buildChoiceSequenceParticles(rootNode->getSecond(), particleList, xsModel);
  211. }
  212. else if (nodeType == ContentSpecNode::Choice)
  213. {
  214. buildChoiceSequenceParticles(rootNode->getFirst(), particleList, xsModel);
  215. buildChoiceSequenceParticles(rootNode->getSecond(), particleList, xsModel);
  216. }
  217. else if ((nodeType & 0x0f) == ContentSpecNode::Any
  218. || (nodeType & 0x0f) == ContentSpecNode::Any_Other
  219. || (nodeType & 0x0f) == ContentSpecNode::Any_NS
  220. || nodeType == ContentSpecNode::Any_NS_Choice)
  221. {
  222. XSParticle* wildcardParticle = createWildcardParticle(rootNode, xsModel);
  223. if (wildcardParticle)
  224. particleList->addElement(wildcardParticle);
  225. }
  226. else if (nodeType == ContentSpecNode::Leaf)
  227. {
  228. XSParticle* elemParticle = createElementParticle(rootNode, xsModel);
  229. if (elemParticle)
  230. particleList->addElement(elemParticle);
  231. }
  232. // must be a model group
  233. else
  234. {
  235. XSParticle* xsParticle = createModelGroupParticle(rootNode, xsModel);
  236. if (xsParticle)
  237. particleList->addElement(xsParticle);
  238. }
  239. }
  240. }
  241. XSParticle*
  242. XSObjectFactory::createElementParticle(const ContentSpecNode* const rootNode,
  243. XSModel* const xsModel)
  244. {
  245. if (rootNode->getElementDecl())
  246. {
  247. XSElementDeclaration* xsElemDecl = addOrFind(
  248. (SchemaElementDecl*) rootNode->getElementDecl(), xsModel);
  249. if (xsElemDecl)
  250. {
  251. XSParticle* particle = new (fMemoryManager) XSParticle
  252. (
  253. XSParticle::TERM_ELEMENT
  254. , xsModel
  255. , xsElemDecl
  256. , rootNode->getMinOccurs()
  257. , rootNode->getMaxOccurs()
  258. , fMemoryManager
  259. );
  260. return particle;
  261. }
  262. }
  263. return 0;
  264. }
  265. XSParticle*
  266. XSObjectFactory::createWildcardParticle(const ContentSpecNode* const rootNode,
  267. XSModel* const xsModel)
  268. {
  269. XSWildcard* xsWildcard = createXSWildcard(rootNode, xsModel);
  270. if (xsWildcard)
  271. {
  272. XSParticle* particle = new (fMemoryManager) XSParticle
  273. (
  274. XSParticle::TERM_WILDCARD
  275. , xsModel
  276. , xsWildcard
  277. , rootNode->getMinOccurs()
  278. , rootNode->getMaxOccurs()
  279. , fMemoryManager
  280. );
  281. return particle;
  282. }
  283. return 0;
  284. }
  285. XSAttributeDeclaration* XSObjectFactory::addOrFind(SchemaAttDef* const attDef,
  286. XSModel* const xsModel)
  287. {
  288. XSAttributeDeclaration* xsObj = (XSAttributeDeclaration*) getObjectFromMap(attDef, xsModel);
  289. if (!xsObj)
  290. {
  291. XSSimpleTypeDefinition* xsType = 0;
  292. if (attDef->getDatatypeValidator())
  293. xsType = addOrFind(attDef->getDatatypeValidator(), xsModel);
  294. // need grammar to determine if scope is global:
  295. XSConstants::SCOPE scope = XSConstants::SCOPE_ABSENT;
  296. XSComplexTypeDefinition* enclosingCTDefinition = 0;
  297. XSNamespaceItem* namespaceItem = xsModel->getNamespaceItem(xsModel->getURIStringPool()->getValueForId(attDef->getAttName()->getURI()));
  298. if (namespaceItem)
  299. {
  300. // REVISIT: what if local name and global name are the same???
  301. if (namespaceItem->getSchemaGrammar()->getAttributeDeclRegistry()->get(attDef))
  302. scope = XSConstants::SCOPE_GLOBAL;
  303. else if (attDef->getEnclosingCT())
  304. {
  305. scope = XSConstants::SCOPE_LOCAL;
  306. enclosingCTDefinition = addOrFind(attDef->getEnclosingCT(), xsModel);
  307. }
  308. }
  309. xsObj = new (fMemoryManager) XSAttributeDeclaration
  310. (
  311. attDef
  312. , xsType
  313. , getAnnotationFromModel(xsModel, attDef)
  314. , xsModel
  315. , scope
  316. , enclosingCTDefinition
  317. , fMemoryManager
  318. );
  319. putObjectInMap(attDef, xsObj, xsModel);
  320. }
  321. return xsObj;
  322. }
  323. XSSimpleTypeDefinition*
  324. XSObjectFactory::addOrFind(DatatypeValidator* const validator,
  325. XSModel* const xsModel)
  326. {
  327. XSSimpleTypeDefinition* xsObj = (XSSimpleTypeDefinition*) getObjectFromMap(validator, xsModel);
  328. if (!xsObj)
  329. {
  330. XSSimpleTypeDefinition* baseType = 0;
  331. XSSimpleTypeDefinitionList* memberTypes = 0;
  332. XSSimpleTypeDefinition* primitiveOrItemType = 0;
  333. XSSimpleTypeDefinition::VARIETY typeVariety = XSSimpleTypeDefinition::VARIETY_ATOMIC;
  334. // compute fBaseType
  335. DatatypeValidator* baseDV = validator->getBaseValidator();
  336. if (baseDV)
  337. baseType = addOrFind(baseDV, xsModel);
  338. //REVISIT: the getFixed method is protected so added friend XSObjectFactory
  339. // to DatatypeValidator class...
  340. DatatypeValidator::ValidatorType dvType = validator->getType();
  341. if (dvType == DatatypeValidator::Union)
  342. {
  343. typeVariety = XSSimpleTypeDefinition::VARIETY_UNION;
  344. RefVectorOf<DatatypeValidator>* membersDV = ((UnionDatatypeValidator*)validator)->getMemberTypeValidators();
  345. unsigned int size = membersDV->size();
  346. if (size)
  347. {
  348. memberTypes = new (fMemoryManager) RefVectorOf<XSSimpleTypeDefinition>(size, false, fMemoryManager);
  349. for (unsigned int i=0; i<size; i++)
  350. memberTypes->addElement(addOrFind(membersDV->elementAt(i), xsModel));
  351. }
  352. }
  353. else if (dvType == DatatypeValidator::List)
  354. {
  355. typeVariety = XSSimpleTypeDefinition::VARIETY_LIST;
  356. while (baseDV->getType() == DatatypeValidator::List)
  357. {
  358. addOrFind(baseDV, xsModel);
  359. baseDV = baseDV->getBaseValidator();
  360. }
  361. primitiveOrItemType = addOrFind(baseDV, xsModel);
  362. }
  363. else
  364. {
  365. // REVISIT: assume ATOMIC but what about VARIETY_ABSENT?
  366. while (baseDV)
  367. {
  368. primitiveOrItemType = addOrFind(baseDV, xsModel);
  369. baseDV = baseDV->getBaseValidator();
  370. }
  371. }
  372. xsObj = new (fMemoryManager) XSSimpleTypeDefinition
  373. (
  374. validator
  375. , typeVariety
  376. , baseType
  377. , primitiveOrItemType
  378. , memberTypes
  379. , getAnnotationFromModel(xsModel, validator)
  380. , xsModel
  381. , fMemoryManager
  382. );
  383. putObjectInMap(validator, xsObj, xsModel);
  384. // process facets
  385. if (validator->getFacetsDefined())
  386. processFacets(validator, xsModel, xsObj);
  387. }
  388. return xsObj;
  389. }
  390. XSElementDeclaration*
  391. XSObjectFactory::addOrFind(SchemaElementDecl* const elemDecl,
  392. XSModel* const xsModel,
  393. XSComplexTypeDefinition* const enclosingTypeDef)
  394. {
  395. XSElementDeclaration* xsObj = (XSElementDeclaration*) getObjectFromMap(elemDecl, xsModel);
  396. if (!xsObj)
  397. {
  398. XSElementDeclaration* xsSubElem = 0;
  399. XSTypeDefinition* xsType = 0;
  400. XSNamedMap<XSIDCDefinition>* icMap = 0;
  401. if (elemDecl->getSubstitutionGroupElem())
  402. xsSubElem = addOrFind(elemDecl->getSubstitutionGroupElem(), xsModel);
  403. // defer checking for complextypeinfo until later as it could
  404. // eventually need this elemement
  405. if (elemDecl->getDatatypeValidator())
  406. xsType = addOrFind(elemDecl->getDatatypeValidator(), xsModel);
  407. unsigned int count = elemDecl->getIdentityConstraintCount();
  408. if (count)
  409. {
  410. //REVISIT: size of hash table....
  411. icMap = new (fMemoryManager) XSNamedMap<XSIDCDefinition>
  412. (
  413. count
  414. , 29
  415. , xsModel->getURIStringPool()
  416. , false
  417. , fMemoryManager
  418. );
  419. for (unsigned int i = 0; i < count; i++)
  420. {
  421. XSIDCDefinition* icDef = addOrFind
  422. (
  423. elemDecl->getIdentityConstraintAt(i)
  424. , xsModel
  425. );
  426. if (icDef)
  427. {
  428. icMap->addElement
  429. (
  430. icDef
  431. , icDef->getName()
  432. , icDef->getNamespace()
  433. );
  434. }
  435. }
  436. }
  437. XSConstants::SCOPE elemScope = XSConstants::SCOPE_ABSENT;
  438. if (enclosingTypeDef)
  439. elemScope = XSConstants::SCOPE_LOCAL;
  440. else if (elemDecl->getEnclosingScope() == Grammar::TOP_LEVEL_SCOPE)
  441. elemScope = XSConstants::SCOPE_GLOBAL;
  442. xsObj = new (fMemoryManager) XSElementDeclaration
  443. (
  444. elemDecl
  445. , xsType
  446. , xsSubElem
  447. , getAnnotationFromModel(xsModel, elemDecl)
  448. , icMap
  449. , xsModel
  450. , elemScope
  451. , enclosingTypeDef
  452. , fMemoryManager
  453. );
  454. putObjectInMap(elemDecl, xsObj, xsModel);
  455. if (!xsType && elemDecl->getComplexTypeInfo())
  456. {
  457. xsType = addOrFind(elemDecl->getComplexTypeInfo(), xsModel);
  458. xsObj->setTypeDefinition(xsType);
  459. }
  460. }
  461. return xsObj;
  462. }
  463. XSComplexTypeDefinition*
  464. XSObjectFactory::addOrFind(ComplexTypeInfo* const typeInfo,
  465. XSModel* const xsModel)
  466. {
  467. XSComplexTypeDefinition* xsObj = (XSComplexTypeDefinition*) getObjectFromMap(typeInfo, xsModel);
  468. if (!xsObj)
  469. {
  470. XSWildcard* xsWildcard = 0;
  471. XSSimpleTypeDefinition* xsSimpleType = 0;
  472. XSAttributeUseList* xsAttList = 0;
  473. XSTypeDefinition* xsBaseType = 0;
  474. XSParticle* xsParticle = 0;
  475. if (typeInfo->getAttWildCard())
  476. xsWildcard = createXSWildcard(typeInfo->getAttWildCard(), xsModel);
  477. if ((typeInfo->getContentType() == SchemaElementDecl::Simple) &&
  478. (typeInfo->getDatatypeValidator()))
  479. xsSimpleType = addOrFind(typeInfo->getDatatypeValidator(), xsModel);
  480. unsigned int attCount;
  481. if (typeInfo->hasAttDefs())
  482. {
  483. SchemaAttDefList& attDefList = (SchemaAttDefList&) typeInfo->getAttDefList();
  484. attCount = attDefList.getAttDefCount();
  485. xsAttList = new (fMemoryManager) RefVectorOf<XSAttributeUse>(attCount, false, fMemoryManager);
  486. // create list now put fill it in after we put complextype into map
  487. // otherwise we may encounter an infinite loop: complextype needs to
  488. // addorfind attdef, which does an addorfind on the enclosingCTdefintion.
  489. }
  490. // compute fBase
  491. if (typeInfo->getBaseComplexTypeInfo())
  492. xsBaseType = addOrFind(typeInfo->getBaseComplexTypeInfo(), xsModel);
  493. else if (typeInfo->getBaseDatatypeValidator())
  494. xsBaseType = addOrFind(typeInfo->getBaseDatatypeValidator(), xsModel);
  495. // compute particle
  496. ContentSpecNode* contentSpec = typeInfo->getContentSpec();
  497. if (contentSpec)
  498. xsParticle = createModelGroupParticle(contentSpec, xsModel);
  499. xsObj = new (fMemoryManager) XSComplexTypeDefinition
  500. (
  501. typeInfo
  502. , xsWildcard
  503. , xsSimpleType
  504. , xsAttList
  505. , xsBaseType
  506. , xsParticle
  507. , getAnnotationFromModel(xsModel, typeInfo)
  508. , xsModel
  509. , fMemoryManager
  510. );
  511. putObjectInMap(typeInfo, xsObj, xsModel);
  512. if (typeInfo->hasAttDefs())
  513. {
  514. // now create the xsattributedeclarations...
  515. SchemaAttDefList& attDefList = (SchemaAttDefList&) typeInfo->getAttDefList();
  516. for(unsigned int i=0; i<attCount; i++)
  517. {
  518. SchemaAttDef& attDef = (SchemaAttDef&) attDefList.getAttDef(i);
  519. XSAttributeDeclaration* xsAttDecl = addOrFind(&attDef, xsModel);
  520. XSAttributeUse* attUse = createXSAttributeUse(xsAttDecl, xsModel);
  521. xsAttList->addElement(attUse);
  522. }
  523. }
  524. // process local elements
  525. unsigned int elemCount = typeInfo->elementCount();
  526. for (unsigned int j=0; j<elemCount; j++)
  527. {
  528. SchemaElementDecl* elemDecl = typeInfo->elementAt(j);
  529. if (elemDecl->getEnclosingScope() == typeInfo->getScopeDefined())
  530. addOrFind(elemDecl, xsModel, xsObj);
  531. }
  532. }
  533. return xsObj;
  534. }
  535. XSIDCDefinition* XSObjectFactory::addOrFind(IdentityConstraint* const ic,
  536. XSModel* const xsModel)
  537. {
  538. XSIDCDefinition* xsObj = (XSIDCDefinition*) getObjectFromMap(ic, xsModel);
  539. if (!xsObj)
  540. {
  541. XSIDCDefinition* keyIC = 0;
  542. StringList* stringList = 0;
  543. unsigned int fieldCount = ic->getFieldCount();
  544. if (fieldCount)
  545. {
  546. stringList = new (fMemoryManager) RefArrayVectorOf<XMLCh>(
  547. fieldCount, true, fMemoryManager);
  548. for(unsigned int i=0; i<fieldCount; i++)
  549. {
  550. XMLCh* expr = XMLString::replicate
  551. (
  552. ic->getFieldAt(i)->getXPath()->getExpression()
  553. , fMemoryManager
  554. );
  555. stringList->addElement(expr);
  556. }
  557. }
  558. if (ic->getType() == IdentityConstraint::KEYREF)
  559. keyIC = addOrFind(((IC_KeyRef*) ic)->getKey(), xsModel);
  560. xsObj= new (fMemoryManager) XSIDCDefinition
  561. (
  562. ic
  563. , keyIC
  564. , getAnnotationFromModel(xsModel, ic)
  565. , stringList
  566. , xsModel
  567. , fMemoryManager
  568. );
  569. putObjectInMap(ic, xsObj, xsModel);
  570. }
  571. return xsObj;
  572. }
  573. XSNotationDeclaration* XSObjectFactory::addOrFind(XMLNotationDecl* const notDecl,
  574. XSModel* const xsModel)
  575. {
  576. XSNotationDeclaration* xsObj = (XSNotationDeclaration*) getObjectFromMap(notDecl, xsModel);
  577. if (!xsObj)
  578. {
  579. xsObj = new (fMemoryManager) XSNotationDeclaration
  580. (
  581. notDecl
  582. , getAnnotationFromModel(xsModel, notDecl)
  583. , xsModel
  584. , fMemoryManager
  585. );
  586. putObjectInMap(notDecl, xsObj, xsModel);
  587. }
  588. return xsObj;
  589. }
  590. XSAttributeUse*
  591. XSObjectFactory::createXSAttributeUse(XSAttributeDeclaration* const xsAttDecl,
  592. XSModel* const xsModel)
  593. {
  594. XSAttributeUse* attrUse = new (fMemoryManager) XSAttributeUse(xsAttDecl, xsModel, fMemoryManager);
  595. fDeleteVector->addElement(attrUse);
  596. return attrUse;
  597. }
  598. XSWildcard*
  599. XSObjectFactory::createXSWildcard(SchemaAttDef* const attDef,
  600. XSModel* const xsModel)
  601. {
  602. XSWildcard* xsWildcard = new (fMemoryManager) XSWildcard
  603. (
  604. attDef
  605. , getAnnotationFromModel(xsModel, attDef)
  606. , xsModel
  607. , fMemoryManager
  608. );
  609. fDeleteVector->addElement(xsWildcard);
  610. return xsWildcard;
  611. }
  612. XSWildcard*
  613. XSObjectFactory::createXSWildcard(const ContentSpecNode* const rootNode,
  614. XSModel* const xsModel)
  615. {
  616. XSWildcard* xsWildcard = new (fMemoryManager) XSWildcard
  617. (
  618. rootNode
  619. , getAnnotationFromModel(xsModel, rootNode)
  620. , xsModel
  621. , fMemoryManager
  622. );
  623. fDeleteVector->addElement(xsWildcard);
  624. return xsWildcard;
  625. }
  626. XSModelGroupDefinition*
  627. XSObjectFactory::createXSModelGroupDefinition(XercesGroupInfo* const groupInfo,
  628. XSModel* const xsModel)
  629. {
  630. XSParticle* particle = createModelGroupParticle(
  631. groupInfo->getContentSpec(), xsModel);
  632. XSModelGroupDefinition* xsObj = new (fMemoryManager) XSModelGroupDefinition
  633. (
  634. groupInfo
  635. , particle
  636. , getAnnotationFromModel(xsModel, groupInfo)
  637. , xsModel
  638. , fMemoryManager
  639. );
  640. fDeleteVector->addElement(xsObj);
  641. // process local elements
  642. unsigned int elemCount = groupInfo->elementCount();
  643. for (unsigned int j=0; j<elemCount; j++)
  644. {
  645. SchemaElementDecl* elemDecl = groupInfo->elementAt(j);
  646. if (elemDecl->getEnclosingScope() == groupInfo->getScope())
  647. addOrFind(elemDecl, xsModel);
  648. }
  649. return xsObj;
  650. }
  651. XSAttributeGroupDefinition*
  652. XSObjectFactory::createXSAttGroupDefinition(XercesAttGroupInfo* const attGroupInfo,
  653. XSModel* const xsModel)
  654. {
  655. XSAttributeUseList* xsAttList = 0;
  656. XSWildcard* xsWildcard = 0;
  657. unsigned int attCount = attGroupInfo->attributeCount();
  658. if (attCount)
  659. {
  660. xsAttList = new (fMemoryManager) RefVectorOf<XSAttributeUse>(attCount, false, fMemoryManager);
  661. for (unsigned int i=0; i < attCount; i++)
  662. {
  663. XSAttributeDeclaration* xsAttDecl = addOrFind(attGroupInfo->attributeAt(i), xsModel);
  664. if (xsAttDecl) // just for sanity
  665. {
  666. XSAttributeUse* attUse = createXSAttributeUse(xsAttDecl, xsModel);
  667. xsAttList->addElement(attUse);
  668. }
  669. }
  670. }
  671. if (attGroupInfo->getCompleteWildCard())
  672. xsWildcard = createXSWildcard(attGroupInfo->getCompleteWildCard(), xsModel);
  673. XSAttributeGroupDefinition* xsObj = new (fMemoryManager) XSAttributeGroupDefinition
  674. (
  675. attGroupInfo
  676. , xsAttList
  677. , xsWildcard
  678. , getAnnotationFromModel(xsModel, attGroupInfo)
  679. , xsModel
  680. , fMemoryManager
  681. );
  682. fDeleteVector->addElement(xsObj);
  683. return xsObj;
  684. }
  685. XSAnnotation* XSObjectFactory::getAnnotationFromModel(XSModel* const xsModel,
  686. const void* const key)
  687. {
  688. XSNamespaceItemList* namespaceItemList = xsModel->getNamespaceItems();
  689. XSAnnotation* annot = 0;
  690. for (unsigned int i=0; i<namespaceItemList->size(); i++)
  691. {
  692. annot = namespaceItemList->elementAt(i)->getSchemaGrammar()->getAnnotation(key);
  693. if (annot)
  694. return annot;
  695. }
  696. if (xsModel->fParent)
  697. return getAnnotationFromModel(xsModel->fParent, key);
  698. return 0;
  699. }
  700. XSObject* XSObjectFactory::getObjectFromMap(void* key, XSModel* const xsModel)
  701. {
  702. XSObject* xsObj = fXercesToXSMap->get(key);
  703. if (xsObj)
  704. return xsObj;
  705. if (xsModel->fParent)
  706. return getObjectFromMap(key, xsModel->fParent);
  707. return 0;
  708. }
  709. void XSObjectFactory::putObjectInMap(void* key, XSObject* const object, XSModel* const xsModel)
  710. {
  711. fXercesToXSMap->put(key, object);
  712. fDeleteVector->addElement(object);
  713. }
  714. void XSObjectFactory::processFacets(DatatypeValidator* const dv,
  715. XSModel* const xsModel,
  716. XSSimpleTypeDefinition* const xsST)
  717. {
  718. // NOTE: XSMultiValueFacetList is not owned by XSModel!
  719. // NOTE: XSFacetList is not owned by XSModel!
  720. int definedFacets = 0;
  721. int fixedFacets = 0;
  722. XSFacetList* xsFacetList = 0;
  723. XSMultiValueFacetList* xsMultiFacetList = 0;
  724. StringList* patternList = 0;
  725. bool isFixed = false;
  726. int dvFacetsDefined = dv->getFacetsDefined();
  727. int dvFixedFacets = dv->getFixed();
  728. if ((dvFacetsDefined & DatatypeValidator::FACET_PATTERN)
  729. || (dvFacetsDefined & DatatypeValidator::FACET_ENUMERATION))
  730. xsMultiFacetList = new (fMemoryManager) RefVectorOf<XSMultiValueFacet>(2, true, fMemoryManager);
  731. if (dvFacetsDefined & DatatypeValidator::FACET_ENUMERATION)
  732. {
  733. RefArrayVectorOf<XMLCh>* enumList = (RefArrayVectorOf<XMLCh>*) dv->getEnumString();
  734. isFixed = ((dvFixedFacets & DatatypeValidator::FACET_ENUMERATION) != 0);
  735. // NOTE: Don't need to add multivaluefacet to "ObjectMap -> getObjectFromMap/putObjectInMap);
  736. xsMultiFacetList->addElement(
  737. new (fMemoryManager) XSMultiValueFacet(
  738. XSSimpleTypeDefinition::FACET_ENUMERATION , enumList, isFixed
  739. , getAnnotationFromModel(xsModel, enumList)
  740. , xsModel, fMemoryManager)
  741. );
  742. definedFacets |= XSSimpleTypeDefinition::FACET_ENUMERATION;
  743. if (isFixed)
  744. fixedFacets |= XSSimpleTypeDefinition::FACET_ENUMERATION;
  745. }
  746. RefHashTableOf<KVStringPair>* facets = dv->getFacets();
  747. if (facets)
  748. {
  749. xsFacetList = new (fMemoryManager) RefVectorOf<XSFacet>(10, true, fMemoryManager);
  750. // NOTE: Don't need to add facet to "ObjectMap -> getObjectFromMap/putObjectInMap);
  751. RefHashTableOfEnumerator<KVStringPair> e(facets);
  752. while (e.hasMoreElements())
  753. {
  754. KVStringPair& pair = e.nextElement();
  755. XMLCh* key = pair.getKey();
  756. XSSimpleTypeDefinition::FACET facetType = XSSimpleTypeDefinition::FACET_NONE;
  757. XSAnnotation* annot = getAnnotationFromModel(xsModel, &pair);
  758. if (XMLString::equals(key, SchemaSymbols::fgELT_MAXINCLUSIVE))
  759. {
  760. facetType = XSSimpleTypeDefinition::FACET_MAXINCLUSIVE;
  761. isFixed = ((dvFixedFacets & DatatypeValidator::FACET_MAXINCLUSIVE) != 0);
  762. }
  763. else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXEXCLUSIVE))
  764. {
  765. facetType = XSSimpleTypeDefinition::FACET_MAXEXCLUSIVE;
  766. isFixed = ((dvFixedFacets & DatatypeValidator::FACET_MAXEXCLUSIVE) !=0);
  767. }
  768. else if (XMLString::equals(key, SchemaSymbols::fgELT_MININCLUSIVE))
  769. {
  770. facetType = XSSimpleTypeDefinition::FACET_MININCLUSIVE;
  771. isFixed = ((dvFixedFacets & DatatypeValidator::FACET_MININCLUSIVE) !=0);
  772. }
  773. else if (XMLString::equals(key, SchemaSymbols::fgELT_MINEXCLUSIVE))
  774. {
  775. facetType = XSSimpleTypeDefinition::FACET_MINEXCLUSIVE;
  776. isFixed = ((dvFixedFacets & DatatypeValidator::FACET_MINEXCLUSIVE) != 0);
  777. }
  778. else if (XMLString::equals(key, SchemaSymbols::fgELT_LENGTH))
  779. {
  780. facetType = XSSimpleTypeDefinition::FACET_LENGTH;
  781. isFixed = ((dvFixedFacets & DatatypeValidator::FACET_LENGTH) != 0);
  782. }
  783. else if (XMLString::equals(key, SchemaSymbols::fgELT_MINLENGTH))
  784. {
  785. facetType = XSSimpleTypeDefinition::FACET_MINLENGTH;
  786. isFixed = ((dvFixedFacets & DatatypeValidator::FACET_MINLENGTH) != 0);
  787. }
  788. else if (XMLString::equals(key, SchemaSymbols::fgELT_MAXLENGTH))
  789. {
  790. facetType = XSSimpleTypeDefinition::FACET_MAXLENGTH;
  791. isFixed = ((dvFixedFacets & DatatypeValidator::FACET_MAXLENGTH) != 0);
  792. }
  793. else if (XMLString::equals(key, SchemaSymbols::fgELT_TOTALDIGITS))
  794. {
  795. facetType = XSSimpleTypeDefinition::FACET_TOTALDIGITS;
  796. isFixed = ((dvFixedFacets & DatatypeValidator::FACET_TOTALDIGITS) != 0);
  797. }
  798. else if (XMLString::equals(key, SchemaSymbols::fgELT_FRACTIONDIGITS))
  799. {
  800. facetType = XSSimpleTypeDefinition::FACET_FRACTIONDIGITS;
  801. isFixed = ((dvFixedFacets & DatatypeValidator::FACET_FRACTIONDIGITS) != 0);
  802. }
  803. else if (XMLString::equals(key, SchemaSymbols::fgELT_WHITESPACE))
  804. {
  805. facetType = XSSimpleTypeDefinition::FACET_WHITESPACE;
  806. isFixed = ((dvFixedFacets & DatatypeValidator::FACET_WHITESPACE) != 0);
  807. }
  808. else if (XMLString::equals(key, SchemaSymbols::fgELT_PATTERN))
  809. {
  810. XMLStringTokenizer tokenizer(dv->getPattern(), &chPipe, fMemoryManager);
  811. patternList = new (fMemoryManager) RefArrayVectorOf<XMLCh>(tokenizer.countTokens(), true, fMemoryManager);
  812. while (tokenizer.hasMoreTokens())
  813. patternList->addElement(XMLString::replicate(tokenizer.nextToken(), fMemoryManager));
  814. isFixed = ((dvFixedFacets & DatatypeValidator::FACET_PATTERN) != 0);
  815. // NOTE: Don't need to add multivaluefacet to "ObjectMap -> getObjectFromMap/putObjectInMap);
  816. xsMultiFacetList->addElement(
  817. new (fMemoryManager) XSMultiValueFacet(
  818. XSSimpleTypeDefinition::FACET_PATTERN, patternList
  819. , isFixed, annot, xsModel, fMemoryManager)
  820. );
  821. definedFacets |= XSSimpleTypeDefinition::FACET_PATTERN;
  822. if (isFixed)
  823. fixedFacets |= XSSimpleTypeDefinition::FACET_PATTERN;
  824. continue;
  825. }
  826. else
  827. {
  828. // REVISIT: hmm... what about XSSimpleTypeDefinition::FACET_NONE
  829. // don't think I need to create an empty Facet?
  830. continue;
  831. }
  832. xsFacetList->addElement(
  833. new (fMemoryManager) XSFacet(
  834. facetType, pair.getValue(), isFixed, annot, xsModel, fMemoryManager)
  835. );
  836. definedFacets |= facetType;
  837. if (isFixed)
  838. fixedFacets |= facetType;
  839. }
  840. }
  841. xsST->setFacetInfo(definedFacets, fixedFacets, xsFacetList, xsMultiFacetList, patternList);
  842. }
  843. XERCES_CPP_NAMESPACE_END