SchemaExtension.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "XMLTags.h"
  14. #include "jptree.hpp"
  15. #include "SchemaExtension.hpp"
  16. #include "SchemaComplexType.hpp"
  17. #include "SchemaSchema.hpp"
  18. #include "ConfigSchemaHelper.hpp"
  19. using namespace CONFIGURATOR;
  20. #define IPropertyTree ::IPropertyTree
  21. static const char* DEFAULT_ENVIRONMENT_XSD("Environment.xsd");
  22. void CExtension::dump(::std::ostream& cout, unsigned int offset) const
  23. {
  24. offset+= STANDARD_OFFSET_1;
  25. QuickOutHeader(cout, XSD_EXTENSION_STR, offset);
  26. QUICK_OUT(cout, Base, offset);
  27. QUICK_OUT(cout, XSDXPath, offset);
  28. if (this->getBaseNode() != NULL)
  29. this->getBaseNode()->dump(cout, offset);
  30. QuickOutFooter(cout, XSD_EXTENSION_STR, offset);
  31. }
  32. const char* CExtension::getXML(const char* /*pComponent*/)
  33. {
  34. if (m_strXML.length() == 0 && m_pXSDNode != NULL)
  35. m_pXSDNode->getXML(NULL);
  36. return NULL;
  37. }
  38. void CExtension::initExtension()
  39. {
  40. NODE_TYPES eNodeType[] = { XSD_SIMPLE_TYPE, XSD_SIMPLE_CONTENT };
  41. const CXSDNodeBase *pBaseNode = (dynamic_cast<const CXSDNodeBase*>(this));
  42. if (pBaseNode != NULL)
  43. {
  44. pBaseNode->getNodeByTypeAndNameAscending( eNodeType, this->getBase());
  45. this->setBaseNode(const_cast<CXSDNodeBase*>(pBaseNode));
  46. }
  47. }
  48. CExtension* CExtension::load(CXSDNodeBase* pParentNode, const IPropertyTree *pSchemaRoot, const char* xpath)
  49. {
  50. CHECK_EXCLUSION(XSD_EXTENSION);
  51. assert(pSchemaRoot != NULL);
  52. if (pSchemaRoot == NULL)
  53. return NULL;
  54. CExtension *pExtension = NULL;
  55. if (xpath && *xpath)
  56. {
  57. IPropertyTree* pTree = pSchemaRoot->queryPropTree(xpath);
  58. if (pTree == NULL)
  59. return NULL; // no xs:extension node
  60. const char* pBase = pSchemaRoot->getPropTree(xpath)->queryProp(XML_ATTR_BASE);
  61. if (pBase != NULL)
  62. {
  63. pExtension = new CExtension(pParentNode);
  64. pExtension->setXSDXPath(xpath);
  65. pExtension->setBase(pBase);
  66. }
  67. }
  68. if (pExtension != NULL)
  69. CConfigSchemaHelper::getInstance()->addExtensionToBeProcessed(pExtension);
  70. return pExtension;
  71. }