SchemaChoice.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 "jptree.hpp"
  14. #include "XMLTags.h"
  15. #include "SchemaChoice.hpp"
  16. #include "SchemaElement.hpp"
  17. #include "DocumentationMarkup.hpp"
  18. using namespace CONFIGURATOR;
  19. #define StringBuffer ::StringBuffer
  20. #define IPropertyTree ::IPropertyTree
  21. CChoice* CChoice::load(CXSDNodeBase* pParentNode, const IPropertyTree *pSchemaRoot, const char* xpath)
  22. {
  23. assert(pSchemaRoot != NULL);
  24. if (pSchemaRoot == NULL || xpath == NULL)
  25. return NULL;
  26. if (pSchemaRoot->queryPropTree(xpath) == NULL)
  27. return NULL; // no xs:choice node found
  28. StringBuffer strXPathExt(xpath);
  29. strXPathExt.append("/").append(XSD_TAG_ELEMENT);
  30. CArrayOfElementArrays *pArrayOfElemArrays = CArrayOfElementArrays::load(NULL, pSchemaRoot, strXPathExt.str());
  31. assert(pArrayOfElemArrays);
  32. if (pArrayOfElemArrays == NULL)
  33. return NULL;
  34. CChoice *pChoice = new CChoice(pParentNode, pArrayOfElemArrays);
  35. assert(pChoice);
  36. if (pChoice == NULL)
  37. return NULL;
  38. pChoice->setXSDXPath(xpath);
  39. SETPARENTNODE(pArrayOfElemArrays, pChoice);
  40. return pChoice;
  41. }
  42. const char* CChoice::getXML(const char* /*pComponent*/)
  43. {
  44. if (m_strXML.length() == 0)
  45. if (m_pArrayOfElementArrays != NULL)
  46. m_strXML.append(m_pArrayOfElementArrays->getXML(NULL));
  47. return m_strXML.str();
  48. }
  49. void CChoice::dump(::std::ostream &cout, unsigned int offset) const
  50. {
  51. offset += STANDARD_OFFSET_1;
  52. quickOutHeader(cout, XSD_CHOICE_STR, offset);
  53. QUICK_OUT(cout, ID, offset);
  54. QUICK_OUT(cout ,MinOccurs, offset);
  55. QUICK_OUT(cout, MaxOccurs, offset);
  56. QUICK_OUT(cout, XSDXPath, offset);
  57. if (m_pArrayOfElementArrays != NULL)
  58. m_pArrayOfElementArrays->dump(cout, offset);
  59. quickOutFooter(cout, XSD_CHOICE_STR, offset);
  60. }
  61. void CChoice::getDocumentation(StringBuffer &strDoc) const
  62. {
  63. if (m_pArrayOfElementArrays != NULL)
  64. m_pArrayOfElementArrays->getDocumentation(strDoc);
  65. }
  66. void CChoice::getJSON(StringBuffer &strJSON, int idx) const
  67. {
  68. // this is really not correct but roxie.xsd is not correct and probably others
  69. bool bSkip = true;
  70. for (int i = 0; m_pArrayOfElementArrays->length() > i; i++)
  71. {
  72. if (m_pArrayOfElementArrays->item(i).length() == 0)
  73. continue;
  74. if (bSkip == false)
  75. {
  76. strJSON.append(",");
  77. }
  78. bSkip = false;
  79. m_pArrayOfElementArrays->item(i).getJSON(strJSON);
  80. }
  81. }
  82. void CChoice::populateEnvXPath(StringBuffer strXPath, unsigned int index)
  83. {
  84. this->setEnvXPath(strXPath);
  85. if (m_pArrayOfElementArrays != NULL)
  86. m_pArrayOfElementArrays->populateEnvXPath(strXPath);
  87. }
  88. void CChoice::loadXMLFromEnvXml(const IPropertyTree *pEnvTree)
  89. {
  90. assert (pEnvTree != NULL);
  91. if (m_pArrayOfElementArrays != NULL)
  92. {
  93. try
  94. {
  95. m_pArrayOfElementArrays->loadXMLFromEnvXml(pEnvTree);
  96. }
  97. catch (...)
  98. {
  99. UNIMPLEMENTED;
  100. }
  101. }
  102. }