SchemaCommon.hpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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_COMMON_HPP_
  14. #define _SCHEMA_COMMON_HPP_
  15. #include <iostream>
  16. #include "jiface.hpp"
  17. #include "jstring.hpp"
  18. #include "jlib.hpp"
  19. #include "jlog.hpp"
  20. #include "jarray.hpp"
  21. #include "XMLTags.h"
  22. #include "ExceptionStrings.hpp"
  23. #include "build-config.h"
  24. namespace CONFIGURATOR
  25. {
  26. #define MINIMUM_STRICTNESS 0
  27. #define DEFAULT_STRICTNESS 5
  28. #define MAXIMUM_STRICTNESS 10
  29. #define STRICTNESS_LEVEL MINIMUM_STRICTNESS
  30. #define QUICK_OUT(X,Y,Z) quickOut(X,#Y,get##Y(),Z);
  31. #define QUICK_OUT_2(Y) quickOut(cout, #Y, get##Y(), offset);
  32. #define QUICK_OUT_3(X) if (m_p##X != nullptr) m_p##X->dump(cout, offset);
  33. #define QUICK_OUT_ARRAY(X,Z) for (int idx=0; idx < this->length(); idx++) \
  34. { \
  35. quickOutPad(X,Z+STANDARD_OFFSET_1); \
  36. X << idx+1 << "]" << ::std::endl; \
  37. (this->item(idx)).dump(cout,Z); \
  38. }
  39. #define QUICK_DOC_ARRAY(X) for (int idx=0; idx < this->length(); idx++) \
  40. { \
  41. (this->item(idx)).getDocumentation(X); \
  42. }
  43. #define LAST_ONLY -1
  44. #define LAST_AND_FIRST -2
  45. #define QUICK_ENV_XPATH(X) for (int idx=0; idx < this->length(); idx++) \
  46. { \
  47. (this->item(idx)).populateEnvXPath(X.str(), idx+1); \
  48. }
  49. #define QUICK_ENV_XPATH_WITH_INDEX(X,Y) for (int idx=0; idx < this->length(); idx++) \
  50. { \
  51. (this->item(idx)).populateEnvXPath(X.str(), Y); \
  52. }
  53. #define QUICK_LOAD_ENV_XML(X) assert(X != nullptr); \
  54. for (int idx=0; idx < this->length(); idx++) \
  55. { \
  56. (this->item(idx)).loadXMLFromEnvXml(X); \
  57. }
  58. #define GETTER(X) virtual const char* get##X() const { return m_str##X.str(); }
  59. #define SETTER(X) virtual void set##X(const char* p) { m_str##X.clear().append(p); }
  60. #define GETTERSETTER(X) protected: StringBuffer m_str##X; public: GETTER(X) SETTER(X) public:
  61. //#define GETTER2(X) virtual const char* get##X() const { return m_str##X.str(); }
  62. //#define SETTER2(X) virtual void set##X(const char* p) { m_str##X.clear().append(p); m_str##X.replace('/','_');}
  63. //#define GETTERSETTER2(X) protected: StringBuffer m_str##X; public: GETTER(X) SETTER2(X) public:
  64. #define GETTERINT(X) virtual const long get##X() const { return m_n##X; }
  65. #define SETTERINT(X) virtual void set##X(long p) { m_n##X = p; } virtual void set##X(const char *p) { assert(p != nullptr); if (p != 0 && *p != 0) m_n##X = atol(p); }
  66. #define GETTERSETTERINT(X) protected: long m_n##X; public: GETTERINT(X) SETTERINT(X) private:
  67. #define SETPARENTNODE(X, Y) if (X!= nullptr && Y != nullptr) X->setParentNode(Y);
  68. //#define DEBUG_MARK_STRDOC strDoc.append(__FILE__).append(":").append(__LINE__).append("\n");
  69. #define DEBUG_MARK_STRDOC
  70. #define DEBUG_MARK_COMMENT(X) X.append("// ").append(__FILE__).append(":").append(__LINE__).append("\n");
  71. #define DEBUG_MARK_COMMENT2(X,Y) X.append("// UIType=").append(Y->getUIType()).append(" ").append(__FILE__).append(":").append(__LINE__).append("\n");
  72. #define DEBUG_MARK_COMMENT_3 quickOutPad(strJSON, offset); strJSON.append("{ \"").append(__FILE__).append("\" : \"").append(__LINE__).append("\"},\n"); QuickOutPad(strJSON, offset);
  73. #define DEBUG_MARK_COMMENT_4 quickOutPad(strJSON, offset); strJSON.append(",{ \"").append(__FILE__).append("\" : \"").append(__LINE__).append("\"},\n"); QuickOutPad(strJSON, offset);
  74. #define DEBUG_MARK_STRJS DEBUG_MARK_COMMENT(strJS)
  75. #define DEBUG_MARK_JSON_1 //DEBUG_MARK_COMMENT_4// DEBUG_MARK_COMMENT(strJSON)
  76. #define DEBUG_MARK_JSON_2 //DEBUG_MARK_COMMENT_3// DEBUG_MARK_COMMENT(strJSON)
  77. #define GETTERTYPE(X) C##X* get##X() const { return m_p##X; }
  78. #define SETTERTYPE(X) void set##X( C##X *p ) { assert(p != nullptr); if (p != nullptr) m_p##X = p; }
  79. #define GETTERSETTERTYPE(X) public: C##X *m_p##X; GETTERTYPE(X) SETTERTYPE(X) private:
  80. #define CHECK_EXCLUSION(X) if(CConfigSchemaHelper::getInstance()->getSchemaMapManager()->isNodeExcluded(X)) return nullptr;
  81. #define IS_EXCLUDED(X) (CConfigSchemaHelper::getInstance()->getSchemaMapManager()->isNodeExcluded(X) ? true : false)
  82. enum NODE_TYPES
  83. {
  84. XSD_ANNOTATION = 0x0,
  85. XSD_APP_INFO,
  86. XSD_ATTRIBUTE,
  87. XSD_ATTRIBUTE_ARRAY,
  88. XSD_ATTRIBUTE_GROUP,
  89. XSD_ATTRIBUTE_GROUP_ARRAY,
  90. XSD_CHOICE,
  91. XSD_COMPLEX_CONTENT,
  92. XSD_COMPLEX_TYPE,
  93. XSD_COMPLEX_TYPE_ARRAY,
  94. XSD_DOCUMENTATION,
  95. XSD_ELEMENT,
  96. XSD_ELEMENT_ARRAY,
  97. XSD_ARRAY_OF_ELEMENT_ARRAYS,
  98. XSD_EXTENSION,
  99. XSD_FIELD,
  100. XSD_FIELD_ARRAY,
  101. XSD_KEY,
  102. XSD_KEY_ARRAY,
  103. XSD_KEYREF,
  104. XSD_KEYREF_ARRAY,
  105. XSD_INCLUDE,
  106. XSD_INCLUDE_ARRAY,
  107. XSD_RESTRICTION,
  108. XSD_SCHEMA,
  109. XSD_SEQUENCE,
  110. XSD_SIMPLE_TYPE,
  111. XSD_SIMPLE_TYPE_ARRAY,
  112. XSD_ENUMERATION,
  113. XSD_ENUMERATION_ARRAY,
  114. XSD_LENGTH,
  115. XSD_FRACTION_DIGITS,
  116. XSD_MAX_EXCLUSIVE,
  117. XSD_MAX_INCLUSIVE,
  118. XSD_MIN_EXCLUSIVE,
  119. XSD_MIN_INCLUSIVE,
  120. XSD_MIN_LENGTH,
  121. XSD_MAX_LENGTH,
  122. XSD_PATTERN,
  123. XSD_SELECTOR,
  124. XSD_SIMPLE_CONTENT,
  125. XSD_TOTAL_DIGITS,
  126. XSD_UNIQUE,
  127. XSD_UNIQUE_ARRAY,
  128. XSD_WHITE_SPACE,
  129. XSD_DT_NORMALIZED_STRING, // keep this as the first DT type for array index purposes
  130. XSD_DT_STRING,
  131. XSD_DT_TOKEN,
  132. XSD_DT_DATE,
  133. XSD_DT_TIME,
  134. XSD_DT_DATE_TIME,
  135. XSD_DT_DECIMAL,
  136. XSD_DT_INT,
  137. XSD_DT_INTEGER,
  138. XSD_DT_LONG,
  139. XSD_DT_NON_NEG_INTEGER,
  140. XSD_DT_NON_POS_INTEGER,
  141. XSD_DT_NEG_INTEGER,
  142. XSD_DT_POS_INTEGER,
  143. XSD_DT_BOOLEAN,
  144. XSD_ERROR
  145. };
  146. static const char* DEFAULT_SCHEMA_DIRECTORY(COMPONENTFILES_DIR "/configxml/");
  147. static const char* XSD_ANNOTATION_STR("Annotation");
  148. static const char* XSD_APP_INFO_STR("AppInfo");
  149. static const char* XSD_ATTRIBUTE_STR("Attribute");
  150. static const char* XSD_ATTRIBUTE_ARRAY_STR("AttributeArray");
  151. static const char* XSD_ATTRIBUTE_GROUP_STR("AttributeGroup");
  152. static const char* XSD_ATTRIBUTE_GROUP_ARRAY_STR("AttributeGroupArray");
  153. static const char* XSD_CHOICE_STR("Choice");
  154. static const char* XSD_COMPLEX_CONTENT_STR("ComplexContent");
  155. static const char* XSD_COMPLEX_TYPE_STR("ComplexType");
  156. static const char* XSD_COMPLEX_TYPE_ARRAY_STR("ComplexTypeArray");
  157. static const char* XSD_DOCUMENTATION_STR("Documentation");
  158. static const char* XSD_ELEMENT_STR("Element");
  159. static const char* XSD_ELEMENT_ARRAY_STR("ElementArray");
  160. static const char* XSD_ARRAY_ELEMENT_ARRAY_STR("ArrayOfElementArrays");
  161. static const char* XSD_ERROR_STR("ERROR");
  162. static const char* XSD_ENUMERATION_STR("Enumeration");
  163. static const char* XSD_ENUMERATION_ARRAY_STR("EnumerationArray");
  164. static const char* XSD_EXTENSION_STR("Extension");
  165. static const char* XSD_FIELD_STR("Field");
  166. static const char* XSD_FIELD_ARRAY_STR("FieldArray");
  167. static const char* XSD_FRACTION_DIGITS_STR("FractionDigits");
  168. static const char* XSD_INCLUDE_STR("Include");
  169. static const char* XSD_INCLUDE_ARRAY_STR("IncludeArray");
  170. static const char* XSD_KEY_STR("Key");
  171. static const char* XSD_KEY_ARRAY_STR("KeyArray");
  172. static const char* XSD_KEYREF_STR("KeyRef");
  173. static const char* XSD_KEYREF_ARRAY_STR("KeyRefArray");
  174. static const char* XSD_LENGTH_STR("Length");
  175. static const char* XSD_MIN_INCLUSIVE_STR("MinInclusive");
  176. static const char* XSD_MAX_INCLUSIVE_STR("MaxInclusive");
  177. static const char* XSD_MIN_EXCLUSIVE_STR("MinExclusive");
  178. static const char* XSD_MAX_EXCLUSIVE_STR("MaxExclusive");
  179. static const char* XSD_MIN_LENGTH_STR("MinLength");
  180. static const char* XSD_MAX_LENGTH_STR("MaxLength");
  181. static const char* XSD_PATTERN_STR("Pattern");
  182. static const char* XSD_RESTRICTION_STR("Restriction");
  183. static const char* XSD_SCHEMA_STR("Schema");
  184. static const char* XSD_SELECTOR_STR("Selector");
  185. static const char* XSD_SEQUENCE_STR("Sequence");
  186. static const char* XSD_SIMPLE_CONTENT_STR("SimpleContent");
  187. static const char* XSD_SIMPLE_TYPE_STR("SimpleType");
  188. static const char* XSD_SIMPLE_TYPE_ARRAY_STR("SimpleTypeArray");
  189. static const char* XSD_TOTAL_DIGITS_STR("TotalDigits");
  190. static const char* XSD_UNIQUE_STR("Unique");
  191. static const char* XSD_UNIQUE_ARRAY_STR("UniqueArray");
  192. static const char* XSD_WHITE_SPACE_STR("WhiteSpace");
  193. static const char* XSD_DT_NORMALIZED_STRING_STR("NormalizedString");
  194. static const char* XSD_DT_STRING_STR("String");
  195. static const char* XSD_DT_TOKEN_STR("Token");
  196. static const char* XSD_DT_DATE_STR("Date");
  197. static const char* XSD_DT_TIME_STR("Time");
  198. static const char* XSD_DT_DATE_TIME_STR("DateTime");
  199. static const char* XSD_DT_DECIMAL_STR("Decimal");
  200. static const char* XSD_DT_INTEGER_STR("Integer");
  201. static const char* XSD_DT_INT_STR("Int");
  202. static const char* XSD_DT_LONG_STR("Long");
  203. static const char* XSD_DT_NON_NEG_INTEGER_STR("NonNegativeInteger");
  204. static const char* XSD_DT_NON_POS_INTEGER_STR("NonPositiveInteger");
  205. static const char* XSD_DT_POS_INTEGER_STR("PositiveInteger");
  206. static const char* XSD_DT_NEG_INTEGER_STR("NegativeInteger");
  207. static const char* XSD_DT_BOOLEAN_STR("Boolean");
  208. static const char* XML_ENV_VALUE_OPTIONAL("optional");
  209. static const char* XML_ENV_VALUE_REQUIRED("required");
  210. static const char* XML_ATTR_DEFAULT("@default");
  211. static const char* XML_ATTR_USE("@use");
  212. static const char* XML_ATTR_MINOCCURS("@minOccurs");
  213. static const char* XML_ATTR_BASE("@base");
  214. static const char* XML_ATTR_XPATH("@xpath");
  215. static const char* XML_ATTR_REFER("@refer");
  216. static const char* TAG_VIEWCHILDNODES("viewChildNodes");
  217. static const char* TAG_VIEWTYPE("viewType");
  218. static const char* TAG_TOOLTIP("tooltip");
  219. static const char* TAG_COLINDEX("colIndex");
  220. static const char* TAG_TITLE("title");
  221. static const char* TAG_WIDTH("width");
  222. static const char* TAG_AUTOGENWIZARD("autogenforwizard");
  223. static const char* TAG_AUTOGENDEFAULTVALUE("autogendefaultvalue");
  224. static const char* TAG_AUTOGENDEFAULTVALUEFORMULTINODE("autogendefaultformultinode");
  225. static const char* TAG_XPATH("xpath");
  226. static const char* TAG_DOC_ID("docid");
  227. static const char* TAG_DOC_USE_LINE_BREAK("docuselinebreak");
  228. static const char* TAG_REQUIRED("required");
  229. static const char* TAG_UNBOUNDED("unbounded");
  230. #define TAG_OPTIONAL "optional"
  231. #define TAG_REQUIRED "required"
  232. #define XML_ATTR_ATTRIBUTEFORMDEFAULT "@attributeFormDefault"
  233. #define XML_ATTR_ELEMENTFORMDEFAULT "@elementFormDefault"
  234. #define XML_ATTR_ID "@id"
  235. #define XML_ATTR_REF "@ref"
  236. #define XML_ATTR_XMLNS_XS "@xmlns:xs"
  237. #define XML_ATTR_SCHEMA_LOCATION "@schemaLocation"
  238. #define XML_ATTR_VALUE "@value"
  239. #define XML_ATTR_OVERRIDE "@overide" // intentionally misspelled
  240. #define XML_ATTR_DEPLOYABLE "@deployable"
  241. static unsigned int STANDARD_OFFSET_1 = 3;
  242. static unsigned int STANDARD_OFFSET_2 = 6;
  243. static unsigned int STANDARD_OFFSET_3 = 9;
  244. static void quickOutPad(::std::ostream& cout, unsigned int offset)
  245. {
  246. while(offset > 0)
  247. {
  248. cout << " ";
  249. offset--;
  250. }
  251. }
  252. static void quickOutPad(::StringBuffer &str, unsigned int offset)
  253. {
  254. while(offset > 0)
  255. {
  256. str.append(" ");
  257. offset--;
  258. }
  259. }
  260. static void quickOutHeader(::std::ostream &cout, const char* pLabel, unsigned int offset = 0)
  261. {
  262. quickOutPad(cout,offset);
  263. cout << "\033[32m-- " << pLabel << " START" << " --" << "\033[0m" << ::std::endl;
  264. }
  265. static void quickOutFooter(::std::ostream &cout, const char* pLabel, unsigned int offset = 0)
  266. {
  267. quickOutPad(cout,offset);
  268. //cout << "<--- FINISH " << pLabel << ::std::endl;
  269. cout << "\033[31m" << "-- " << pLabel << " FINISH" << " --" << "\033[0m" << ::std::endl;
  270. }
  271. static void quickOut(::std::ostream &cout, const char* pLabel, const char* pValue, unsigned int offset = 0)
  272. {
  273. if (pLabel && strlen(pValue) > 0)
  274. {
  275. quickOutPad(cout,offset+STANDARD_OFFSET_2);
  276. cout << "\033[34m" << pLabel << ":\t\033[0m" << "\033[34m'\033[0m" << pValue << "\033[34m'" << "\033[0m" << ::std::endl;
  277. }
  278. }
  279. static void quickOut(::std::ostream &cout, const char* pLabel, int value, unsigned int offset = 0)
  280. {
  281. quickOutPad(cout,offset);
  282. cout << pLabel << ": " << value << ::std::endl;
  283. }
  284. static const char* stripTrailingIndex(StringBuffer& strXPath) // should this replace int CConfigSchemaHelper::stripXPathIndex(StringBuffer &strXPath)?
  285. {
  286. if (strXPath.length() == 0 || strXPath[strXPath.length()-1] != ']')
  287. return strXPath.str();
  288. while (1)
  289. {
  290. if (strXPath[strXPath.length()-1] == '[')
  291. {
  292. strXPath.setLength(strXPath.length()-1);
  293. break;
  294. }
  295. strXPath.setLength(strXPath.length()-1);
  296. }
  297. return strXPath.str();
  298. }
  299. class CXSDNodeBase
  300. {
  301. public:
  302. CXSDNodeBase(CXSDNodeBase* pParentNode = nullptr, NODE_TYPES eNodeType = XSD_ERROR);
  303. virtual ~CXSDNodeBase();
  304. GETTERSETTER(XSDXPath)
  305. GETTERSETTER(EnvXPath)
  306. //GETTERSETTER(EnvValueFromXML)
  307. virtual const char* getEnvValueFromXML() const
  308. {
  309. return m_strEnvValueFromXML;
  310. }
  311. virtual bool setEnvValueFromXML(const char* p)
  312. {
  313. if (p != nullptr)
  314. {
  315. m_strEnvValueFromXML.set(p);
  316. return true;
  317. }
  318. return false;
  319. }
  320. void dumpStdOut() const;
  321. virtual CXSDNodeBase* getParentNode() const
  322. {
  323. return m_pParentNode;
  324. }
  325. virtual const CXSDNodeBase* getConstAncestorNode(unsigned iLevel) const;
  326. virtual const CXSDNodeBase* getConstParentNode() const
  327. {
  328. return m_pParentNode;
  329. }
  330. virtual const CXSDNodeBase* getParentNodeByType(NODE_TYPES eNodeType[], const CXSDNodeBase *pParent = nullptr, int length = 1) const;
  331. virtual const CXSDNodeBase* getParentNodeByType(NODE_TYPES eNodeType, const CXSDNodeBase *pParent = nullptr) const;
  332. virtual const CXSDNodeBase* getNodeByTypeAndNameAscending(NODE_TYPES eNodeType[], const char *pName, int length = 1) const;
  333. virtual const CXSDNodeBase* getNodeByTypeAndNameAscending(NODE_TYPES eNodeType, const char *pName) const
  334. {
  335. if (this->getNodeType() == eNodeType)
  336. return this;
  337. else
  338. return this->getConstParentNode()->getNodeByTypeAndNameAscending(eNodeType, pName);
  339. }
  340. virtual const CXSDNodeBase* getNodeByTypeAndNameDescending(NODE_TYPES eNodeType[], const char *pName, int length = 1) const;
  341. virtual const CXSDNodeBase* getNodeByTypeAndNameDescending(NODE_TYPES eNodeType, const char *pName) const
  342. {
  343. return getNodeByTypeAndNameDescending(&eNodeType, pName);
  344. }
  345. void setParentNode(CXSDNodeBase *pParentNode)
  346. {
  347. if (m_pParentNode == nullptr) // Should only be set once, otherwise it's an external schema and should have parent set
  348. {
  349. m_pParentNode = pParentNode;
  350. }
  351. }
  352. const char* getNodeTypeStr() const
  353. {
  354. return m_pNodeType;
  355. }
  356. virtual NODE_TYPES getNodeType() const
  357. {
  358. return m_eNodeType;
  359. }
  360. virtual void dump(::std::ostream& cout, unsigned int offset = 0) const = 0;
  361. virtual const char* getXML(const char* /*pComponent*/)
  362. {
  363. return nullptr;
  364. }
  365. virtual void getDocumentation(::StringBuffer &strDoc) const = 0;
  366. virtual void populateEnvXPath(::StringBuffer strXPath, unsigned int index = 1)
  367. {
  368. }
  369. virtual void loadXMLFromEnvXml(const ::IPropertyTree *pEnvTree)
  370. {
  371. }
  372. protected:
  373. CXSDNodeBase* m_pParentNode;
  374. ::StringBuffer m_strXML;
  375. NODE_TYPES m_eNodeType;
  376. char m_pNodeType[1024];
  377. StringBuffer m_strEnvValueFromXML;
  378. private:
  379. };
  380. class CXSDNode : public CInterface, public CXSDNodeBase
  381. {
  382. public:
  383. IMPLEMENT_IINTERFACE
  384. CXSDNode(CXSDNodeBase *pParentNode, NODE_TYPES pNodeType = XSD_ERROR );
  385. virtual bool checkSelf(NODE_TYPES eNodeType, const char *pName, const char* pCompName) const;
  386. virtual const CXSDNodeBase* getParentNodeByType(NODE_TYPES eNodeType) const;
  387. private:
  388. };
  389. template<class T>
  390. class CXSDNodeWithRestrictions : public CXSDNode
  391. {
  392. public:
  393. CXSDNodeWithRestrictions(CXSDNodeBase* pParentNode, enum NODE_TYPES eNodeType) : CXSDNode::CXSDNode(pParentNode)
  394. {
  395. }
  396. static T* load(CXSDNodeBase* pParentNode, const ::IPropertyTree *pSchemaRoot, const char* xpath)
  397. {
  398. assert(pSchemaRoot != nullptr);
  399. if (pSchemaRoot == nullptr)
  400. return nullptr;
  401. T *pT = nullptr;
  402. if (xpath != nullptr && *xpath != 0)
  403. {
  404. ::IPropertyTree* pTree = pSchemaRoot->queryPropTree(xpath);
  405. if (pTree == nullptr)
  406. return nullptr;
  407. pT = new T(pParentNode);
  408. const char* pValue = pTree->queryProp(XML_ATTR_VALUE);
  409. if (pValue != nullptr && *pValue != 0)
  410. pT->setValue(pValue);
  411. else
  412. {
  413. assert(!"No Value set");
  414. //TODO: throw? and delete?
  415. }
  416. pT->setXSDXPath(xpath);
  417. }
  418. return pT;
  419. }
  420. void dump(::std::ostream& cout, unsigned int offset) const
  421. {
  422. offset += STANDARD_OFFSET_1;
  423. quickOutHeader(cout, XSD_MIN_INCLUSIVE_STR, offset);
  424. QUICK_OUT(cout, Value, offset);
  425. quickOutFooter(cout, XSD_MIN_INCLUSIVE_STR, offset);
  426. }
  427. virtual void getDocumentation(::StringBuffer &strDoc) const
  428. {
  429. UNIMPLEMENTED;
  430. }
  431. virtual const char* getXML(const char* /*pComponent*/)
  432. {
  433. UNIMPLEMENTED;
  434. return nullptr;
  435. }
  436. virtual void populateEnvXPath(::StringBuffer strXPath, unsigned int index = 1)
  437. {
  438. UNIMPLEMENTED;
  439. }
  440. virtual void loadXMLFromEnvXml(const ::IPropertyTree *pEnvTree)
  441. {
  442. UNIMPLEMENTED;
  443. }
  444. GETTERSETTER(Value)
  445. };
  446. class CXSDNodeWithType : public CXSDNode
  447. {
  448. GETTERSETTER(Type)
  449. public:
  450. CXSDNodeWithType(CXSDNodeBase* pParentNode, enum NODE_TYPES eNodeType) : CXSDNode::CXSDNode(pParentNode, eNodeType), m_pXSDNode(nullptr)
  451. {
  452. }
  453. virtual void loadXMLFromEnvXml(const ::IPropertyTree *pEnvTree)
  454. {
  455. UNIMPLEMENTED_X("Should be implemented in the derived class");
  456. }
  457. void setTypeNode(CXSDNode* pCXSDNode)
  458. {
  459. m_pXSDNode = pCXSDNode;
  460. }
  461. const CXSDNode* getTypeNode() const
  462. {
  463. return m_pXSDNode;
  464. }
  465. protected:
  466. CXSDNode *m_pXSDNode;
  467. };
  468. class CXSDNodeWithBase : public CXSDNode
  469. {
  470. GETTERSETTER(Base)
  471. public:
  472. CXSDNodeWithBase(CXSDNodeBase* pParentNode, enum NODE_TYPES eNodeType) : CXSDNode::CXSDNode(pParentNode, eNodeType), m_pXSDNode(nullptr)
  473. {
  474. }
  475. void setBaseNode(CXSDNodeBase* pCXSDNode)
  476. {
  477. m_pXSDNode = pCXSDNode;
  478. }
  479. const CXSDNodeBase* getBaseNode() const
  480. {
  481. return m_pXSDNode;
  482. }
  483. protected:
  484. CXSDNodeBase *m_pXSDNode;
  485. };
  486. class CXSDBuiltInDataType : public CXSDNode
  487. {
  488. public:
  489. static CXSDBuiltInDataType* create(CXSDNodeBase* pParentNode, const char* pNodeType);
  490. virtual ~CXSDBuiltInDataType();
  491. virtual void loadXMLFromEnvXml(const ::IPropertyTree *pEnvTree);
  492. virtual void dump(::std::ostream& cout, unsigned int offset = 0) const;
  493. virtual void getDocumentation(::StringBuffer &strDoc) const;
  494. virtual bool checkConstraint(const char *pValue) const;
  495. private:
  496. CXSDBuiltInDataType(CXSDNodeBase* pParentNode = nullptr, NODE_TYPES eNodeType = XSD_ERROR);
  497. CXSDBuiltInDataType(CXSDNodeBase* pParentNode, const char* pNodeType);
  498. };
  499. }
  500. #endif // _SCHEMA_COMMON_HPP_