SchemaInclude.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 "SchemaInclude.hpp"
  16. #include "SchemaSchema.hpp"
  17. #include "ConfigSchemaHelper.hpp"
  18. using namespace CONFIGURATOR;
  19. #define IPropertyTree ::IPropertyTree
  20. void CInclude::dump(::std::ostream& cout, unsigned int offset) const
  21. {
  22. offset+= STANDARD_OFFSET_1;
  23. quickOutHeader(cout, XSD_INCLUDE_STR, offset);
  24. QUICK_OUT(cout, SchemaLocation, offset);
  25. QUICK_OUT(cout, XSDXPath, offset);
  26. if (this->getIncludeSchema() != nullptr)
  27. this->getIncludeSchema()->dump(cout, offset);
  28. quickOutFooter(cout, XSD_INCLUDE_STR, offset);
  29. }
  30. void CInclude::getDocumentation(StringBuffer &strDoc) const
  31. {
  32. }
  33. const char* CInclude::getXML(const char* /*pComponent*/)
  34. {
  35. return m_strXML.str();
  36. }
  37. CInclude* CInclude::load(CXSDNodeBase* pParentNode, const IPropertyTree *pSchemaRoot, const char* xpath)
  38. {
  39. //return nullptr; // TODO: Fix this to properly work with includes... temporary for testing
  40. if (pParentNode == nullptr || pSchemaRoot == nullptr || xpath == nullptr)
  41. return nullptr;
  42. CInclude *pInclude = nullptr;
  43. IPropertyTree *pTree = pSchemaRoot->queryPropTree(xpath);
  44. if (pTree != nullptr)
  45. {
  46. const char *pSchemaLocation = pTree->queryProp(XML_ATTR_SCHEMA_LOCATION);
  47. if (pSchemaLocation != nullptr)
  48. {
  49. CSchema* pSchema = CSchema::load(pSchemaLocation, nullptr); // no parent across XSD files
  50. pInclude = new CInclude(nullptr, pSchemaLocation);
  51. pInclude->setXSDXPath(xpath);
  52. pInclude->setIncludedSchema(pSchema);
  53. }
  54. }
  55. return pInclude;
  56. }
  57. void CInclude::populateEnvXPath(StringBuffer strXPath, unsigned int index)
  58. {
  59. assert(this->m_pIncludedSchema != nullptr);
  60. this->m_pIncludedSchema->populateEnvXPath(strXPath.str());
  61. }
  62. void CIncludeArray::populateEnvXPath(StringBuffer strXPath, unsigned int index)
  63. {
  64. //this->setEnvXPath(strXPath);
  65. //strXPath.clear();
  66. //QUICK_ENV_XPATH_WITH_INDEX(strXPath, index);
  67. }
  68. CIncludeArray* CIncludeArray::load(CXSDNodeBase* pParentNode, const IPropertyTree *pSchemaRoot, const char *xpath)
  69. {
  70. if (pSchemaRoot == nullptr)
  71. return nullptr;
  72. CIncludeArray *pIncludeArray = new CIncludeArray(pParentNode);
  73. pIncludeArray->setXSDXPath(xpath);
  74. Owned<IPropertyTreeIterator> elemIter = pSchemaRoot->getElements(xpath);
  75. int count = 1;
  76. ForEach(*elemIter)
  77. {
  78. StringBuffer strXPathExt(xpath);
  79. strXPathExt.appendf("[%d]", count);
  80. CInclude *pInclude = CInclude::load(pIncludeArray, pSchemaRoot, strXPathExt.str());
  81. if (pInclude != nullptr)
  82. pIncludeArray->append(*pInclude);
  83. count++;
  84. }
  85. if (pIncludeArray->length() == 0)
  86. {
  87. delete pIncludeArray;
  88. return nullptr;
  89. }
  90. return pIncludeArray;
  91. }
  92. const char* CIncludeArray::getXML(const char* /*pComponent*/)
  93. {
  94. if (m_strXML.length() == 0)
  95. {
  96. int length = this->length();
  97. for (int idx = 0; idx < length; idx++)
  98. {
  99. CInclude &Include = this->item(idx);
  100. m_strXML.append(Include.getXML(nullptr));
  101. if (idx+1 < length)
  102. m_strXML.append("\n");
  103. }
  104. }
  105. return m_strXML.str();
  106. }
  107. void CIncludeArray::dump(::std::ostream &cout, unsigned int offset) const
  108. {
  109. offset+= STANDARD_OFFSET_1;
  110. quickOutHeader(cout, XSD_INCLUDE_ARRAY_STR, offset);
  111. QUICK_OUT_ARRAY(cout, offset);
  112. quickOutFooter(cout, XSD_INCLUDE_ARRAY_STR, offset);
  113. }
  114. void CIncludeArray::getDocumentation(StringBuffer &strDoc) const
  115. {
  116. QUICK_DOC_ARRAY(strDoc);
  117. }