PageRenderTime 325ms CodeModel.GetById 8ms 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/SchemaElementDecl.cpp

http://atf2flightsim.googlecode.com/
C++ | 524 lines | 261 code | 67 blank | 196 comment | 17 complexity | a46714164cd78c3902108e2de03d220d 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) 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: SchemaElementDecl.cpp,v $
  58. * Revision 1.1.1.1 2009/03/14 06:43:10 whitegr
  59. * epics channel archiver
  60. *
  61. * Revision 1.15 2003/11/13 23:20:47 peiyongz
  62. * initSize
  63. *
  64. * Revision 1.14 2003/10/17 21:17:12 peiyongz
  65. * using XTemplateSerializer
  66. *
  67. * Revision 1.12 2003/10/14 15:22:28 peiyongz
  68. * Implementation of Serialization/Deserialization
  69. *
  70. * Revision 1.11 2003/10/05 02:08:05 neilg
  71. * Because it makes grammars un-sharable between parsers running on multiple threads, xsi:type should not be handled by modifying element declarations. Modifying implementation so it no longer relies on this kind of behaviour; marking methods as deprecated which imply that xsi:type will be handled in this way. Once their behaviour is handled elsewhere, these methods should eventually be removed
  72. *
  73. * Revision 1.10 2003/05/18 14:02:08 knoaman
  74. * Memory manager implementation: pass per instance manager.
  75. *
  76. * Revision 1.9 2003/05/16 21:43:21 knoaman
  77. * Memory manager implementation: Modify constructors to pass in the memory manager.
  78. *
  79. * Revision 1.8 2003/05/15 18:57:27 knoaman
  80. * Partial implementation of the configurable memory manager.
  81. *
  82. * Revision 1.7 2003/01/29 19:47:16 gareth
  83. * added DOMTypeInfo and some PSVI methods
  84. *
  85. * Revision 1.6 2002/11/04 14:49:41 tng
  86. * C++ Namespace Support.
  87. *
  88. * Revision 1.5 2002/07/12 15:17:48 knoaman
  89. * For a given global element, store info about a substitution group element
  90. * as a SchemaElementDecl and not as a string.
  91. *
  92. * Revision 1.4 2002/05/08 13:53:37 peiyongz
  93. * Bug#8898: SchemaElementDecl doesn't compile with Intel C++ for IA32,
  94. * patch from Curt Arnold
  95. *
  96. * Revision 1.3 2002/03/21 16:31:43 knoaman
  97. * Remove data/methods from SchemaElementDecl that are not used.
  98. *
  99. * Revision 1.2 2002/02/06 22:30:50 knoaman
  100. * Added a new attribute to store the wild card information for elements of type 'anyType'.
  101. *
  102. * Revision 1.1.1.1 2002/02/01 22:22:46 peiyongz
  103. * sane_include
  104. *
  105. * Revision 1.18 2002/01/02 15:20:22 tng
  106. * Schema Fix: should not store a temp value as the key in the element pool and the attribute pool.
  107. *
  108. * Revision 1.17 2001/11/02 14:13:45 knoaman
  109. * Add support for identity constraints.
  110. *
  111. * Revision 1.16 2001/10/11 12:07:39 tng
  112. * Schema: model type should be based on complextypeinfo if exists.
  113. *
  114. * Revision 1.15 2001/09/14 14:50:22 tng
  115. * Schema: Fix some wildcard bugs, and some retrieving qualified/unqualified element decl problems.
  116. *
  117. * Revision 1.14 2001/09/11 13:02:40 tng
  118. * [Bug 3523] SchemaElementDecl.cpp(242) : error C2202 : not all control paths return a value
  119. *
  120. * Revision 1.13 2001/08/29 20:52:35 tng
  121. * Schema: xsi:type support
  122. *
  123. * Revision 1.12 2001/08/21 16:06:11 tng
  124. * Schema: Unique Particle Attribution Constraint Checking.
  125. *
  126. * Revision 1.11 2001/07/24 18:33:46 knoaman
  127. * Added support for <group> + extra constraint checking for complexType
  128. *
  129. * Revision 1.10 2001/07/09 15:22:43 knoaman
  130. * complete <any> declaration.
  131. *
  132. * Revision 1.9 2001/06/13 20:51:18 peiyongz
  133. * fIsMixed: to handle mixed Content Model
  134. *
  135. * Revision 1.8 2001/05/11 13:27:35 tng
  136. * Copyright update.
  137. *
  138. * Revision 1.7 2001/05/03 20:34:42 tng
  139. * Schema: SchemaValidator update
  140. *
  141. * Revision 1.6 2001/05/03 19:17:59 knoaman
  142. * TraverseSchema Part II.
  143. *
  144. * Revision 1.5 2001/04/19 17:43:16 knoaman
  145. * More schema implementation classes.
  146. *
  147. * Revision 1.4 2001/03/21 21:56:33 tng
  148. * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
  149. *
  150. * Revision 1.3 2001/03/21 19:30:15 tng
  151. * Schema: Content Model Updates, by Pei Yong Zhang.
  152. *
  153. * Revision 1.2 2001/03/07 17:42:12 tng
  154. * fix typo
  155. *
  156. * Revision 1.1 2001/02/27 18:48:22 tng
  157. * Schema: Add SchemaAttDef, SchemaElementDecl, SchemaAttDefList.
  158. *
  159. */
  160. // ---------------------------------------------------------------------------
  161. // Includes
  162. // ---------------------------------------------------------------------------
  163. #include <xercesc/util/XMLString.hpp>
  164. #include <xercesc/util/XMLUniDefs.hpp>
  165. #include <xercesc/util/XMLUni.hpp>
  166. #include <xercesc/validators/schema/SchemaAttDefList.hpp>
  167. #include <xercesc/validators/schema/SchemaElementDecl.hpp>
  168. #include <xercesc/validators/schema/identity/IdentityConstraint.hpp>
  169. #include <xercesc/internal/XTemplateSerializer.hpp>
  170. XERCES_CPP_NAMESPACE_BEGIN
  171. // ---------------------------------------------------------------------------
  172. // SchemaElementDecl: Constructors and Destructor
  173. // ---------------------------------------------------------------------------
  174. SchemaElementDecl::SchemaElementDecl(MemoryManager* const manager) :
  175. XMLElementDecl(manager)
  176. , fModelType(Any)
  177. , fDatatypeValidator(0)
  178. , fEnclosingScope(Grammar::TOP_LEVEL_SCOPE)
  179. , fBlockSet(0)
  180. , fFinalSet(0)
  181. , fMiscFlags(0)
  182. , fDefaultValue(0)
  183. , fComplexTypeInfo(0)
  184. , fXsiComplexTypeInfo(0)
  185. , fXsiSimpleTypeInfo(0)
  186. , fAttDefs(0)
  187. , fIdentityConstraints(0)
  188. , fAttWildCard(0)
  189. , fSubstitutionGroupElem(0)
  190. , fValidity(PSVIDefs::UNKNOWN)
  191. , fValidation(PSVIDefs::NONE)
  192. , fSeenValidation(false)
  193. , fSeenNoValidation(false)
  194. , fHadContent(false)
  195. {
  196. }
  197. SchemaElementDecl::SchemaElementDecl(const XMLCh* const prefix
  198. , const XMLCh* const localPart
  199. , const int uriId
  200. , const SchemaElementDecl::ModelTypes type
  201. , const int enclosingScope
  202. , MemoryManager* const manager) :
  203. XMLElementDecl(manager)
  204. , fModelType(type)
  205. , fDatatypeValidator(0)
  206. , fEnclosingScope(enclosingScope)
  207. , fBlockSet(0)
  208. , fFinalSet(0)
  209. , fMiscFlags(0)
  210. , fDefaultValue(0)
  211. , fComplexTypeInfo(0)
  212. , fXsiComplexTypeInfo(0)
  213. , fXsiSimpleTypeInfo(0)
  214. , fAttDefs(0)
  215. , fIdentityConstraints(0)
  216. , fAttWildCard(0)
  217. , fSubstitutionGroupElem(0)
  218. , fValidity(PSVIDefs::UNKNOWN)
  219. , fValidation(PSVIDefs::NONE)
  220. , fSeenValidation(false)
  221. , fSeenNoValidation(false)
  222. , fHadContent(false)
  223. {
  224. setElementName(prefix, localPart, uriId);
  225. }
  226. SchemaElementDecl::SchemaElementDecl(const QName* const elementName
  227. , const SchemaElementDecl::ModelTypes type
  228. , const int enclosingScope
  229. , MemoryManager* const manager) :
  230. XMLElementDecl(manager)
  231. , fModelType(type)
  232. , fDatatypeValidator(0)
  233. , fEnclosingScope(enclosingScope)
  234. , fBlockSet(0)
  235. , fFinalSet(0)
  236. , fMiscFlags(0)
  237. , fDefaultValue(0)
  238. , fComplexTypeInfo(0)
  239. , fXsiComplexTypeInfo(0)
  240. , fXsiSimpleTypeInfo(0)
  241. , fAttDefs(0)
  242. , fIdentityConstraints(0)
  243. , fAttWildCard(0)
  244. , fSubstitutionGroupElem(0)
  245. , fValidity(PSVIDefs::UNKNOWN)
  246. , fValidation(PSVIDefs::NONE)
  247. , fSeenValidation(false)
  248. , fSeenNoValidation(false)
  249. , fHadContent(false)
  250. {
  251. setElementName(elementName);
  252. }
  253. SchemaElementDecl::~SchemaElementDecl()
  254. {
  255. getMemoryManager()->deallocate(fDefaultValue);//delete [] fDefaultValue;
  256. delete fAttDefs;
  257. delete fIdentityConstraints;
  258. delete fAttWildCard;
  259. }
  260. // ---------------------------------------------------------------------------
  261. // SchemaElementDecl: XMLElementDecl virtual interface implementation
  262. // ---------------------------------------------------------------------------
  263. XMLAttDef* SchemaElementDecl::findAttr(const XMLCh* const qName
  264. , const unsigned int uriId
  265. , const XMLCh* const baseName
  266. , const XMLCh* const prefix
  267. , const LookupOpts options
  268. , bool& wasAdded) const
  269. {
  270. if (fComplexTypeInfo) {
  271. return fComplexTypeInfo->findAttr(qName, uriId, baseName, prefix, options, wasAdded);
  272. }
  273. else {
  274. if (options == XMLElementDecl::AddIfNotFound) {
  275. SchemaAttDef* retVal = 0;
  276. // If no att list exist yet, then create one
  277. if (!fAttDefs) {
  278. // Use a hash modulus of 29 and tell it owns its elements
  279. ((SchemaElementDecl*)this)->fAttDefs =
  280. new (getMemoryManager()) RefHash2KeysTableOf<SchemaAttDef>(29, true, getMemoryManager());
  281. }
  282. retVal = fAttDefs->get(baseName, uriId);
  283. // Fault it in if not found and ask to add it
  284. if (!retVal)
  285. {
  286. // And add a default attribute for this name
  287. retVal = new (getMemoryManager()) SchemaAttDef
  288. (
  289. prefix
  290. , baseName
  291. , uriId
  292. , XMLAttDef::CData
  293. , XMLAttDef::Implied
  294. , getMemoryManager()
  295. );
  296. retVal->setElemId(getId());
  297. fAttDefs->put((void*)retVal->getAttName()->getLocalPart(), uriId, retVal);
  298. wasAdded = true;
  299. }
  300. else
  301. {
  302. wasAdded = false;
  303. }
  304. return retVal;
  305. }
  306. else {
  307. wasAdded = false;
  308. return 0;
  309. }
  310. }
  311. }
  312. XMLAttDefList& SchemaElementDecl::getAttDefList() const
  313. {
  314. if (!fComplexTypeInfo)
  315. {
  316. ThrowXML(RuntimeException, XMLExcepts::DV_InvalidOperation);
  317. }
  318. return fComplexTypeInfo->getAttDefList();
  319. }
  320. XMLElementDecl::CharDataOpts SchemaElementDecl::getCharDataOpts() const
  321. {
  322. SchemaElementDecl::ModelTypes modelType = fModelType;
  323. if (fComplexTypeInfo) {
  324. modelType = (SchemaElementDecl::ModelTypes) fComplexTypeInfo->getContentType();
  325. }
  326. XMLElementDecl::CharDataOpts retVal;
  327. switch(modelType)
  328. {
  329. case Children :
  330. retVal = XMLElementDecl::SpacesOk;
  331. break;
  332. case Empty :
  333. retVal = XMLElementDecl::NoCharData;
  334. break;
  335. default :
  336. retVal = XMLElementDecl::AllCharData;
  337. break;
  338. }
  339. return retVal;
  340. }
  341. bool SchemaElementDecl::hasAttDefs() const
  342. {
  343. if (fComplexTypeInfo) {
  344. return fComplexTypeInfo->hasAttDefs();
  345. }
  346. // If the collection hasn't been faulted in, then no att defs
  347. return false;
  348. }
  349. bool SchemaElementDecl::resetDefs()
  350. {
  351. if (fComplexTypeInfo) {
  352. return fComplexTypeInfo->resetDefs();
  353. }
  354. else if (fAttDefs) {
  355. //all the attdefs here are faulted-in, so just reset the fAttDefs
  356. //but still return false to indicate there is no real att defs
  357. // defined in this element
  358. fAttDefs->removeAll();
  359. }
  360. return false;
  361. }
  362. const XMLCh*
  363. SchemaElementDecl::getFormattedContentModel() const
  364. {
  365. if (fComplexTypeInfo) {
  366. return fComplexTypeInfo->getFormattedContentModel();
  367. }
  368. return 0;
  369. }
  370. // ---------------------------------------------------------------------------
  371. // SchemaElementDecl: Getter methods
  372. // ---------------------------------------------------------------------------
  373. const SchemaAttDef* SchemaElementDecl::getAttDef(const XMLCh* const baseName, const int uriId) const
  374. {
  375. if (fComplexTypeInfo) {
  376. return fComplexTypeInfo->getAttDef(baseName, uriId);
  377. }
  378. // If no complex type, then return a null
  379. return 0;
  380. }
  381. SchemaAttDef* SchemaElementDecl::getAttDef(const XMLCh* const baseName, const int uriId)
  382. {
  383. if (fComplexTypeInfo) {
  384. return fComplexTypeInfo->getAttDef(baseName, uriId);
  385. }
  386. // If no complex type, then return a null
  387. return 0;
  388. }
  389. /***
  390. * Support for Serialization/De-serialization
  391. ***/
  392. IMPL_XSERIALIZABLE_TOCREATE(SchemaElementDecl)
  393. void SchemaElementDecl::serialize(XSerializeEngine& serEng)
  394. {
  395. XMLElementDecl::serialize(serEng);
  396. if (serEng.isStoring())
  397. {
  398. serEng<<(int)fModelType;
  399. DatatypeValidator::storeDV(serEng, fDatatypeValidator);
  400. serEng<<fEnclosingScope;
  401. serEng<<fFinalSet;
  402. serEng<<fBlockSet;
  403. serEng<<fMiscFlags;
  404. serEng.writeString(fDefaultValue);
  405. serEng<<fComplexTypeInfo;
  406. /***
  407. * Serialize RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
  408. ***/
  409. XTemplateSerializer::storeObject(fAttDefs, serEng);
  410. serEng<<fXsiComplexTypeInfo;
  411. DatatypeValidator::storeDV(serEng, (DatatypeValidator*)fXsiSimpleTypeInfo);
  412. /***
  413. * Serialize RefVectorOf<IdentityConstraint>* fIdentityConstraints;
  414. ***/
  415. XTemplateSerializer::storeObject(fIdentityConstraints, serEng);
  416. serEng<<fAttWildCard;
  417. serEng<<fSubstitutionGroupElem;
  418. serEng<<(int)fValidity;
  419. serEng<<(int)fValidation;
  420. serEng<<fSeenValidation;
  421. serEng<<fSeenNoValidation;
  422. serEng<<fHadContent;
  423. }
  424. else
  425. {
  426. int i;
  427. serEng>>i;
  428. fModelType = (ModelTypes)i;
  429. fDatatypeValidator = DatatypeValidator::loadDV(serEng);
  430. serEng>>fEnclosingScope;
  431. serEng>>fFinalSet;
  432. serEng>>fBlockSet;
  433. serEng>>fMiscFlags;
  434. serEng.readString(fDefaultValue);
  435. serEng>>fComplexTypeInfo;
  436. /***
  437. * DeSerialize RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
  438. ***/
  439. XTemplateSerializer::loadObject(&fAttDefs, 29, true, serEng);
  440. serEng>>fXsiComplexTypeInfo;
  441. fXsiSimpleTypeInfo = DatatypeValidator::loadDV(serEng);
  442. /***
  443. * DeSerialize RefVectorOf<IdentityConstraint>* fIdentityConstraints;
  444. ***/
  445. XTemplateSerializer::loadObject(&fIdentityConstraints, 16, true, serEng);
  446. serEng>>fAttWildCard;
  447. serEng>>fSubstitutionGroupElem;
  448. serEng>>i;
  449. fValidity = (PSVIDefs::Validity)i;
  450. serEng>> i;
  451. fValidation = (PSVIDefs::Validation)i;
  452. serEng>>fSeenValidation;
  453. serEng>>fSeenNoValidation;
  454. serEng>>fHadContent;
  455. }
  456. }
  457. XERCES_CPP_NAMESPACE_END