rad  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DOMSCXMLReader.h
Go to the documentation of this file.
1 /*
2  * scampl4cpp/parser
3  *
4  * Copyright by European Southern Observatory, 2012
5  * All rights reserved
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA.
21  */
22 
23 /*
24  * $Id: DOMSCXMLReader.h 1061 2015-07-13 15:03:59Z landolfa $
25  */
26 
27 #ifndef SCXML4CPP_DOMSCXMLREADER_H
28 #define SCXML4CPP_DOMSCXMLREADER_H
29 
30 #ifndef __cplusplus
31 #error This is a C++ include file and cannot be used from plain C
32 #endif
33 
34 #ifndef SCXML4CPP_SCXMLREADER_H
35 #include "scxml4cpp/SCXMLReader.h"
36 #endif
37 
38 #include <stdio.h>
39 #include <stdexcept>
40 
41 #include <xercesc/dom/DOM.hpp>
42 #include <xercesc/dom/DOMDocument.hpp>
43 #include <xercesc/dom/DOMDocumentType.hpp>
44 #include <xercesc/dom/DOMElement.hpp>
45 #include <xercesc/dom/DOMImplementation.hpp>
46 #include <xercesc/dom/DOMImplementationLS.hpp>
47 #include <xercesc/dom/DOMNodeIterator.hpp>
48 #include <xercesc/dom/DOMNodeList.hpp>
49 #include <xercesc/dom/DOMText.hpp>
50 #include <xercesc/sax/HandlerBase.hpp>
51 #include <xercesc/parsers/XercesDOMParser.hpp>
52 #include <xercesc/util/XMLUni.hpp>
53 
54 
55 using namespace xercesc;
56 
57 namespace scxml4cpp {
58 
59 class StateMachine;
60 class State;
61 class Action;
62 class Activity;
63 
64 class DOMSCXMLReader : public SCXMLReader
65 {
66  public:
67  DOMSCXMLReader();
68  ~DOMSCXMLReader();
72  bool read(const std::string& filename,
73  std::list<Action*>* actions,
74  std::list<Activity*>* activities,
75  StateMachine& sm);
76 
77  private:
78  std::list<DOMElement*> mStates;
79  std::list<Action*>* mActions;
80  std::list<Activity*>* mActivities;
81  std::list<Action*> mTraces;
82 
83  DOMDocument* mDoc;
84  XercesDOMParser* mDomParser;
85  ErrorHandler* mErrHandler;
86 
87  XMLCh* XML_SCXML;
88  XMLCh* XML_INITIAL;
89  XMLCh* XML_STATE;
90  XMLCh* XML_PARALLEL;
91  XMLCh* XML_FINAL;
92  XMLCh* XML_ONENTRY;
93  XMLCh* XML_ONEXIT;
94  XMLCh* XML_TRANSITION;
95  XMLCh* XML_HISTORY;
96  XMLCh* XML_INVOKE;
97 
98  // SCXML Element's attributes names
99  XMLCh* XML_ATTR_INITIAL;
100  XMLCh* XML_ATTR_NAME;
101  /*
102  XMLCh* XML_ATTR_XMLNS = "xmlns";
103  XMLCh* XML_ATTR_VERSION = "version";
104  XMLCh* XML_ATTR_PROFILE = "profile";
105  XMLCh* XML_ATTR_EXMODE = "exmode";
106  */
107  XMLCh* XML_ATTR_ID;
108  XMLCh* XML_ATTR_EVENT;
109  XMLCh* XML_ATTR_COND;
110  XMLCh* XML_ATTR_TARGET;
111  XMLCh* XML_ATTR_TYPE;
112  /*
113  XMLCh* XML_ATTR_LABEL = "label";
114  XMLCh* XML_ATTR_EXPR = "expr";
115  XMLCh* XML_ATTR_LEVEL = "level";
116  XMLCh* XML_ATTR_ANCHOR = "anchor";
117  */
118  // Custom Element name (extension to the SCXML Executable Content)
119  XMLCh* XML_ACTION;
120  XMLCh* XML_ATTR_ACTION_NAME;
121  XMLCh* XML_ATTR_ACTION_PARAM;
122 
123  XMLCh* SCXML_HISTORY_DEEP;
124  XMLCh* SCXML_HISTORY_SHALLOW;
125  XMLCh* USER_DATA_KEY_STATE;
126  XMLCh* DEFAULT_SCXML_NAME;
127 
128 
129  void addTraces(State* s);
130  void delTraces();
131 
132  void parseActivities();
133  void parseActions(const XMLCh*);
134  void resolveInitialStates(StateMachine& sm);
135  Action* findAction(const XMLCh*);
136  DOMNodeList* findCustomActionXMLElement(DOMElement* elementList);
137  Activity* findActivity(const XMLCh*);
138  State* findTargetState(const XMLCh*);
139  void parseTransitions(StateMachine& sm);
140  void resolveParents(StateMachine& sm);
141  void resolveHistory();
142  bool isStateCompound(DOMElement*);
143  void parseStates();
147  void parseDoc(StateMachine& sm);
148 
149  DOMSCXMLReader(const DOMSCXMLReader&);
150  DOMSCXMLReader& operator= (const DOMSCXMLReader&);
151 };
152 
153 } // namespace scxml4cpp
154 
155 #endif // SCXML4CPP_DOMSCXMLREADER_H