summaryrefslogtreecommitdiffstats
path: root/src/uscxml/Message.cpp
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2012-09-16 00:12:32 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2012-09-16 00:12:32 (GMT)
commitd7211d570f8b78442f35bd9c55808053eb18ecc2 (patch)
tree5f670609b6486e8bf4cad19ca0967d51cb0becb4 /src/uscxml/Message.cpp
parentaa6c3a1257a29cc5bcf8b94893732ee553f27582 (diff)
downloaduscxml-d7211d570f8b78442f35bd9c55808053eb18ecc2.zip
uscxml-d7211d570f8b78442f35bd9c55808053eb18ecc2.tar.gz
uscxml-d7211d570f8b78442f35bd9c55808053eb18ecc2.tar.bz2
Implemented invoke for nested SCXML instances
Diffstat (limited to 'src/uscxml/Message.cpp')
-rw-r--r--src/uscxml/Message.cpp62
1 files changed, 61 insertions, 1 deletions
diff --git a/src/uscxml/Message.cpp b/src/uscxml/Message.cpp
index 3d3048b..f7e7a5a 100644
--- a/src/uscxml/Message.cpp
+++ b/src/uscxml/Message.cpp
@@ -1,4 +1,5 @@
#include "uscxml/Message.h"
+//#include "uscxml/Interpreter.h"
#include <DOM/SAX2DOM/SAX2DOM.hpp>
#include <SAX/helpers/CatchErrorHandler.hpp>
@@ -6,6 +7,65 @@ namespace uscxml {
static int _dataIndentation = 1;
+Data::Data(const Arabica::DOM::Node<std::string>& dom) {
+ // we may need to convert some keys to arrays if we have the same name as an element
+ std::map<std::string, std::list<Data> > arrays;
+// Interpreter::dump(dom);
+
+ if (dom.hasAttributes()) {
+ Arabica::DOM::NamedNodeMap<std::string> attributes = dom.getAttributes();
+ for (int i = 0; i < attributes.getLength(); i++) {
+ Arabica::DOM::Node<std::string> attribute = attributes.item(i);
+// Interpreter::dump(attribute);
+
+ assert(attribute.getNodeType() == Arabica::DOM::Node_base::ATTRIBUTE_NODE);
+ std::string key = attribute.getLocalName();
+ std::string value = attribute.getNodeValue();
+ compound[key] = Data(value, VERBATIM);
+ }
+ }
+
+ if (dom.hasChildNodes()) {
+ Arabica::DOM::NodeList<std::string> children = dom.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Arabica::DOM::Node<std::string> child = children.item(i);
+// Interpreter::dump(child);
+ std::string key;
+ switch (child.getNodeType()) {
+ case Arabica::DOM::Node_base::ELEMENT_NODE:
+ key = TAGNAME(child);
+ break;
+ case Arabica::DOM::Node_base::ATTRIBUTE_NODE:
+ key = ((Arabica::DOM::Attr<std::string>)child).getName();
+ break;
+ case Arabica::DOM::Node_base::TEXT_NODE:
+ default:
+ break;
+ }
+ if (key.length() == 0)
+ continue;
+
+ if (compound.find(key) != compound.end()) {
+ // we already have such a key .. make it an array after we processed all children
+ arrays[key].push_back(Data(child));
+ } else {
+ compound[key] = Data(child);
+ }
+ }
+ } else {
+ atom = dom.getNodeValue();
+ type = VERBATIM;
+ }
+
+ std::map<std::string, std::list<Data> >::iterator arrayIter = arrays.begin();
+ while(arrayIter != arrays.end()) {
+ assert(compound.find(arrayIter->first) != compound.end());
+ Data arrayData;
+ arrays[arrayIter->first].push_front(compound[arrayIter->first]);
+ arrayData.array = arrays[arrayIter->first];
+ compound[arrayIter->first] = arrayData;
+ }
+}
Arabica::DOM::Document<std::string> Data::toDocument() {
Arabica::DOM::DOMImplementation<std::string> domFactory = Arabica::SimpleDOM::DOMImplementation<std::string>::getDOMImplementation();
@@ -137,7 +197,7 @@ std::ostream& operator<< (std::ostream& os, const Data& data) {
os << "{" << std::endl;
compoundIter = data.compound.begin();
while(compoundIter != data.compound.end()) {
- os << indent << " \"" << compoundIter->first << "\" " << keyPadding.substr(0, longestKey - compoundIter->first.size()) << "= ";
+ os << indent << " \"" << compoundIter->first << "\" " << keyPadding.substr(0, longestKey - compoundIter->first.size()) << ": ";
_dataIndentation += 2;
os << compoundIter->second << "," << std::endl;
_dataIndentation -= 2;