Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 1 | /* |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 2 | * INTEL CONFIDENTIAL |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 3 | * Copyright © 2013 Intel |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 4 | * Corporation All Rights Reserved. |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 5 | * |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 6 | * The source code contained or described herein and all documents related to |
| 7 | * the source code ("Material") are owned by Intel Corporation or its suppliers |
| 8 | * or licensors. Title to the Material remains with Intel Corporation or its |
| 9 | * suppliers and licensors. The Material contains trade secrets and proprietary |
| 10 | * and confidential information of Intel or its suppliers and licensors. The |
| 11 | * Material is protected by worldwide copyright and trade secret laws and |
| 12 | * treaty provisions. No part of the Material may be used, copied, reproduced, |
| 13 | * modified, published, uploaded, posted, transmitted, distributed, or |
| 14 | * disclosed in any way without Intel’s prior express written permission. |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 15 | * |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 16 | * No license under any patent, copyright, trade secret or other intellectual |
| 17 | * property right is granted to or conferred upon you by disclosure or delivery |
| 18 | * of the Materials, either expressly, by implication, inducement, estoppel or |
| 19 | * otherwise. Any license under such intellectual property rights must be |
| 20 | * express and approved by Intel in writing. |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 21 | */ |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 22 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 23 | #pragma once |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 24 | #include "XmlElement.h" |
| 25 | #include "XmlSerializingContext.h" |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 26 | #include <string> |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 27 | |
| 28 | struct _xmlDoc; |
| 29 | struct _xmlNode; |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 30 | struct _xmlError; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 31 | |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 32 | /** |
| 33 | * The CXmlDocSource is used by CXmlDocSink. |
| 34 | * The interaction between the xml source and xml sink is defined |
| 35 | * in the process method of CXmlDocSink. One can subclass CXmlDocSource |
| 36 | * for different purposes by implementing the populate method and then |
| 37 | * use it with any existing implementation of CXmlDocSink. |
| 38 | */ |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 39 | class CXmlDocSource |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 40 | { |
| 41 | public: |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 42 | /** |
| 43 | * Constructor |
| 44 | * |
| 45 | * @param[out] pDoc a pointer to the xml document that will be filled by the class |
| 46 | * @param[in] pRootNode a pointer to the root element of the document. |
| 47 | */ |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 48 | CXmlDocSource(_xmlDoc* pDoc, _xmlNode* pRootNode = NULL); |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 49 | |
| 50 | /** |
| 51 | * Constructor |
| 52 | * |
| 53 | * @param[out] pDoc a pointer to the xml document that will be filled by the class |
| 54 | * @param[in] strXmlSchemaFile a string containing the path to the schema file |
| 55 | * @param[in] strRootElementType a string containing the root element type |
| 56 | * @param[in] strRootElementName a string containing the root element name |
| 57 | * @param[in] strNameAttributeName a string containing the name of the root name attribute |
| 58 | */ |
| 59 | CXmlDocSource(_xmlDoc* pDoc, |
| 60 | const string& strXmlSchemaFile, |
| 61 | const string& strRootElementType, |
| 62 | const string& strRootElementName, |
| 63 | const string& strNameAttrituteName); |
| 64 | |
| 65 | /** |
| 66 | * Constructor |
| 67 | * |
| 68 | * @param[out] pDoc a pointer to the xml document that will be filled by the class |
| 69 | * @param[in] strXmlSchemaFile a string containing the path to the schema file |
| 70 | * @param[in] strRootElementType a string containing the root element type |
| 71 | */ |
| 72 | CXmlDocSource(_xmlDoc* pDoc, const string& strXmlSchemaFile, const string& strRootElementType); |
| 73 | |
| 74 | /** |
| 75 | * Destructor |
| 76 | */ |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 77 | virtual ~CXmlDocSource(); |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 78 | |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 79 | /** |
| 80 | * Method called by the CXmlDocSink::process method. |
| 81 | * |
| 82 | * @param[out] serializingContext is used as error output |
| 83 | * |
| 84 | * @return false if there are any error |
| 85 | */ |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 86 | virtual bool populate(CXmlSerializingContext& serializingContext) = 0; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 87 | |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 88 | /** |
| 89 | * Method that returns the root element of the Xml tree. |
| 90 | * |
| 91 | * @param[out] xmlRootElement a reference to the CXmleElement destination |
| 92 | */ |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 93 | void getRootElement(CXmlElement& xmlRootElement) const; |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 94 | |
| 95 | /** |
| 96 | * Getter method. |
| 97 | * |
| 98 | * @return the root element's name |
| 99 | */ |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 100 | string getRootElementName() const; |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 101 | |
| 102 | /** |
| 103 | * Getter method. |
| 104 | * Method that returns the root element's attribute with name matching strAttributeName. |
| 105 | * |
| 106 | * @param[in] strAttributeName is a string used to find the corresponding attribute |
| 107 | * |
| 108 | * @return the value of the root's attribute named as strAttributeName |
| 109 | */ |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 110 | string getRootElementAttributeString(const string& strAttributeName) const; |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 111 | |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 112 | /** |
| 113 | * Getter method. |
| 114 | * Method that returns the xmlDoc contained in the Source. |
| 115 | * (Can be used in a Doc Sink) |
| 116 | * |
| 117 | * @return the document _pDoc |
| 118 | */ |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 119 | _xmlDoc* getDoc() const; |
| 120 | |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 121 | /** |
| 122 | * Method that validates the Xml doc contained in pDoc |
| 123 | * |
| 124 | * @param[out] serializingContext is used as error output |
| 125 | * |
| 126 | * @return false if any error occurs |
| 127 | */ |
| 128 | virtual bool validate(CXmlSerializingContext& serializingContext); |
| 129 | |
Georges-Henri Baron | 326a31d | 2012-06-28 12:05:09 +0200 | [diff] [blame] | 130 | |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 131 | protected: |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 132 | |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 133 | /** |
| 134 | * Doc |
| 135 | */ |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 136 | _xmlDoc* _pDoc; |
| 137 | |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 138 | /** |
| 139 | * Root node |
| 140 | */ |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 141 | _xmlNode* _pRootNode; |
| 142 | |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 143 | /** |
| 144 | * libxml2 library cleanup |
| 145 | */ |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 146 | static bool _bLibXml2CleanupScheduled; |
Georges-Henri Baron | cec86c1 | 2012-09-04 17:30:28 +0200 | [diff] [blame^] | 147 | |
| 148 | private: |
| 149 | |
| 150 | /** |
| 151 | * Method that initializes class internal attributes in constructor |
| 152 | */ |
| 153 | void init(); |
| 154 | |
| 155 | /** Method that check the validity of the document with the xsd file. |
| 156 | * |
| 157 | * @return true if document is valid, false if any error occures |
| 158 | */ |
| 159 | bool isInstanceDocumentValid(); |
| 160 | |
| 161 | /** Validity error display method |
| 162 | * |
| 163 | * @param[in] pUserData pointer to the data to validate |
| 164 | * @param[out] pError is the xml error output |
| 165 | */ |
| 166 | static void schemaValidityStructuredErrorFunc(void* pUserData, _xmlError* pError); |
| 167 | |
| 168 | /** |
| 169 | * Schema file |
| 170 | */ |
| 171 | string _strXmlSchemaFile; |
| 172 | |
| 173 | /** |
| 174 | * Element type info |
| 175 | */ |
| 176 | string _strRootElementType; |
| 177 | |
| 178 | /** |
| 179 | * Element name info |
| 180 | */ |
| 181 | string _strRootElementName; |
| 182 | |
| 183 | /** |
| 184 | * Element name attribute info |
| 185 | */ |
| 186 | string _strNameAttrituteName; |
| 187 | |
| 188 | /** |
| 189 | * Boolean that enables the root element name attribute check |
| 190 | */ |
| 191 | bool _bNameCheck; |
Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 192 | }; |