rad  5.1.0
DOMSCXMLReader.h
Go to the documentation of this file.
1 
10 /*
11  * scampl4cpp/parser
12  *
13  * Copyright by European Southern Observatory, 2012
14  * All rights reserved
15  *
16  * This library is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU Lesser General Public
18  * License as published by the Free Software Foundation; either
19  * version 2.1 of the License, or (at your option) any later version.
20  *
21  * This library is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24  * Lesser General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public
27  * License along with this library; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29  * 02111-1307 USA.
30  */
31 
32 #ifndef SCXML4CPP_DOMSCXMLREADER_H
33 #define SCXML4CPP_DOMSCXMLREADER_H
34 
35 #ifndef __cplusplus
36 #error This is a C++ include file and cannot be used from plain C
37 #endif
38 
39 #ifndef SCXML4CPP_SCXMLREADER_H
40 #include "scxml4cpp/SCXMLReader.h"
41 #endif
42 
43 #ifndef SCXML4CPP_REPLACE_RULES_H
44 #include "scxml4cpp/ReplaceRules.h"
45 #endif
46 
47 #include <stdio.h>
48 //#include <stdexcept>
49 #include <vector>
50 #include <string>
51 
52 #include <xercesc/dom/DOM.hpp>
53 #include <xercesc/dom/DOMDocument.hpp>
54 #include <xercesc/dom/DOMDocumentType.hpp>
55 #include <xercesc/dom/DOMElement.hpp>
56 #include <xercesc/dom/DOMImplementation.hpp>
57 #include <xercesc/dom/DOMImplementationLS.hpp>
58 #include <xercesc/dom/DOMNodeIterator.hpp>
59 #include <xercesc/dom/DOMNodeList.hpp>
60 #include <xercesc/dom/DOMText.hpp>
61 #include <xercesc/sax/HandlerBase.hpp>
62 #include <xercesc/parsers/XercesDOMParser.hpp>
63 #include <xercesc/util/XMLUni.hpp>
64 
65 
66 using namespace xercesc;
67 
68 namespace scxml4cpp {
69 
70 class StateMachine;
71 class State;
72 class Action;
73 class Activity;
74 
80 {
81  public:
90 
97  ~DOMSCXMLReader();
98 
99 
110  bool read(const std::string& filename,
111  std::list<Action*>* actions,
112  std::list<Activity*>* activities,
113  StateMachine& sm);
114 
126  bool read(const std::string& input,
127  const std::string& id,
128  std::list<Action*>* actions,
129  std::list<Activity*>* activities,
130  StateMachine& sm);
131 
132 #if 0
133  void addReplaceRule(const ReplaceRules::ElementType elementType,
134  const std::string& srcId,
135  const std::string& dstId);
136 #endif
137  void setReplaceRules(const ReplaceRules& replaceRules);
138  void clearReplaceRules();
139 
140  const std::vector<std::string>& getWarnings() const;
141  void resetWarnings();
142 
143  private:
144  ReplaceRules mReplaceRules;
145 
146  std::vector<std::string> mWarnings;
147 
148  std::list<DOMElement*> mStates;
149  std::list<Action*>* mActions;
150  std::list<Activity*>* mActivities;
151  std::list<Action*> mTraces;
152 
153  DOMDocument* mDoc;
154  XercesDOMParser* mDomParser;
155  ErrorHandler* mErrHandler;
156 
157  XMLCh* XML_SCXML;
158  XMLCh* XML_INITIAL;
159  XMLCh* XML_STATE;
160  XMLCh* XML_PARALLEL;
161  XMLCh* XML_FINAL;
162  XMLCh* XML_ONENTRY;
163  XMLCh* XML_ONEXIT;
164  XMLCh* XML_TRANSITION;
165  XMLCh* XML_HISTORY;
166  XMLCh* XML_INVOKE;
167 
168  // SCXML Element's attributes names
169  XMLCh* XML_ATTR_INITIAL;
170  XMLCh* XML_ATTR_NAME;
171  /*
172  XMLCh* XML_ATTR_XMLNS = "xmlns";
173  XMLCh* XML_ATTR_VERSION = "version";
174  XMLCh* XML_ATTR_PROFILE = "profile";
175  XMLCh* XML_ATTR_EXMODE = "exmode";
176  */
177  XMLCh* XML_ATTR_ID;
178  XMLCh* XML_ATTR_EVENT;
179  XMLCh* XML_ATTR_COND;
180  XMLCh* XML_ATTR_TARGET;
181  XMLCh* XML_ATTR_TYPE;
182  /*
183  XMLCh* XML_ATTR_LABEL = "label";
184  XMLCh* XML_ATTR_EXPR = "expr";
185  XMLCh* XML_ATTR_LEVEL = "level";
186  XMLCh* XML_ATTR_ANCHOR = "anchor";
187  */
188  // Custom Element name (extension to the SCXML Executable Content)
189  XMLCh* XML_ACTION;
190  XMLCh* XML_ATTR_ACTION_NAME;
191  XMLCh* XML_ATTR_ACTION_PARAM;
192  XMLCh* XML_ALL;
193 
194  XMLCh* SCXML_HISTORY_DEEP;
195  XMLCh* SCXML_HISTORY_SHALLOW;
196  XMLCh* USER_DATA_KEY_STATE;
197  XMLCh* DEFAULT_SCXML_NAME;
198 
199  std::string buildWarningMsg(const std::string& str, const XMLCh* id);
200  void addWarning(const std::string& msg);
201 
202  void addTraces(State* s);
203  void delTraces();
204 
205  void parseActivities();
206  void parseActions(const XMLCh*);
207  void resolveInitialStates(StateMachine& sm);
208  Action* findAction(const XMLCh*);
209  Action* findGuard(const XMLCh*);
210  DOMNodeList* findCustomActionXMLElement(DOMElement* elementList);
211  Activity* findActivity(const XMLCh*);
212  State* findTargetState(const XMLCh*);
213  void parseTransitions(StateMachine& sm);
214  void resolveParents(StateMachine& sm);
215  void resolveHistory();
216  bool isStateCompound(DOMElement*);
217  void parseStates();
221  void parseDoc(StateMachine& sm);
222 
224  DOMSCXMLReader& operator= (const DOMSCXMLReader&);
225 };
226 
227 } // namespace scxml4cpp
228 
229 #endif // SCXML4CPP_DOMSCXMLREADER_H
ReplaceRules header.
SCXMLReader header.
Definition: Action.h:66
Definition: Activity.h:52
Definition: DOMSCXMLReader.h:80
Definition: ReplaceRules.h:53
ElementType
Definition: ReplaceRules.h:55
Definition: SCXMLReader.h:50
Definition: StateMachine.h:64
Definition: State.h:60
Definition: Action.h:40