OpenASIP 2.2
Loading...
Searching...
No Matches
XMLSerializer.hh
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file XMLSerializer.hh
26 *
27 * Declaration of XMLSerializer class.
28 *
29 * @author Lasse Laasonen 2003 (lasse.laasonen-no.spam-tut.fi)
30 * @note reviewed 8 Jun 2004 by tr, jm, am, ll
31 * @note rating: red
32 */
33
34#ifndef TTA_XML_SERIALIZER_HH
35#define TTA_XML_SERIALIZER_HH
36
37#include <string>
38
39#include <xercesc/util/XercesVersion.hpp>
40
41#if XERCES_VERSION_MAJOR >= 3
42#include <xercesc/dom/DOMLSParser.hpp>
43#else
44#include <xercesc/dom/DOMBuilder.hpp>
45#endif
46#include <xercesc/dom/DOMDocument.hpp>
47
48#include "Serializable.hh"
49#include "Serializer.hh"
50#include "Exception.hh"
51
52#if _XERCES_VERSION >= 20200
53XERCES_CPP_NAMESPACE_USE
54#endif
55
56class ObjectState;
57
58/**
59 * This class is used to read and write XML. This is a base class for
60 * different kind of XML serializers.
61 */
63public:
65 virtual ~XMLSerializer();
66
67 void setSourceFile(const std::string& fileName);
68 void setSourceString(const std::string& source);
69
70 void setDestinationFile(const std::string& fileName);
71 void setDestinationString(std::string& destination);
72
73 void setSchemaFile(const std::string& fileName);
74 void setUseSchema(bool useSchema);
75
76 void setXMLNamespace(std::string nsUri);
77
78 virtual ObjectState* readState();
79
80 virtual void writeState(const ObjectState* rootState);
81
82protected:
83 std::string sourceFile() const;
84
85private:
86 /// Copying forbidden.
88 /// Assignment forbidden.
90
91 void initializeParser();
92
93 virtual ObjectState* readFile(const std::string& fileName);
94
95 virtual ObjectState* readString(const std::string& source);
96
97 virtual void writeFile(
98 const std::string& fileName, const ObjectState* rootState);
99
100 virtual void writeString(std::string& target, const ObjectState* rootState);
101
102 DOMDocument* createDOMDocument(const ObjectState* state) const;
103 void ensureValidStream(const std::string& fileName) const;
104
105 DOMElement* createDOM(
106 ObjectState* state,
107 DOMDocument* doc) const;
108 ObjectState* createState(const DOMNode* node) const;
109 bool hasChildElementNodes(const DOMNode* node) const;
110
111 /// Source file path.
112 std::string sourceFile_;
113 /// Destination file path.
114 std::string destinationFile_;
115 /// Schema file path.
116 std::string schemaFile_;
117 /// Indicates if xml file is validated using schema.
119 /// The parser that checks the XML file for errors with the Schema.
120#if XERCES_VERSION_MAJOR >= 3
121 DOMLSParser* parser_;
122#else
123 DOMBuilder* parser_;
124#endif
125 /// Implementation of the DOM.
126 DOMImplementation* domImplementation_;
127
128 /// Source string to read.
129 const std::string* sourceString_;
130 /// Destination string to write.
131 std::string* destinationString_;
132
133 /// XML namespace URI
134 std::string nsUri_;
135};
136
137#endif
138
DOMImplementation * domImplementation_
Implementation of the DOM.
XMLSerializer & operator=(const XMLSerializer &)
Assignment forbidden.
const std::string * sourceString_
Source string to read.
DOMElement * createDOM(ObjectState *state, DOMDocument *doc) const
void setUseSchema(bool useSchema)
virtual void writeString(std::string &target, const ObjectState *rootState)
std::string schemaFile_
Schema file path.
bool useSchema_
Indicates if xml file is validated using schema.
bool hasChildElementNodes(const DOMNode *node) const
void setSourceString(const std::string &source)
void setSchemaFile(const std::string &fileName)
void ensureValidStream(const std::string &fileName) const
void setXMLNamespace(std::string nsUri)
virtual ObjectState * readString(const std::string &source)
void setSourceFile(const std::string &fileName)
std::string sourceFile() const
virtual ~XMLSerializer()
std::string sourceFile_
Source file path.
DOMDocument * createDOMDocument(const ObjectState *state) const
std::string destinationFile_
Destination file path.
virtual void writeState(const ObjectState *rootState)
void setDestinationFile(const std::string &fileName)
virtual ObjectState * readFile(const std::string &fileName)
DOMBuilder * parser_
The parser that checks the XML file for errors with the Schema.
XMLSerializer(const XMLSerializer &)
Copying forbidden.
std::string * destinationString_
Destination string to write.
void initializeParser()
virtual ObjectState * readState()
virtual void writeFile(const std::string &fileName, const ObjectState *rootState)
ObjectState * createState(const DOMNode *node) const
void setDestinationString(std::string &destination)
std::string nsUri_
XML namespace URI.