SchemaField.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "SchemaField.hpp"
  14. using namespace CONFIGURATOR;
  15. #define IPropertyTree ::IPropertyTree
  16. CField* CField::load(CXSDNodeBase* pParentNode, const IPropertyTree *pSchemaRoot, const char* xpath)
  17. {
  18. assert(pSchemaRoot != nullptr);
  19. assert(pParentNode != nullptr);
  20. assert(pParentNode->getNodeType() == XSD_FIELD_ARRAY);
  21. if (pSchemaRoot == nullptr || pParentNode == nullptr)
  22. {
  23. // TODO: Throw Exception
  24. return nullptr;
  25. }
  26. CField *pField = nullptr;
  27. if (xpath != nullptr && *xpath != 0)
  28. {
  29. IPropertyTree* pTree = pSchemaRoot->queryPropTree(xpath);
  30. if (pTree == nullptr)
  31. return nullptr;
  32. const char* pXPath = pTree->queryProp(XML_ATTR_XPATH);
  33. assert(pXPath != nullptr && *pXPath != 0);
  34. if (pXPath == nullptr || *pXPath == 0)
  35. {
  36. assert(!"Throw Exception");
  37. // TODO: throw exception
  38. }
  39. if (pXPath != nullptr)
  40. {
  41. pField = new CField(pParentNode);
  42. pField->setXSDXPath(xpath);
  43. pField->setXPath(pXPath);
  44. }
  45. else
  46. {
  47. assert(!"xpath can not be be empty!");
  48. // TODO: throw MakeExceptionFromMap(EX_STR_MISSING_XPATH_IN_FIELD);
  49. }
  50. const char *pID = pTree->queryProp(XML_ATTR_ID);
  51. if (pID != nullptr)
  52. pField->setID(pID);
  53. }
  54. return pField;
  55. }
  56. void CField::dump(::std::ostream& cout, unsigned int offset) const
  57. {
  58. offset += STANDARD_OFFSET_1;
  59. quickOutHeader(cout, XSD_FIELD_STR, offset);
  60. QUICK_OUT(cout, XPath, offset);
  61. QUICK_OUT(cout, ID, offset);
  62. QUICK_OUT(cout, XSDXPath, offset);
  63. quickOutFooter(cout, XSD_FIELD_STR, offset);
  64. }
  65. CFieldArray* CFieldArray::load(CXSDNodeBase* pParentNode, const IPropertyTree *pSchemaRoot, const char* xpath)
  66. {
  67. assert(xpath != nullptr);
  68. assert(pParentNode != nullptr);
  69. assert(pSchemaRoot != nullptr);
  70. assert(pParentNode->getNodeType() == XSD_KEY || pParentNode->getNodeType() == XSD_KEYREF || pParentNode->getNodeType() == XSD_UNIQUE);
  71. if (pSchemaRoot == nullptr || xpath == nullptr || pParentNode == nullptr)
  72. {
  73. // TODO: exceptions
  74. //throw
  75. return nullptr;
  76. }
  77. StringBuffer strXPathExt(xpath);
  78. CFieldArray *pFieldArray = new CFieldArray(pParentNode);
  79. pFieldArray->setXSDXPath(xpath);
  80. Owned<IPropertyTreeIterator> attributeIter = pSchemaRoot->getElements(xpath, ipt_ordered);
  81. int count = 1;
  82. ForEach(*attributeIter)
  83. {
  84. strXPathExt.setf("%s[%d]", xpath, count);
  85. CField *pField = CField::load(pFieldArray, pSchemaRoot, strXPathExt.str());
  86. if (pField != nullptr)
  87. pFieldArray->append(*pField);
  88. count++;
  89. }
  90. if (pFieldArray->length() == 0)
  91. {
  92. delete pFieldArray;
  93. pFieldArray = nullptr;
  94. }
  95. return pFieldArray;
  96. }
  97. void CFieldArray::dump(::std::ostream &cout, unsigned int offset) const
  98. {
  99. offset+= STANDARD_OFFSET_1;
  100. quickOutHeader(cout, XSD_FIELD_ARRAY_STR, offset);
  101. QUICK_OUT(cout, XSDXPath, offset);
  102. QUICK_OUT(cout, EnvXPath, offset);
  103. QUICK_OUT_ARRAY(cout, offset);
  104. quickOutFooter(cout, XSD_FIELD_ARRAY_STR, offset);
  105. }