ConfigSchemaHelper.hpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #ifndef _CONFIG_SCHEMA_HELPER_HPP_
  14. #define _CONFIG_SCHEMA_HELPER_HPP_
  15. #include "jiface.hpp"
  16. #include "jptree.hpp"
  17. #include "jutil.hpp"
  18. #include "jarray.hpp"
  19. #include "jhash.hpp"
  20. #include "SchemaAttributes.hpp"
  21. #include "SchemaAttributeGroup.hpp"
  22. #include "SchemaElement.hpp"
  23. #include "SchemaSchema.hpp"
  24. #include "SchemaExtension.hpp"
  25. #include "BuildSet.hpp"
  26. #include "ConfiguratorAPI.hpp"
  27. #include "SchemaMapManager.hpp"
  28. namespace CONFIGURATOR
  29. {
  30. static const char* CONFIGURATOR_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Environment>\n\t<Software>";
  31. class CSchemaMapManager;
  32. class CSimpleType;
  33. class CConfigSchemaHelper : public ::CInterface
  34. {
  35. public:
  36. IMPLEMENT_IINTERFACE
  37. static CConfigSchemaHelper* getInstance(const char* pDefaultDirOverride = nullptr);
  38. static CConfigSchemaHelper* getInstance(const char* pBuildSetFileName, const char *pBaseDirectory, const char *pDefaultDirOverride = nullptr);
  39. static CConfigSchemaHelper* getNewInstance(const char* pDefaultDirOverride = nullptr);
  40. virtual ~CConfigSchemaHelper();
  41. bool populateSchema();
  42. void printConfigSchema(StringBuffer &str) const;
  43. CSchemaMapManager* getSchemaMapManager()
  44. {
  45. return m_pSchemaMapManager;
  46. }
  47. void addExtensionToBeProcessed(CExtension *pExtension);
  48. void processExtensionArr();
  49. void addAttributeGroupToBeProcessed(CAttributeGroup *pAttributeGroup);
  50. void processAttributeGroupArr();
  51. void addNodeForBaseProcessing(CXSDNodeWithBase *pNode);
  52. void processNodeWithBaseArr();
  53. void addNodeForTypeProcessing(CXSDNodeWithType *pNode);
  54. void processNodeWithTypeArr(CXSDNodeBase *pParentNode = nullptr);
  55. void addElementForRefProcessing(CElement *pElement);
  56. void processElementArr();
  57. void addKeyRefForReverseAssociation(const CKeyRef *pKeyRef) const;
  58. void processKeyRefReverseAssociation() const;
  59. void addKeyForReverseAssociation(const CKey *pKeyRef) const;
  60. void processKeyReverseAssociation() const;
  61. bool getXMLFromSchema(StringBuffer& strXML, const char* pXSD); //test purposes
  62. void populateEnvXPath();
  63. void loadEnvFromConfig(const char *pEnvFile);
  64. void printDocumentation(const char* comp, char **pOutput) const;
  65. void printJSON(const char* comp, char **pOutput, int nIdx = -1, bool bCleanUp = false) const;
  66. void printJSONByKey(const char* key, char **pOutput, bool bCleanUp = false) const;
  67. void printNavigatorJSON(char **pOutput, bool bCleanUp = false) const;
  68. void printDump(const char* comp) const;
  69. void dumpStdOut() const;
  70. const char* getBasePath() const
  71. {
  72. return m_pBasePath;
  73. }
  74. void setBasePath(const char *pBasePath);
  75. void setEnvTreeProp(const char *pXPath, const char* pValue);
  76. const char* getTableValue(const char* pXPath, int nRow = 1) const;
  77. int getEnvironmentXPathSize() const
  78. {
  79. return m_strArrayEnvXPaths.length();
  80. }
  81. const char* getEnvironmentXPaths(int idx) const
  82. {
  83. assert(idx >= 0);
  84. assert(m_strArrayEnvXPaths.length() > idx);
  85. return m_strArrayEnvXPaths.item(idx);
  86. }
  87. const char* getAttributeXSDXPathFromEnvXPath(const char* pEnvXPath) const;
  88. const char* getElementArrayXSDXPathFromEnvXPath(const char* pXSDXPath) const;
  89. int getElementArraySize(const char *pXPath) const;
  90. void appendAttributeXPath(const char *pXPath);
  91. void appendElementXPath(const char *pXPath);
  92. static int stripXPathIndex(StringBuffer &strXPath);
  93. static bool isXPathTailAttribute(const StringBuffer &strXPath);
  94. ::IPropertyTree* getEnvPropertyTree()
  95. {
  96. return m_pEnvPropertyTree;
  97. }
  98. const ::IPropertyTree* getConstEnvPropertyTree() const
  99. {
  100. return m_pEnvPropertyTree;
  101. }
  102. int getNumberOfTables() const
  103. {
  104. return m_nTables;
  105. }
  106. void incTables()
  107. {
  108. m_nTables++;
  109. }
  110. void resetTables() const
  111. {
  112. m_nTables = 0;
  113. }
  114. bool saveConfigurationFile() const;
  115. bool saveConfigurationFileAs(const char *pFilePath = nullptr);
  116. const char* getEnvFilePath() const
  117. {
  118. return m_strEnvFilePath.str();
  119. }
  120. int getInstancesOfComponentType(const char *pCompType) const;
  121. const char* getInstanceNameOfComponentType(const char *pCompType, int idx);
  122. protected:
  123. CConfigSchemaHelper(const char* pBuildSetFile = DEFAULT_BUILD_SET_XML_FILE, const char* pBuildSetDir = DEFAULT_BUILD_SET_DIRECTORY, const char* pDefaultDirOverride = nullptr);
  124. CSchemaMapManager *m_pSchemaMapManager;
  125. ::CIArrayOf<CExtension> m_extensionArr;
  126. ::CIArrayOf<CAttributeGroup> m_attributeGroupArr;
  127. ::CIArrayOf<CXSDNodeWithType> m_nodeWithTypeArr;
  128. ::CIArrayOf<CXSDNodeWithBase> m_nodeWithBaseArr;
  129. ::CIArrayOf<CElement> m_ElementArr;
  130. ::CIArrayOf<CKeyRef> m_KeyRefArr;
  131. ::StringArray m_strArrayEnvXPaths;
  132. ::StringArray m_strArrayEnvXMLComponentInstances;
  133. void setEnvPropertyTree(::IPropertyTree *pEnvTree)
  134. {
  135. m_pEnvPropertyTree = pEnvTree;
  136. }
  137. void setEnvFilePath(const char* pEnvFilePath)
  138. {
  139. assert(pEnvFilePath != nullptr);
  140. m_strEnvFilePath.set(pEnvFilePath);
  141. }
  142. static void clearLF(StringBuffer& strToClear);
  143. static size_t getXPathIndexLength(const char *pXPath);
  144. private:
  145. static CConfigSchemaHelper* s_pCConfigSchemaHelper;
  146. mutable int m_nTables;
  147. char *m_pBasePath;
  148. ::StringBuffer m_strEnvFilePath;
  149. ::IPropertyTree *m_pEnvPropertyTree;
  150. };
  151. }
  152. #endif // _CONFIG_SCHEMA_HELPER_HPP_