diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-07-03 11:31:35 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-07-03 11:31:35 (GMT) |
commit | 67f8e8b4106eb20ce0bc01fd840b0d8e4319cb36 (patch) | |
tree | 42ba94ef35bf70d74ebb8dcc03e01752874a6540 /src/uscxml/plugins | |
parent | b542369263782dc8b85893e218119ed070efa7b3 (diff) | |
download | uscxml-67f8e8b4106eb20ce0bc01fd840b0d8e4319cb36.zip uscxml-67f8e8b4106eb20ce0bc01fd840b0d8e4319cb36.tar.gz uscxml-67f8e8b4106eb20ce0bc01fd840b0d8e4319cb36.tar.bz2 |
Introduced isLocation for datamodels to check for valid namelist entries
Diffstat (limited to 'src/uscxml/plugins')
13 files changed, 58 insertions, 2 deletions
diff --git a/src/uscxml/plugins/DataModel.h b/src/uscxml/plugins/DataModel.h index f142a60..1a4deba 100644 --- a/src/uscxml/plugins/DataModel.h +++ b/src/uscxml/plugins/DataModel.h @@ -41,6 +41,7 @@ public: virtual std::list<std::string> getNames() = 0; virtual bool validate(const std::string& location, const std::string& schema) = 0; + virtual bool isLocation(const std::string& expr) = 0; virtual void setEvent(const Event& event) = 0; virtual Data getStringAsData(const std::string& content) = 0; @@ -121,6 +122,10 @@ public: virtual bool validate(const std::string& location, const std::string& schema) { return _impl->validate(location, schema); } + virtual bool isLocation(const std::string& expr) { + return _impl->isLocation(expr); + } + virtual void setEvent(const Event& event) { return _impl->setEvent(event); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 6dc8c26..73a3744 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -482,6 +482,19 @@ void JSCDataModel::setForeach(const std::string& item, } } +bool JSCDataModel::isLocation(const std::string& expr) { + JSStringRef scriptJS = JSStringCreateWithUTF8CString((expr + "++").c_str()); + JSValueRef exception = NULL; + bool valid = JSCheckScriptSyntax(_ctx, scriptJS, NULL, 0, &exception); + JSStringRelease(scriptJS); + + if (exception || !valid) { + return false; + } + return true; +} + + bool JSCDataModel::isDeclared(const std::string& expr) { JSStringRef scriptJS = JSStringCreateWithUTF8CString(expr.c_str()); JSValueRef exception = NULL; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index 82882f0..fea2234 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -49,6 +49,7 @@ public: } virtual bool validate(const std::string& location, const std::string& schema); + virtual bool isLocation(const std::string& expr); virtual void setEvent(const Event& event); virtual Data getStringAsData(const std::string& content); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index 8b222f7..a995ec2 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -457,6 +457,22 @@ bool V8DataModel::validate(const std::string& location, const std::string& schem return true; } +bool V8DataModel::isLocation(const std::string& expr) { + v8::Locker locker; + v8::HandleScope handleScope; + v8::TryCatch tryCatch; + v8::Context::Scope contextScope(_contexts.back()); + + v8::Handle<v8::String> source = v8::String::New((expr + "++").c_str()); + v8::Handle<v8::Script> script = v8::Script::Compile(source); + + if (script.IsEmpty() || tryCatch.HasCaught()) { + return false; + } + + return true; +} + uint32_t V8DataModel::getLength(const std::string& expr) { v8::Locker locker; v8::HandleScope handleScope; @@ -468,7 +484,7 @@ uint32_t V8DataModel::getLength(const std::string& expr) { Event exceptionEvent; exceptionEvent.name = "error.execution"; - exceptionEvent.data.compound["exception"] = Data("'" + expr + "' does not evaluate to an array.", Data::VERBATIM); + exceptionEvent.data.compound["cause"] = Data("'" + expr + "' does not evaluate to an array.", Data::VERBATIM); throw(exceptionEvent); } @@ -720,7 +736,7 @@ void V8DataModel::throwExceptionEvent(const v8::TryCatch& tryCatch) { exceptionEvent.eventType = Event::PLATFORM; std::string exceptionString(*v8::String::AsciiValue(tryCatch.Exception())); - exceptionEvent.data.compound["exception"] = Data(exceptionString, Data::VERBATIM);; + exceptionEvent.data.compound["cause"] = Data(exceptionString, Data::VERBATIM);; v8::Handle<v8::Message> message = tryCatch.Message(); if (!message.IsEmpty()) { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h index 5bfca93..6df1951 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h @@ -53,6 +53,7 @@ public: virtual void setEvent(const Event& event); virtual bool validate(const std::string& location, const std::string& schema); + virtual bool isLocation(const std::string& expr); virtual uint32_t getLength(const std::string& expr); virtual void setForeach(const std::string& item, diff --git a/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp b/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp index 45d7a5c..073657a 100644 --- a/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp +++ b/src/uscxml/plugins/datamodel/null/NULLDataModel.cpp @@ -76,6 +76,10 @@ bool NULLDataModel::validate(const std::string& location, const std::string& sch return true; } +bool NULLDataModel::isLocation(const std::string& expr) { + return true; +} + uint32_t NULLDataModel::getLength(const std::string& expr) { return 0; } diff --git a/src/uscxml/plugins/datamodel/null/NULLDataModel.h b/src/uscxml/plugins/datamodel/null/NULLDataModel.h index 162ffdb..f9609c4 100644 --- a/src/uscxml/plugins/datamodel/null/NULLDataModel.h +++ b/src/uscxml/plugins/datamodel/null/NULLDataModel.h @@ -50,6 +50,7 @@ public: virtual void setEvent(const Event& event); virtual bool validate(const std::string& location, const std::string& schema); + virtual bool isLocation(const std::string& expr); virtual uint32_t getLength(const std::string& expr); virtual void setForeach(const std::string& item, diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp index 8f5e588..924e14a 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp @@ -607,6 +607,10 @@ bool SWIDataModel::validate(const std::string& location, const std::string& sche return true; } +bool SWIDataModel::isLocation(const std::string& expr) { + return true; +} + uint32_t SWIDataModel::getLength(const std::string& expr) { SWIEngineLock engineLock; try { diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h index f022811..a673a40 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.h @@ -68,6 +68,7 @@ public: virtual void registerIOProcessor(const std::string& name, const IOProcessor& ioprocessor); virtual bool validate(const std::string& location, const std::string& schema); + virtual bool isLocation(const std::string& expr); virtual uint32_t getLength(const std::string& expr); virtual void setForeach(const std::string& item, diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp index 4300512..6d34677 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.cpp @@ -98,6 +98,10 @@ bool PromelaDataModel::validate(const std::string& location, const std::string& return true; } +bool PromelaDataModel::isLocation(const std::string& expr) { + return true; +} + uint32_t PromelaDataModel::getLength(const std::string& expr) { if (!isDeclared(expr)) { ERROR_EXECUTION_THROW("Variable '" + expr + "' was not declared"); diff --git a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h index cbbf570..ca6b19d 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h +++ b/src/uscxml/plugins/datamodel/promela/PromelaDataModel.h @@ -49,6 +49,7 @@ public: virtual void registerIOProcessor(const std::string& name, const IOProcessor& ioprocessor); virtual bool validate(const std::string& location, const std::string& schema); + virtual bool isLocation(const std::string& expr); virtual uint32_t getLength(const std::string& expr); virtual void setForeach(const std::string& item, diff --git a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp index 3b28547..c38842b 100644 --- a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp +++ b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp @@ -285,6 +285,10 @@ bool XPathDataModel::validate(const std::string& location, const std::string& sc return true; } +bool XPathDataModel::isLocation(const std::string& expr) { + return true; +} + uint32_t XPathDataModel::getLength(const std::string& expr) { // std::cout << _datamodel << std::endl; XPathValue<std::string> result = _xpath.evaluate_expr(expr, _doc); diff --git a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.h b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.h index d18d05a..09d63fa 100644 --- a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.h +++ b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.h @@ -95,6 +95,7 @@ public: virtual void setEvent(const Event& event); virtual bool validate(const std::string& location, const std::string& schema); + virtual bool isLocation(const std::string& expr); virtual uint32_t getLength(const std::string& expr); virtual void setForeach(const std::string& item, |