summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/datamodel
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-07-01 22:51:30 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-07-01 22:51:30 (GMT)
commit945160d0539ad119ffc986fac712db76c7203e84 (patch)
treec43e4a7db898026bc62cc20af5061d07736f847e /src/uscxml/plugins/datamodel
parentc70d02010ea99e6c8e35da3b767f41f1ee5dce56 (diff)
downloaduscxml-945160d0539ad119ffc986fac712db76c7203e84.zip
uscxml-945160d0539ad119ffc986fac712db76c7203e84.tar.gz
uscxml-945160d0539ad119ffc986fac712db76c7203e84.tar.bz2
More polishing for bindings C# and Java
Diffstat (limited to 'src/uscxml/plugins/datamodel')
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp31
-rw-r--r--src/uscxml/plugins/datamodel/null/NULLDataModel.cpp5
-rw-r--r--src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp10
-rw-r--r--src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp30
-rw-r--r--src/uscxml/plugins/datamodel/promela/PromelaParser.cpp13
-rw-r--r--src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp54
6 files changed, 60 insertions, 83 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp
index b2fce62..6dc8c26 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp
@@ -452,12 +452,7 @@ uint32_t JSCDataModel::getLength(const std::string& expr) {
result = evalAsValue("(" + expr + ").length");
JSType type = JSValueGetType(_ctx, result);
if (type == kJSTypeNull || type == kJSTypeUndefined) {
- Event exceptionEvent;
- exceptionEvent.data.compound["exception"] = Data("'" + expr + "' does not evaluate to an array.", Data::VERBATIM);
- exceptionEvent.name = "error.execution";
- exceptionEvent.eventType = Event::PLATFORM;
-
- throw(exceptionEvent);
+ ERROR_EXECUTION_THROW("'" + expr + "' does not evaluate to an array.");
}
JSValueRef exception = NULL;
@@ -549,20 +544,20 @@ void JSCDataModel::assign(const Element<std::string>& assignElem,
} else if (HAS_ATTR(assignElem, "location")) {
key = ATTR(assignElem, "location");
}
- if (key.length() == 0)
- throw Event("error.execution", Event::PLATFORM);
-
+ if (key.length() == 0) {
+ ERROR_EXECUTION_THROW("Assign element has neither id nor location");
+ }
// flags on attribute are ignored?
if (key.compare("_sessionid") == 0) // test 322
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Cannot assign to _sessionId");
if (key.compare("_name") == 0)
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Cannot assign to _name");
if (key.compare("_ioprocessors") == 0) // test 326
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Cannot assign to _ioprocessors");
if (key.compare("_invokers") == 0)
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Cannot assign to _invokers");
if (key.compare("_event") == 0)
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Cannot assign to _event");
if (HAS_ATTR(assignElem, "expr")) {
evalAsValue(key + " = " + ATTR(assignElem, "expr"));
@@ -666,13 +661,7 @@ void JSCDataModel::handleException(JSValueRef exception) {
JSStringRelease(exceptionStringRef);
std::string exceptionMsg(buffer);
- Event exceptionEvent;
- exceptionEvent.data.compound["exception"] = Data(exceptionMsg, Data::VERBATIM);
- exceptionEvent.name = "error.execution";
- exceptionEvent.eventType = Event::PLATFORM;
-
- throw(exceptionEvent);
-
+ ERROR_EXECUTION_THROW(exceptionMsg);
}
JSValueRef JSCDataModel::jsPrint(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) {
diff --git a/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp b/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp
index 98d2dda..45d7a5c 100644
--- a/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp
+++ b/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp
@@ -65,7 +65,10 @@ void NULLDataModel::setEvent(const Event& event) {
}
Data NULLDataModel::getStringAsData(const std::string& content) {
- Data data;
+ Data data = Data::fromJSON(content);
+ if (data.empty()) {
+ data = Data(content, Data::VERBATIM);
+ }
return data;
}
diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp
index ad0c42b..8f5e588 100644
--- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp
+++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp
@@ -37,10 +37,7 @@ extern "C" {
}
#define RETHROW_PLEX_AS_EVENT \
catch (PlException plex) { \
- Event e; \
- e.name = "error.execution"; \
- e.data.compound["cause"] = (char*)plex; \
- throw e; \
+ ERROR_EXECUTION_THROW((char*)plex); \
} \
#define PL_MODULE \
@@ -733,10 +730,7 @@ std::string SWIDataModel::evalAsString(const std::string& expr) {
if (term.type() == PL_ATOM || term.type() == PL_CHARS || term.type() == PL_STRING) {
return std::string(term);
} else {
- Event e;
- e.name = "error.execution";
- e.data.compound["cause"] = (char*)plex;
- throw e;
+ ERROR_EXECUTION_THROW((char*)plex);
}
}
}
diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp
index 8bfc39d..4300512 100644
--- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp
+++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp
@@ -100,11 +100,11 @@ bool PromelaDataModel::validate(const std::string& location, const std::string&
uint32_t PromelaDataModel::getLength(const std::string& expr) {
if (!isDeclared(expr)) {
- throwErrorExecution("Variable " + expr + " was not declared");
+ ERROR_EXECUTION_THROW("Variable '" + expr + "' was not declared");
}
if (!_variables[expr].hasKey("size")) {
- throwErrorExecution("Variable " + expr + " is no array");
+ ERROR_EXECUTION_THROW("Variable '" + expr + "' is no array");
}
return strTo<int>(_variables[expr]["size"].atom);
@@ -216,7 +216,7 @@ void PromelaDataModel::evaluateDecl(void* ast) {
_variables.compound[name->value] = variable;
} else {
- throwErrorExecution("Declaring variables via " + PromelaParserNode::typeToDesc((*nameIter)->type) + " not implemented");
+ ERROR_EXECUTION_THROW("Declaring variables via " + PromelaParserNode::typeToDesc((*nameIter)->type) + " not implemented");
}
}
assert(opIter == node->operands.end());
@@ -227,7 +227,7 @@ void PromelaDataModel::evaluateDecl(void* ast) {
evaluateDecl(*declIter);
}
} else {
- throwErrorExecution("Declaring variables via " + PromelaParserNode::typeToDesc(node->type) + " not implemented");
+ ERROR_EXECUTION_THROW("Declaring variables via " + PromelaParserNode::typeToDesc(node->type) + " not implemented");
}
}
@@ -269,7 +269,7 @@ int PromelaDataModel::evaluateExpr(void* ast) {
case PML_OR:
return evaluateExpr(*opIter++) != 0 || evaluateExpr(*opIter++) != 0;
default:
- throwErrorExecution("Support for " + PromelaParserNode::typeToDesc(node->type) + " expressions not implemented");
+ ERROR_EXECUTION_THROW("Support for " + PromelaParserNode::typeToDesc(node->type) + " expressions not implemented");
}
return 0;
}
@@ -291,7 +291,7 @@ void PromelaDataModel::evaluateStmnt(void* ast) {
break;
}
default:
- throwErrorExecution("No support for " + PromelaParserNode::typeToDesc(node->type) + " statement implemented");
+ ERROR_EXECUTION_THROW("No support for " + PromelaParserNode::typeToDesc(node->type) + " statement implemented");
}
}
@@ -306,15 +306,15 @@ void PromelaDataModel::setVariable(void* ast, int value) {
int index = evaluateExpr(expr);
if (_variables.compound.find(name->value) == _variables.compound.end()) {
- throwErrorExecution("No variable " + name->value + " was declared");
+ ERROR_EXECUTION_THROW("No variable " + name->value + " was declared");
}
if (!_variables[name->value].hasKey("size")) {
- throwErrorExecution("Variable " + name->value + " is no array");
+ ERROR_EXECUTION_THROW("Variable " + name->value + " is no array");
}
if (strTo<int>(_variables[name->value]["size"].atom) <= index) {
- throwErrorExecution("Index " + toStr(index) + " in array " + name->value + "[" + _variables[name->value]["size"].atom + "] is out of bounds");
+ ERROR_EXECUTION_THROW("Index " + toStr(index) + " in array " + name->value + "[" + _variables[name->value]["size"].atom + "] is out of bounds");
}
_variables.compound[name->value].compound["value"][index] = Data(value, Data::VERBATIM);
@@ -339,10 +339,10 @@ int PromelaDataModel::getVariable(void* ast) {
switch(node->type) {
case PML_NAME:
if (_variables.compound.find(node->value) == _variables.compound.end()) {
- throwErrorExecution("No variable " + node->value + " was declared");
+ ERROR_EXECUTION_THROW("No variable " + node->value + " was declared");
}
if (_variables[node->value].compound.find("size") != _variables[node->value].compound.end()) {
- throwErrorExecution("Type error: Variable " + node->value + " is an array");
+ ERROR_EXECUTION_THROW("Type error: Variable " + node->value + " is an array");
}
return strTo<int>(_variables[node->value]["value"].atom);
case PML_VAR_ARRAY: {
@@ -351,20 +351,20 @@ int PromelaDataModel::getVariable(void* ast) {
int index = evaluateExpr(expr);
if (_variables.compound.find(name->value) == _variables.compound.end()) {
- throwErrorExecution("No variable " + name->value + " was declared");
+ ERROR_EXECUTION_THROW("No variable " + name->value + " was declared");
}
if (!_variables[name->value].hasKey("size")) {
- throwErrorExecution("Variable " + name->value + " is no array");
+ ERROR_EXECUTION_THROW("Variable " + name->value + " is no array");
}
if (strTo<int>(_variables[name->value]["size"].atom) <= index) {
- throwErrorExecution("Index " + toStr(index) + " in array " + name->value + "[" + _variables[name->value]["size"].atom + "] is out of bounds");
+ ERROR_EXECUTION_THROW("Index " + toStr(index) + " in array " + name->value + "[" + _variables[name->value]["size"].atom + "] is out of bounds");
}
return strTo<int>(_variables.compound[name->value].compound["value"][index].atom);
}
default:
- throwErrorExecution("Retrieving value of " + PromelaParserNode::typeToDesc(node->type) + " variable not implemented");
+ ERROR_EXECUTION_THROW("Retrieving value of " + PromelaParserNode::typeToDesc(node->type) + " variable not implemented");
}
return 0;
}
diff --git a/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp b/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp
index cd3bbaf..d12b7fc 100644
--- a/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp
+++ b/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp
@@ -19,6 +19,7 @@
#include "PromelaParser.h"
#include "parser/promela.tab.hpp"
+#include "uscxml/messages/Event.h"
#include <iostream>
@@ -35,10 +36,7 @@ int promela_lex_destroy (void*);
void promela_error (uscxml::PromelaParser* ctx, void* yyscanner, const char* err) {
// mark as pending exception as we cannot throw from constructor and have the destructor called
- uscxml::Event excEvent;
- excEvent.data.compound["exception"] = uscxml::Data(err, uscxml::Data::VERBATIM);
- excEvent.name = "error.execution";
- excEvent.eventType = uscxml::Event::PLATFORM;
+ ERROR_EXECUTION(excEvent, err);
ctx->pendingException = excEvent;
}
@@ -53,12 +51,7 @@ PromelaParser::PromelaParser(const std::string& expr, Type expectedType) {
if (type != expectedType) {
std::stringstream ss;
ss << "Promela syntax type mismatch: Expected " << typeToDesc(expectedType) << " but got " << typeToDesc(type);
-
- uscxml::Event excEvent;
- excEvent.data.compound["exception"] = uscxml::Data(ss.str(), uscxml::Data::VERBATIM);
- excEvent.name = "error.execution";
- excEvent.eventType = uscxml::Event::PLATFORM;
- throw excEvent;
+ ERROR_EXECUTION_THROW(ss.str());
}
}
diff --git a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp
index 4d9854b..5800f98 100644
--- a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp
+++ b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp
@@ -296,9 +296,7 @@ uint32_t XPathDataModel::getLength(const std::string& expr) {
return result.asNodeSet().size();
break;
default:
- Event exceptionEvent("error.execution", Event::PLATFORM);
- exceptionEvent.data.compound["exception"] = Data("'" + expr + "' does not evaluate to an array.", Data::VERBATIM);
- throw(exceptionEvent);
+ ERROR_EXECUTION_THROW("'" + expr + "' does not evaluate to an array.");
}
return 0;
}
@@ -326,7 +324,7 @@ void XPathDataModel::setForeach(const std::string& item,
if (!isDeclared(item)) {
if (!isValidIdentifier(item))
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Expression '" + item + "' not a valid identifier.");
Element<std::string> container = _doc.createElement("data");
container.setAttribute("id", item);
container.appendChild(arrayResult.asNodeSet()[iteration].cloneNode(true));
@@ -400,9 +398,9 @@ bool XPathDataModel::evalAsBool(const Arabica::DOM::Node<std::string>& node, con
try {
result = _xpath.evaluate_expr(expr, _doc);
} catch(SyntaxException e) {
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW(e.what());
} catch(std::runtime_error e) {
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW(e.what());
}
return result.asBool();
}
@@ -413,9 +411,9 @@ std::string XPathDataModel::evalAsString(const std::string& expr) {
try {
result = _xpath.evaluate_expr(expr, _doc);
} catch(SyntaxException e) {
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW(e.what());
} catch(std::runtime_error e) {
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW(e.what());
}
switch (result.type()) {
case STRING:
@@ -440,7 +438,7 @@ std::string XPathDataModel::evalAsString(const std::string& expr) {
break;
}
case ANY:
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Type ANY not supported to evaluate as string");
break;
}
return "undefined";
@@ -472,13 +470,13 @@ void XPathDataModel::assign(const Element<std::string>& assignElem,
for (int i = 0; i < key.asNodeSet().size(); i++) {
Node<std::string> node = key.asNodeSet()[i];
if (node == _varResolver.resolveVariable("", "_ioprocessors").asNodeSet()[0])
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Cannot assign _ioProcessors");
if (node == _varResolver.resolveVariable("", "_sessionid").asNodeSet()[0])
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Cannot assign _sessionid");
if (node == _varResolver.resolveVariable("", "_name").asNodeSet()[0])
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Cannot assign _name");
if (node == _varResolver.resolveVariable("", "_event").asNodeSet()[0])
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Cannot assign _event");
}
} catch (Event e) {}
}
@@ -570,11 +568,11 @@ void XPathDataModel::init(const Element<std::string>& dataElem,
}
case Arabica::XPath::BOOL:
case ANY:
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("expr evaluates to type ANY");
}
_datamodel.appendChild(container);
} catch (SyntaxException e) {
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW(e.what());
}
} else {
LOG(ERROR) << "data element has no content";
@@ -595,7 +593,7 @@ void XPathDataModel::assign(const XPathValue<std::string>& key,
switch (key.type()) {
case NODE_SET:
if (key.asNodeSet().size() == 0) {
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("key for assign is empty nodeset");
}
switch (value.type()) {
case STRING:
@@ -611,14 +609,14 @@ void XPathDataModel::assign(const XPathValue<std::string>& key,
assign(key.asNodeSet(), value.asNodeSet(), assignElem);
break;
case ANY:
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Type ANY as key for assign not supported");
}
break;
case STRING:
case Arabica::XPath::BOOL:
case NUMBER:
case ANY:
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Type ANY as key for assign not supported")
break;
}
}
@@ -637,7 +635,7 @@ void XPathDataModel::assign(const XPathValue<std::string>& key,
case Arabica::XPath::BOOL:
case NUMBER:
case ANY:
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Type ANY as key for assign not supported")
}
}
@@ -665,7 +663,7 @@ void XPathDataModel::assign(const NodeSet<std::string>& key,
// addattribute: Add an attribute with the name specified by 'attr'
// and value specified by 'expr' to the node specified by 'location'.
if (!HAS_ATTR(assignElem, "attr"))
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Assign element is missing 'attr'")
element.setAttribute(ATTR(assignElem, "attr"), value);
} else {
/// test 547
@@ -677,7 +675,7 @@ void XPathDataModel::assign(const NodeSet<std::string>& key,
break;
}
default:
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Unsupported node type with assign");
break;
}
}
@@ -709,7 +707,7 @@ void XPathDataModel::assign(const NodeSet<std::string>& key,
break;
default:
// std::cout << key[i].getNodeType() << std::endl;
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Unsupported node type for assign");
break;
}
}
@@ -740,7 +738,7 @@ void XPathDataModel::assign(const Element<std::string>& key,
// node specified by 'location', keeping the same parent.
Node<std::string> parent = element.getParentNode();
if (!parent)
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Node has no parent");
for (int i = 0; i < value.size(); i++) {
Node<std::string> importedNode = (value[i].getOwnerDocument() == _doc ? value[i].cloneNode(true) : _doc.importNode(value[i], true));
parent.insertBefore(importedNode, element);
@@ -750,7 +748,7 @@ void XPathDataModel::assign(const Element<std::string>& key,
// specified by 'location', keeping the same parent.
Node<std::string> parent = element.getParentNode();
if (!parent)
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Node has no parent");
for (int i = value.size(); i; i--) {
Node<std::string> importedNode = (value[i-1].getOwnerDocument() == _doc ? value[i-1].cloneNode(true) : _doc.importNode(value[i-1], true));
Node<std::string> nextSibling = element.getNextSibling();
@@ -764,16 +762,16 @@ void XPathDataModel::assign(const Element<std::string>& key,
// replace: Replace the node specified by 'location' by the value specified by 'expr'.
Node<std::string> parent = element.getParentNode();
if (!parent)
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Node has no parent");
if (value.size() != 1)
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Value not singular");
Node<std::string> importedNode = (value[0].getOwnerDocument() == _doc ? value[0].cloneNode(true) : _doc.importNode(value[0], true));
parent.replaceChild(importedNode, element);
} else if (assignElem && HAS_ATTR(assignElem, "type") && iequals(ATTR(assignElem, "type"), "delete")) {
// delete: Delete the node specified by 'location'. ('expr' is ignored.).
Node<std::string> parent = element.getParentNode();
if (!parent)
- throw Event("error.execution", Event::PLATFORM);
+ ERROR_EXECUTION_THROW("Node has no parent");
parent.removeChild(element);
} else {
// replacechildren: Replace all the children at 'location' with the value specified by 'expr'.
@@ -791,7 +789,7 @@ NodeSetVariableResolver::resolveVariable(const std::string& namepaceUri,
const std::string& name) const {
std::map<std::string, NodeSet<std::string> >::const_iterator n = _variables.find(name);
if(n == _variables.end()) {
- throw Event("error.execution");
+ ERROR_EXECUTION_THROW("No varable named '" + name + "'");
}
#if VERBOSE
std::cout << std::endl << "Getting " << name << ":" << std::endl;