SchemaSequence.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2015 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include <cassert>
  14. #include "jptree.hpp"
  15. #include "XMLTags.h"
  16. #include "SchemaSequence.hpp"
  17. #include "SchemaElement.hpp"
  18. #include "JSONMarkUp.hpp"
  19. using namespace CONFIGURATOR;
  20. #define StringBuffer ::StringBuffer
  21. #define IPropertyTree ::IPropertyTree
  22. const CXSDNodeBase* CSequence::getNodeByTypeAndNameDescending(NODE_TYPES eNodeType, const char *pName) const
  23. {
  24. const CXSDNodeBase* pMatchingNode = NULL;
  25. if (eNodeType == this->getNodeType() && (pName != NULL ? !strcmp(pName, this->getNodeTypeStr()) : true))
  26. return this;
  27. if (m_pArrayOfElementArrays != NULL)
  28. pMatchingNode = m_pArrayOfElementArrays->getNodeByTypeAndNameDescending(eNodeType, pName);
  29. return pMatchingNode;
  30. }
  31. CSequence* CSequence::load(CXSDNodeBase* pParentNode, const IPropertyTree *pSchemaRoot, const char* xpath)
  32. {
  33. assert(pSchemaRoot != NULL);
  34. CSequence *pSequence = NULL;
  35. if (pSchemaRoot == NULL)
  36. return NULL;
  37. if (pSchemaRoot->queryPropTree(xpath) == NULL)
  38. return NULL; // no sequence node
  39. StringBuffer strXPath(xpath);
  40. strXPath.append("/").append(XSD_TAG_ELEMENT);
  41. CArrayOfElementArrays *pArrayOfElemArrays = CArrayOfElementArrays::load(NULL, pSchemaRoot, strXPath.str());
  42. if (pArrayOfElemArrays != NULL)
  43. {
  44. pSequence = new CSequence(pParentNode, pArrayOfElemArrays);
  45. pSequence->setXSDXPath(xpath);
  46. }
  47. SETPARENTNODE(pArrayOfElemArrays, pSequence)
  48. return pSequence;
  49. }
  50. void CSequence::dump(::std::ostream& cout, unsigned int offset) const
  51. {
  52. offset+= STANDARD_OFFSET_1;
  53. quickOutHeader(cout, XSD_SEQUENCE_STR, offset);
  54. QUICK_OUT(cout, XSDXPath, offset);
  55. if (m_pArrayOfElementArrays != NULL)
  56. m_pArrayOfElementArrays->dump(cout, offset);
  57. quickOutFooter(cout, XSD_SEQUENCE_STR, offset);
  58. }
  59. void CSequence::getDocumentation(StringBuffer &strDoc) const
  60. {
  61. if (m_pArrayOfElementArrays != NULL)
  62. m_pArrayOfElementArrays->getDocumentation(strDoc);
  63. }
  64. void CSequence::getJSON(StringBuffer &strJSON, unsigned int offset, int idx) const
  65. {
  66. if (m_pArrayOfElementArrays != NULL)
  67. {
  68. m_pArrayOfElementArrays->getJSON(strJSON, offset);
  69. }
  70. }
  71. void CSequence::populateEnvXPath(StringBuffer strXPath, unsigned int index)
  72. {
  73. if (m_pArrayOfElementArrays != NULL)
  74. m_pArrayOfElementArrays->populateEnvXPath(strXPath, index);
  75. this->setEnvXPath(strXPath);
  76. }
  77. void CSequence::loadXMLFromEnvXml(const IPropertyTree *pEnvTree)
  78. {
  79. if (m_pArrayOfElementArrays != NULL)
  80. m_pArrayOfElementArrays->loadXMLFromEnvXml(pEnvTree);
  81. }
  82. bool CSequence::hasChildElements() const
  83. {
  84. if (this->m_pArrayOfElementArrays->length() > 0)
  85. {
  86. for(int i = 0; i < m_pArrayOfElementArrays->ordinality(); i++)
  87. {
  88. if (m_pArrayOfElementArrays->item(i).length() > 0)
  89. return true;
  90. }
  91. }
  92. return false;
  93. }