XmlReader.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::
17 * @author Christian Mandery (christian.mandery at kit dot edu)
18 * @date 2014
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #pragma once
24 
25 #include "../../StatechartViewerPlugin/model/State.h"
26 
31 
32 namespace armarx::statechartio
33 {
34  /**
35  * @class XmlReader
36  * @brief XML reader class used to build State objects from XML representations.
37  */
38  class XmlReader
39  {
40  public:
41  /**
42  * Creates a new XmlReader. The ICE communicator is required for deserialization of parameter default values from JSON.
43  * @param iceCommunicator Ice communicator.
44  */
45  XmlReader(Ice::CommunicatorPtr iceCommunicator, VariantInfoPtr info);
46 
47  /**
48  * Parses the given XML document and builds a State object (that can be retrieved using getRootState()).
49  * The State object will not contain references to other states until addReferences() has been called.
50  * @param xmlString XML document to parse.
51  */
52  void parseXml(const QString& xmlString);
53 
54  /**
55  * Returns the State object created by this XML reader.
56  * @return State object.
57  */
59  {
60  return loadedState;
61  }
62 
63  private:
64  QString readDescription(rapidxml::xml_node<>* rootNode) const;
65  armarx::statechartmodel::EventList readEventList(rapidxml::xml_node<>* eventListNode) const;
66  armarx::statechartmodel::StateParameterMap readParameterList(rapidxml::xml_node<>* parameterListNode) const;
67  armarx::statechartmodel::ParameterMappingList readParameterMappingList(rapidxml::xml_node<>* parameterMappingListNode) const;
68  void readStartState(rapidxml::xml_node<>* startStateNode) const;
69  armarx::statechartmodel::StateInstanceMap readSubstateList(rapidxml::xml_node<>* substateListNode) const;
70  armarx::statechartmodel::TransitionList readTransitionList(rapidxml::xml_node<>* transitionListNode) const;
71 
72  armarx::statechartmodel::StateInstancePtr getSubstateByInstanceName(const QString& name) const;
73 
74  QString readAttribute(rapidxml::xml_node<>* node, const QString& attributeName, bool required = true) const;
75 
76  Ice::CommunicatorPtr iceCommunicator;
77  VariantInfoPtr info;
79  bool hasSubstateByInstanceName(const QString& name) const;
80  };
81 
82  /**
83  * @class XmlNodeIterator
84  * @brief Iterate over all child nodes with a certain name of a given XML node.
85  */
87  {
88  public:
89  XmlNodeIterator(rapidxml::xml_node<>* parentNode, const QString& nodeName, bool required);
90 
92 
93  private:
94  rapidxml::xml_node<>* parentNode, *currentChildNode;
95  const QString& nodeName;
96  const QByteArray nodeNameUtf8;
97  bool required;
98  };
99 }
100 
102 {
103  class XmlReaderException : public LocalException
104  {
105  public:
106  XmlReaderException(const std::string& errorText) : LocalException("Parsing the XML file failed: " + errorText) {}
107  std::string name() const override
108  {
109  return "armarx::exceptions::local::XmlReaderException";
110  }
111  };
112 }
113 
armarx::statechartio::XmlReader::XmlReader
XmlReader(Ice::CommunicatorPtr iceCommunicator, VariantInfoPtr info)
Creates a new XmlReader.
Definition: XmlReader.cpp:38
armarx::exceptions::local::XmlReaderException
Definition: XmlReader.h:103
armarx::statechartio
Definition: StateInstanceFactory.h:31
armarx::statechartmodel::EventList
QList< EventPtr > EventList
Definition: XmlWriter.h:47
armarx::statechartio::XmlReader::parseXml
void parseXml(const QString &xmlString)
Parses the given XML document and builds a State object (that can be retrieved using getRootState()).
Definition: XmlReader.cpp:42
armarx::statechartmodel::StateInstancePtr
std::shared_ptr< StateInstance > StateInstancePtr
Definition: StateInstance.h:138
armarx::statechartio::XmlReader::getLoadedState
armarx::statechartmodel::StatePtr getLoadedState() const
Returns the State object created by this XML reader.
Definition: XmlReader.h:58
IceInternal::Handle< ::Ice::Communicator >
armarx::statechartmodel::StateInstanceMap
QMap< QString, StateInstancePtr > StateInstanceMap
Definition: State.h:50
armarx::exceptions::local
Definition: DynamicLibraryException.h:31
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::exceptions::local::XmlReaderException::name
std::string name() const override
Definition: XmlReader.h:107
IceManager.h
armarx::statechartmodel::TransitionList
QList< TransitionPtr > TransitionList
Definition: State.h:48
rapidxml::xml_node
Class representing a node of XML document.
Definition: rapidxml.hpp:138
armarx::statechartio::XmlNodeIterator
Iterate over all child nodes with a certain name of a given XML node.
Definition: XmlReader.h:86
armarx::exceptions::local::XmlReaderException::XmlReaderException
XmlReaderException(const std::string &errorText)
Definition: XmlReader.h:106
armarx::VariantInfoPtr
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition: VariantInfo.h:39
armarx::statechartmodel::ParameterMappingList
QList< ParameterMappingPtr > ParameterMappingList
Definition: XmlWriter.h:49
armarx::statechartmodel::StatePtr
std::shared_ptr< State > StatePtr
Definition: State.h:46
armarx::statechartio::XmlReader
XML reader class used to build State objects from XML representations.
Definition: XmlReader.h:38
rapidxml.hpp
Exception.h
armarx::statechartio::XmlNodeIterator::getNext
rapidxml::xml_node * getNext()
Definition: XmlReader.cpp:571
VariantInfo.h
armarx::statechartio::XmlNodeIterator::XmlNodeIterator
XmlNodeIterator(rapidxml::xml_node<> *parentNode, const QString &nodeName, bool required)
Definition: XmlReader.cpp:564