rad  3.0.0
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 
65 {
66  public:
68  ~DOMSCXMLReader();
72  bool read(const std::string& filename,
73  std::list<Action*>* actions,
74  std::list<Activity*>* activities,
75  StateMachine& sm);
76  bool read(const std::string& input,
77  const std::string& id,
78  std::list<Action*>* actions,
79  std::list<Activity*>* activities,
80  StateMachine& sm);
81 
82  private:
83  std::list<DOMElement*> mStates;
84  std::list<Action*>* mActions;
85  std::list<Activity*>* mActivities;
86  std::list<Action*> mTraces;
87 
88  DOMDocument* mDoc;
89  XercesDOMParser* mDomParser;
90  ErrorHandler* mErrHandler;
91 
92  XMLCh* XML_SCXML;
93  XMLCh* XML_INITIAL;
94  XMLCh* XML_STATE;
95  XMLCh* XML_PARALLEL;
96  XMLCh* XML_FINAL;
97  XMLCh* XML_ONENTRY;
98  XMLCh* XML_ONEXIT;
99  XMLCh* XML_TRANSITION;
100  XMLCh* XML_HISTORY;
101  XMLCh* XML_INVOKE;
102 
103  // SCXML Element's attributes names
104  XMLCh* XML_ATTR_INITIAL;
105  XMLCh* XML_ATTR_NAME;
106  /*
107  XMLCh* XML_ATTR_XMLNS = "xmlns";
108  XMLCh* XML_ATTR_VERSION = "version";
109  XMLCh* XML_ATTR_PROFILE = "profile";
110  XMLCh* XML_ATTR_EXMODE = "exmode";
111  */
112  XMLCh* XML_ATTR_ID;
113  XMLCh* XML_ATTR_EVENT;
114  XMLCh* XML_ATTR_COND;
115  XMLCh* XML_ATTR_TARGET;
116  XMLCh* XML_ATTR_TYPE;
117  /*
118  XMLCh* XML_ATTR_LABEL = "label";
119  XMLCh* XML_ATTR_EXPR = "expr";
120  XMLCh* XML_ATTR_LEVEL = "level";
121  XMLCh* XML_ATTR_ANCHOR = "anchor";
122  */
123  // Custom Element name (extension to the SCXML Executable Content)
124  XMLCh* XML_ACTION;
125  XMLCh* XML_ATTR_ACTION_NAME;
126  XMLCh* XML_ATTR_ACTION_PARAM;
127 
128  XMLCh* SCXML_HISTORY_DEEP;
129  XMLCh* SCXML_HISTORY_SHALLOW;
130  XMLCh* USER_DATA_KEY_STATE;
131  XMLCh* DEFAULT_SCXML_NAME;
132 
133 
134  void addTraces(State* s);
135  void delTraces();
136 
137  void parseActivities();
138  void parseActions(const XMLCh*);
139  void resolveInitialStates(StateMachine& sm);
140  Action* findAction(const XMLCh*);
141  DOMNodeList* findCustomActionXMLElement(DOMElement* elementList);
142  Activity* findActivity(const XMLCh*);
143  State* findTargetState(const XMLCh*);
144  void parseTransitions(StateMachine& sm);
145  void resolveParents(StateMachine& sm);
146  void resolveHistory();
147  bool isStateCompound(DOMElement*);
148  void parseStates();
152  void parseDoc(StateMachine& sm);
153 
155  DOMSCXMLReader& operator= (const DOMSCXMLReader&);
156 };
157 
158 } // namespace scxml4cpp
159 
160 #endif // SCXML4CPP_DOMSCXMLREADER_H
scxml4cpp
Definition: Action.h:36
scxml4cpp::SCXMLReader
Definition: SCXMLReader.h:42
scxml4cpp::Activity
Definition: Activity.h:40
scxml4cpp::StateMachine
Definition: StateMachine.h:45
scxml4cpp::State
Definition: State.h:48
scxml4cpp::Action
Definition: Action.h:41
scxml4cpp::DOMSCXMLReader
Definition: DOMSCXMLReader.h:65