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 
29 
30 #include "../../StatechartViewerPlugin/model/State.h"
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  */
60  {
61  return loadedState;
62  }
63 
64  private:
65  QString readDescription(rapidxml::xml_node<>* rootNode) const;
66  armarx::statechartmodel::EventList readEventList(rapidxml::xml_node<>* eventListNode) const;
68  readParameterList(rapidxml::xml_node<>* parameterListNode) const;
70  readParameterMappingList(rapidxml::xml_node<>* parameterMappingListNode) const;
71  void readStartState(rapidxml::xml_node<>* startStateNode) const;
73  readSubstateList(rapidxml::xml_node<>* substateListNode) const;
75  readTransitionList(rapidxml::xml_node<>* transitionListNode) const;
76 
78  getSubstateByInstanceName(const QString& name) const;
79 
80  QString readAttribute(rapidxml::xml_node<>* node,
81  const QString& attributeName,
82  bool required = true) const;
83 
84  Ice::CommunicatorPtr iceCommunicator;
85  VariantInfoPtr info;
87  bool hasSubstateByInstanceName(const QString& name) const;
88  };
89 
90  /**
91  * @class XmlNodeIterator
92  * @brief Iterate over all child nodes with a certain name of a given XML node.
93  */
95  {
96  public:
97  XmlNodeIterator(rapidxml::xml_node<>* parentNode, const QString& nodeName, bool required);
98 
100 
101  private:
102  rapidxml::xml_node<>*parentNode, *currentChildNode;
103  const QString& nodeName;
104  const QByteArray nodeNameUtf8;
105  bool required;
106  };
107 } // namespace armarx::statechartio
108 
110 {
111  class XmlReaderException : public LocalException
112  {
113  public:
114  XmlReaderException(const std::string& errorText) :
115  LocalException("Parsing the XML file failed: " + errorText)
116  {
117  }
118 
119  std::string
120  name() const override
121  {
122  return "armarx::exceptions::local::XmlReaderException";
123  }
124  };
125 } // namespace armarx::exceptions::local
armarx::statechartio::XmlReader::XmlReader
XmlReader(Ice::CommunicatorPtr iceCommunicator, VariantInfoPtr info)
Creates a new XmlReader.
Definition: XmlReader.cpp:39
armarx::exceptions::local::XmlReaderException
Definition: XmlReader.h:111
armarx::statechartio
Definition: StateInstanceFactory.h:30
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:45
armarx::statechartmodel::StateInstancePtr
std::shared_ptr< StateInstance > StateInstancePtr
Definition: StateInstance.h:146
armarx::statechartio::XmlReader::getLoadedState
armarx::statechartmodel::StatePtr getLoadedState() const
Returns the State object created by this XML reader.
Definition: XmlReader.h:59
IceInternal::Handle<::Ice::Communicator >
armarx::statechartmodel::StateInstanceMap
QMap< QString, StateInstancePtr > StateInstanceMap
Definition: State.h:52
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:120
IceManager.h
armarx::statechartmodel::TransitionList
QList< TransitionPtr > TransitionList
Definition: State.h:50
rapidxml::xml_node
Class representing a node of XML document.
Definition: rapidxml.hpp:140
armarx::statechartio::XmlNodeIterator
Iterate over all child nodes with a certain name of a given XML node.
Definition: XmlReader.h:94
armarx::exceptions::local::XmlReaderException::XmlReaderException
XmlReaderException(const std::string &errorText)
Definition: XmlReader.h:114
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:48
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:627
VariantInfo.h
armarx::statechartio::XmlNodeIterator::XmlNodeIterator
XmlNodeIterator(rapidxml::xml_node<> *parentNode, const QString &nodeName, bool required)
Definition: XmlReader.cpp:615