SchemaSelector.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "SchemaSelector.hpp"
  14. #include "SchemaCommon.hpp"
  15. using namespace CONFIGURATOR;
  16. #define IPropertyTree ::IPropertyTree
  17. #define StringBuffer ::StringBuffer
  18. CSelector* CSelector::load(CXSDNodeBase* pParentNode, const IPropertyTree *pSchemaRoot, const char* xpath)
  19. {
  20. assert(pSchemaRoot != NULL);
  21. assert(pParentNode != NULL);
  22. assert(pParentNode->getNodeType() == XSD_KEY || pParentNode->getNodeType() == XSD_KEYREF || pParentNode->getNodeType() == XSD_UNIQUE);
  23. if (pSchemaRoot == NULL || pParentNode == NULL)
  24. {
  25. // TODO: Throw Exception
  26. assert(false);
  27. return NULL;
  28. }
  29. CSelector *pSelector = NULL;
  30. if (xpath != NULL && *xpath != 0)
  31. {
  32. IPropertyTree* pTree = pSchemaRoot->queryPropTree(xpath);
  33. if (pTree == NULL)
  34. {
  35. assert(!"Selector required");
  36. // TODO: throw MakeExceptionFromMap("EX_STR_MISSING_SELECTOR_MISSING");
  37. }
  38. const char* pXPath = pSchemaRoot->getPropTree(xpath)->queryProp(XML_ATTR_XPATH);
  39. assert(pXPath != NULL && *pXPath != 0);
  40. if (pXPath == NULL || *pXPath == 0)
  41. {
  42. assert(!"Throw Exception");
  43. return NULL;
  44. // TODO: throw exception
  45. }
  46. if (pXPath != NULL)
  47. {
  48. pSelector = new CSelector(pParentNode);
  49. pSelector->setXSDXPath(xpath);
  50. pSelector->setXPath(pXPath);
  51. }
  52. else
  53. {
  54. assert(!"selector can not be be empty!");
  55. // TODO: throw MakeExceptionFromMap(EX_STR_MISSING_VALUE_ATTRIBUTE_IN_LENGTH);
  56. }
  57. const char *pID = pSchemaRoot->getPropTree(xpath)->queryProp(XML_ATTR_ID);
  58. if (pID != NULL)
  59. pSelector->setID(pID);
  60. }
  61. return pSelector;
  62. }
  63. void CSelector::dump(::std::ostream& cout, unsigned int offset) const
  64. {
  65. offset += STANDARD_OFFSET_1;
  66. QuickOutHeader(cout, XSD_SELECTOR_STR, offset);
  67. QUICK_OUT(cout, XPath, offset);
  68. QUICK_OUT(cout, ID, offset);
  69. QUICK_OUT(cout, XSDXPath, offset);
  70. QuickOutFooter(cout, XSD_SELECTOR_STR, offset);
  71. }
  72. void CSelector::populateEnvXPath(StringBuffer strXPath, unsigned int index)
  73. {
  74. this->setEnvXPath(&(strXPath.str()[1])); // strip out .
  75. PROGLOG("Function: %s() at %s:%d", __func__, __FILE__, __LINE__);
  76. PROGLOG("Setting selector %s to EnvXPath = %s", this->getXSDXPath(), this->getEnvXPath());
  77. }