SchemaLength.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "SchemaLength.hpp"
  15. #include "ConfigSchemaHelper.hpp"
  16. using namespace CONFIGURATOR;
  17. #define IPropertyTree ::IPropertyTree
  18. CLength* CLength::load(CXSDNodeBase* pParentNode, const IPropertyTree *pSchemaRoot, const char* xpath)
  19. {
  20. assert(pSchemaRoot != NULL);
  21. if (pSchemaRoot == NULL)
  22. return NULL;
  23. CLength *pLength = NULL;
  24. if (xpath && *xpath)
  25. {
  26. IPropertyTree* pTree = pSchemaRoot->queryPropTree(xpath);
  27. if (pTree == NULL)
  28. return NULL; // no xs:length node
  29. const char* pValue = pTree->queryProp(XML_ATTR_VALUE);
  30. if (pValue != NULL)
  31. {
  32. if (atoi(pValue) < 0)
  33. throw MakeExceptionFromMap(EX_STR_MISSING_VALUE_ATTRIBUTE_IN_LENGTH);
  34. pLength = new CLength(pParentNode);
  35. pLength->setXSDXPath(xpath);
  36. pLength->setValue(pValue);
  37. }
  38. else
  39. {
  40. assert(!"value attribute can be empty!");
  41. throw MakeExceptionFromMap(EX_STR_MISSING_VALUE_ATTRIBUTE_IN_LENGTH);
  42. }
  43. }
  44. return pLength;
  45. }
  46. void CLength::dump(::std::ostream& cout, unsigned int offset) const
  47. {
  48. offset += STANDARD_OFFSET_1;
  49. quickOutHeader(cout, XSD_LENGTH_STR, offset);
  50. QUICK_OUT(cout, Value, offset);
  51. quickOutFooter(cout, XSD_LENGTH_STR, offset);
  52. }