SchemaCommon.hpp 25 KB

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