SchemaAttributes.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 _SCHEMA_ATTRIBUTES_HPP_
  14. #define _SCHEMA_ATTRIBUTES_HPP_
  15. #include "jarray.hpp"
  16. #include "jatomic.hpp"
  17. #include "XMLTags.h"
  18. #include "SchemaCommon.hpp"
  19. #include "SchemaAnnotation.hpp"
  20. namespace CONFIGURATOR
  21. {
  22. class CSimpleTypeArray;
  23. class CKeyRefArray;
  24. class CKeyArray;
  25. class CKey;
  26. class CKeyRef;
  27. class CAttribute : public CXSDNodeWithType
  28. {
  29. public:
  30. CAttribute(CXSDNodeBase* pParentNode, const char* pName = nullptr) : CXSDNodeWithType::CXSDNodeWithType(pParentNode, XSD_ATTRIBUTE), m_strName(pName),
  31. m_strDefault(""), m_strUse(""), m_pAnnotation(nullptr), m_pSimpleTypeArray(nullptr), m_bInstanceValueValid(false)
  32. {
  33. }
  34. CAttribute(CXSDNodeBase* pParentNode, const char* pName, const char* pType, const char* pDefault, const char* pUse) : CXSDNodeWithType::CXSDNodeWithType(pParentNode, XSD_ATTRIBUTE), m_strName(pName), m_pAnnotation(nullptr),
  35. m_strDefault(pDefault), m_strUse(pUse), m_pSimpleTypeArray(nullptr), m_bInstanceValueValid(false)
  36. {
  37. }
  38. virtual ~CAttribute();
  39. GETTERSETTER(Name)
  40. GETTERSETTER(Default)
  41. GETTERSETTER(Use)
  42. GETTERSETTER(InstanceValue)
  43. const CAnnotation* getAnnotation() const
  44. {
  45. return m_pAnnotation;
  46. }
  47. const char* getTitle() const;
  48. virtual const char* getXML(const char* pComponent);
  49. virtual void dump(::std::ostream& cout, unsigned int offset = 0) const;
  50. virtual void getDocumentation(::StringBuffer &strDoc) const;
  51. virtual void getJSON(::StringBuffer &strJSON, unsigned int offset = 0, int idx = -1) const;
  52. virtual void populateEnvXPath(::StringBuffer strXPath, unsigned int index = 1);
  53. virtual void loadXMLFromEnvXml(const ::IPropertyTree *pEnvTree);
  54. const CSimpleTypeArray* getSimpleTypeArray() const
  55. {
  56. return m_pSimpleTypeArray;
  57. }
  58. static CAttribute* load(CXSDNodeBase* pParentNode, const ::IPropertyTree *pSchemaRoot, const char* xpath = nullptr);
  59. bool isInstanceValueValid()
  60. {
  61. return m_bInstanceValueValid;
  62. }
  63. bool isHidden();
  64. virtual bool setEnvValueFromXML(const char *p);
  65. void appendReverseKey(const CKey *pKey);
  66. void appendReverseKeyRef(const CKeyRef *pKeyRef);
  67. protected:
  68. void setInstanceAsValid(bool bValid = true)
  69. {
  70. m_bInstanceValueValid = bValid;
  71. }
  72. void setAnnotation(CAnnotation *pAnnotation)
  73. {
  74. assert(pAnnotation != nullptr); // why would this ever be nullptr?
  75. m_pAnnotation = pAnnotation;
  76. }
  77. void setSimpleTypeArray(CSimpleTypeArray *pSimpleTypeArray)
  78. {
  79. assert(pSimpleTypeArray != nullptr); // why would this ever be nullptr?
  80. m_pSimpleTypeArray = pSimpleTypeArray;
  81. }
  82. CAnnotation *m_pAnnotation;
  83. CSimpleTypeArray *m_pSimpleTypeArray;
  84. ::PointerArray m_ReverseKeyArray;
  85. ::PointerArray m_ReverseKeyRefArray;
  86. bool m_bInstanceValueValid;
  87. private:
  88. };
  89. class CAttributeArray : public ::CIArrayOf<CAttribute>, public CInterface, public CXSDNodeBase
  90. {
  91. public:
  92. CAttributeArray(CXSDNodeBase* pParentNode = nullptr) : CXSDNodeBase::CXSDNodeBase(pParentNode, XSD_ATTRIBUTE_ARRAY)
  93. {
  94. }
  95. virtual ~CAttributeArray()
  96. {
  97. }
  98. virtual void dump(::std::ostream& cout, unsigned int offset = 0) const;
  99. virtual void getDocumentation(::StringBuffer &strDoc) const;
  100. virtual void getJSON(::StringBuffer &strJSON, unsigned int offset = 0, int idx = -1) const;
  101. virtual void populateEnvXPath(::StringBuffer strXPath, unsigned int index = 1);
  102. virtual void loadXMLFromEnvXml(const ::IPropertyTree *pEnvTree);
  103. virtual const char* getXML(const char* /*pComponent*/);
  104. const CAttribute* findAttributeWithName(const char *pName, bool bCaseInsensitive = true) const;
  105. const void getAttributeNames(::StringArray &names, ::StringArray &titles) const;
  106. static CAttributeArray* load(const char* pSchemaFile);
  107. static CAttributeArray* load(CXSDNodeBase* pParentNode, const ::IPropertyTree *pSchemaRoot, const char* xpath);
  108. protected:
  109. bool getCountOfValueMatches(const char *pValue) const;
  110. private:
  111. };
  112. }
  113. #endif // _SCHEMA_ATTRIBUTES_HPP_