From d35b69b97dead2e50dda697f0fb0d5e574bbf205 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Tue, 13 Aug 2013 14:24:51 +0200 Subject: Renamed event.type to eventType to avoid clash with send.type and invoker.type --- .gitignore | 3 + CMakeLists.txt | 2 +- contrib/dom/idl/SCXMLEvent.idl | 2 +- .../java/src/org/uscxml/tests/TestDataModel.java | 83 ++++++++++++---- src/bindings/swig/java/JavaDataModel.h | 61 +++++++++++- src/bindings/swig/java/uscxml.i | 11 ++- src/uscxml/Factory.cpp | 8 +- src/uscxml/Interpreter.cpp | 6 +- src/uscxml/Message.cpp | 2 +- src/uscxml/Message.h | 65 ++----------- src/uscxml/interpreter/InterpreterDraft6.cpp | 2 +- .../ecmascript/JavaScriptCore/JSCDataModel.cpp | 2 +- .../JavaScriptCore/dom/JSCSCXMLEvent.cpp | 2 +- .../ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.h | 2 +- .../JavaScriptCore/dom/JSCSCXMLEventCustom.cpp | 4 +- .../JavaScriptCore/dom/JSCXPathResultCustom.cpp | 18 ++-- .../datamodel/ecmascript/v8/V8DataModel.cpp | 2 +- .../datamodel/ecmascript/v8/dom/V8SCXMLEvent.h | 4 +- .../ecmascript/v8/dom/V8SCXMLEventCustom.cpp | 4 +- .../plugins/datamodel/prolog/swi/SWIDataModel.cpp | 2 +- .../plugins/datamodel/xpath/XPathDataModel.cpp | 2 +- .../plugins/invoker/umundo/UmundoInvoker.cpp | 8 +- .../ioprocessor/basichttp/BasicHTTPIOProcessor.cpp | 2 +- .../ioprocessor/modality/MMIHTTPIOProcessor.cpp | 2 +- test/samples/uscxml/test-java-datamodel.scxml | 105 +++++++++++++++++++++ 25 files changed, 284 insertions(+), 120 deletions(-) create mode 100644 test/samples/uscxml/test-java-datamodel.scxml diff --git a/.gitignore b/.gitignore index 8a1e4e8..b80c75e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ contrib/prebuilt/linux* contrib/prebuilt/windows* contrib/prebuilt/ios* contrib/prebuilt/android* +contrib/java/bin* +contrib/java/*.log + package/linux* package/darwin* package/windows* diff --git a/CMakeLists.txt b/CMakeLists.txt index 92b0369..c256caa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -461,7 +461,7 @@ list (APPEND USCXML_CORE_LIBS ${EVENT_LIBRARY}) ################################################# # Optional libraries -if (APPLE OR IOS) +if (OFF AND (APPLE OR IOS)) find_library(AUDIOTOOLBOX AudioToolbox REQUIRED) list (APPEND USCXML_OPT_LIBS ${AUDIOTOOLBOX}) diff --git a/contrib/dom/idl/SCXMLEvent.idl b/contrib/dom/idl/SCXMLEvent.idl index 67f5070..fbb7661 100644 --- a/contrib/dom/idl/SCXMLEvent.idl +++ b/contrib/dom/idl/SCXMLEvent.idl @@ -7,7 +7,7 @@ const unsigned short EXTERNAL = 2; const unsigned short PLATFORM = 3; - [CustomGetter, EmptyAsNull] readonly attribute DOMString type; + [CustomGetter, EmptyAsNull] readonly attribute DOMString eventType; readonly attribute DOMString name; [EmptyAsNull] readonly attribute DOMString origin; [EmptyAsNull] readonly attribute DOMString origintype; diff --git a/contrib/java/src/org/uscxml/tests/TestDataModel.java b/contrib/java/src/org/uscxml/tests/TestDataModel.java index c9d8ae0..e3c8d7a 100644 --- a/contrib/java/src/org/uscxml/tests/TestDataModel.java +++ b/contrib/java/src/org/uscxml/tests/TestDataModel.java @@ -16,11 +16,20 @@ public class TestDataModel extends JavaDataModel { @Override public JavaDataModel create(Interpreter interpreter) { - return new JavaDataModel(); + /** + * An SCXML interpreter wants an instance of this datamodel + */ + System.out.println("create"); + return new TestDataModel(); } @Override public StringSet getNames() { + /** + * Register with the following names for the datamodel attribute + * at the scxml element. + */ + System.out.println("getNames"); StringSet ss = new StringSet(); ss.insert("java"); return ss; @@ -28,67 +37,107 @@ public class TestDataModel extends JavaDataModel { @Override public boolean validate(String location, String schema) { + /** + * Validate the datamodel. This make more sense for XML datamodels + * and is pretty much unused but required as per draft. + */ + System.out.println("validate " + location + " " + schema); return true; } @Override public void setEvent(Event event) { - /* make sure the fields of event are available as _event to conform - * with the SCXML draft + /** + * Make the event available as the variable _event + * in the datamodel. */ + System.out.println("setEvent " + event); } @Override public Data getStringAsData(String content) { + /** + * Evaluate the string as a value expression and + * transform it into a JSON-like Data structure + */ + System.out.println("getStringAsData " + content); Data data = new Data(); return data; } @Override public long getLength(String expr) { + /** + * Return the length of the expression if it were an + * array, used by foreach element. + */ + System.out.println("getLength " + expr); return 0; } @Override public void setForeach(String item, String array, String index, long iteration) { + /** + * Prepare an iteration of the foreach element, by setting the variable in index + * to the curent iteration and setting the variable in item to the current item + * from array. + */ + System.out.println("setForeach " + item + " " + index + " " + iteration); } @Override - public void eval(SWIGTYPE_p_Arabica__DOM__ElementT_std__string_t scriptElem, String expr) { + public void eval(String scriptElem, String expr) { + /** + * Evaluate the given expression in the datamodel. + * This is used foremost with script elements. + */ + System.out.println("eval " + scriptElem + " " + expr); } @Override public String evalAsString(String expr) { + /** + * Evaluate the expression as a string e.g. for the log element. + */ + System.out.println("evalAsString " + expr); return ""; } @Override public boolean evalAsBool(String expr) { + /** + * Evaluate the expression as a boolean for cond attributes in + * if and transition elements. + */ + System.out.println("evalAsBool " + expr); return true; } @Override public boolean isDeclared(String expr) { + /** + * The interpreter is supposed to raise an error if we assign + * to an undeclared variable. This method is used to check whether + * a location from assign is declared. + */ + System.out.println("isDeclared " + expr); return true; } @Override - public void assign(SWIGTYPE_p_Arabica__DOM__ElementT_std__string_t assignElem, SWIGTYPE_p_Arabica__DOM__DocumentT_std__string_t doc, String content) { - } - - @Override - public void assign(String location, Data data) { - super.assign(location, data); - } - - @Override - public void init(SWIGTYPE_p_Arabica__DOM__ElementT_std__string_t dataElem, SWIGTYPE_p_Arabica__DOM__DocumentT_std__string_t doc, String content) { - super.init(dataElem, doc, content); + public void init(String dataElem, String location, String content) { + /** + * Called when we pass data elements. + */ + System.out.println("init " + dataElem + " " + location + " " + content); } @Override - public void init(String location, Data data) { - super.init(location, data); + public void assign(String assignElem, String location, String content) { + /** + * Called when we evaluate assign elements + */ + System.out.println("assign " + assignElem + " " + location + " " + content); } /** diff --git a/src/bindings/swig/java/JavaDataModel.h b/src/bindings/swig/java/JavaDataModel.h index 9188cf6..5d76480 100644 --- a/src/bindings/swig/java/JavaDataModel.h +++ b/src/bindings/swig/java/JavaDataModel.h @@ -44,7 +44,11 @@ public: virtual void popContext() {} virtual void eval(const Arabica::DOM::Element& scriptElem, - const std::string& expr) {} + const std::string& expr) { + std::ostringstream ssEval; + ssEval << scriptElem; + eval(ssEval.str(), expr); + } virtual std::string evalAsString(const std::string& expr) { return ""; @@ -59,14 +63,61 @@ public: virtual void assign(const Arabica::DOM::Element& assignElem, const Arabica::DOM::Document& doc, - const std::string& content) {} - virtual void assign(const std::string& location, const Data& data) {} + const std::string& content) { + // convert XML back into strings + std::string location; + if (assignElem.hasAttribute("location")) { + location = assignElem.getAttribute("location"); + } + std::ostringstream ssAssign; + ssAssign << assignElem; + std::string tmp; + if (doc) { + std::ostringstream ssContent; + ssContent << doc; + tmp = ssContent.str(); + } else { + tmp = content; + } + assign(location, ssAssign.str(), tmp); + } + + virtual void assign(const std::string& location, const Data& data) { + init("", location, Data::toJSON(data)); + } + + // this is assign the function exposed to java virtual void init(const Arabica::DOM::Element& dataElem, const Arabica::DOM::Document& doc, - const std::string& content) {} - virtual void init(const std::string& location, const Data& data) {} + const std::string& content) { + // convert XML back into strings + std::string location; + if (dataElem.hasAttribute("id")) { + location = dataElem.getAttribute("id"); + } + std::ostringstream ssData; + if (dataElem) + ssData << dataElem; + std::string tmp; + if (doc) { + std::ostringstream ssContent; + ssContent << doc; + tmp = ssContent.str(); + } else { + tmp = content; + } + init(location, ssData.str(), tmp); + } + + virtual void init(const std::string& location, const Data& data) { + init("", location, Data::toJSON(data)); + } + // these functions are exposed to java + virtual void init(const std::string& dataElem, const std::string& location, const std::string& content) {} + virtual void assign(const std::string& assignElem, const std::string& location, const std::string& content) {} + virtual void eval(const std::string& scriptElem, const std::string& expr) {} }; diff --git a/src/bindings/swig/java/uscxml.i b/src/bindings/swig/java/uscxml.i index 81ac83e..02ef531 100644 --- a/src/bindings/swig/java/uscxml.i +++ b/src/bindings/swig/java/uscxml.i @@ -1,5 +1,8 @@ %module(directors="1", allprotected="1") uscxmlNativeJava +// provide a macro for the header files +#define SWIGIMPORTED 1 + // import swig typemaps //%include //%include @@ -12,7 +15,6 @@ %include - typedef uscxml::Data Data; typedef uscxml::Event Event; typedef uscxml::InvokeRequest InvokeRequest; @@ -68,6 +70,12 @@ using namespace uscxml; %ignore uscxml::JavaInvoker::create(InterpreterImpl*); %ignore uscxml::JavaDataModel::create(InterpreterImpl*); +%ignore uscxml::JavaDataModel::init(const Arabica::DOM::Element&, const Arabica::DOM::Document&, const std::string&); +%ignore uscxml::JavaDataModel::init(const std::string&, const Data&); +%ignore uscxml::JavaDataModel::assign(const Arabica::DOM::Element&, const Arabica::DOM::Document&, const std::string&); +%ignore uscxml::JavaDataModel::assign(const std::string&, const Data&); +%ignore uscxml::JavaDataModel::eval(const Arabica::DOM::Element&, const std::string&); + %template(DataMap) std::map; %template(DataList) std::list; %template(StringSet) std::set; @@ -80,7 +88,6 @@ using namespace uscxml; // Parse the header file to generate wrappers //*********************************************** -#define SWIGIMPORTED 1 %include "../../../uscxml/Factory.h" %include "../../../uscxml/Message.h" %include "../../../uscxml/Interpreter.h" diff --git a/src/uscxml/Factory.cpp b/src/uscxml/Factory.cpp index 21e820a..22d6008 100644 --- a/src/uscxml/Factory.cpp +++ b/src/uscxml/Factory.cpp @@ -491,7 +491,7 @@ void EventHandlerImpl::returnErrorExecution(const std::string& cause) { Event exceptionEvent; exceptionEvent.data.compound["exception"] = Data(cause, Data::VERBATIM); exceptionEvent.name = "error.execution"; - exceptionEvent.type = Event::PLATFORM; + exceptionEvent.eventType = Event::PLATFORM; returnEvent(exceptionEvent); } @@ -499,15 +499,15 @@ void EventHandlerImpl::returnErrorPlatform(const std::string& cause) { Event exceptionEvent; exceptionEvent.data.compound["exception"] = Data(cause, Data::VERBATIM); exceptionEvent.name = "error.platform"; - exceptionEvent.type = Event::PLATFORM; + exceptionEvent.eventType = Event::PLATFORM; returnEvent(exceptionEvent); } void EventHandlerImpl::returnEvent(Event& event) { if (event.invokeid.length() == 0) event.invokeid = _invokeId; - if (event.type == 0) - event.type = Event::EXTERNAL; + if (event.eventType == 0) + event.eventType = Event::EXTERNAL; if (event.origin.length() == 0) event.origin = "#_" + _invokeId; if (event.origintype.length() == 0) diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index b529f57..a58de6b 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -32,7 +32,7 @@ catch (Event e) {\ throw(e);\ } else {\ e.name = "error.execution";\ - e.type = Event::PLATFORM;\ + e.eventType = Event::PLATFORM;\ receiveInternal(e);\ }\ } @@ -577,7 +577,7 @@ void InterpreterImpl::processParamChilds(const Arabica::DOM::Node& void InterpreterImpl::send(const Arabica::DOM::Node& element) { SendRequest sendReq; // test 331 - sendReq.Event::type = Event::EXTERNAL; + sendReq.Event::eventType = Event::EXTERNAL; try { // event if (HAS_ATTR(element, "eventexpr") && _dataModel) { @@ -776,7 +776,7 @@ void InterpreterImpl::delayedSend(void* userdata, std::string eventName) { void InterpreterImpl::invoke(const Arabica::DOM::Node& element) { InvokeRequest invokeReq; - invokeReq.Event::type = Event::EXTERNAL; + invokeReq.Event::eventType = Event::EXTERNAL; try { // type if (HAS_ATTR(element, "typeexpr") && _dataModel) { diff --git a/src/uscxml/Message.cpp b/src/uscxml/Message.cpp index 266b4be..ddb8996 100644 --- a/src/uscxml/Message.cpp +++ b/src/uscxml/Message.cpp @@ -503,7 +503,7 @@ std::ostream& operator<< (std::ostream& os, const Event& event) { indent += " "; } - os << indent << (event.type == Event::EXTERNAL ? "External" : "Internal") << " Event " << (event.dom ? "with DOM attached" : "") << std::endl; + os << indent << (event.eventType == Event::EXTERNAL ? "External" : "Internal") << " Event " << (event.dom ? "with DOM attached" : "") << std::endl; if (event.name.size() > 0) os << indent << " name: " << event.name << std::endl; diff --git a/src/uscxml/Message.h b/src/uscxml/Message.h index ed481e2..1e7a7ca 100644 --- a/src/uscxml/Message.h +++ b/src/uscxml/Message.h @@ -112,10 +112,7 @@ protected: protected: Arabica::DOM::Document toNode(const Arabica::DOM::Document& factory, const Data& data); - -#ifndef SWIG friend std::ostream& operator<< (std::ostream& os, const Data& data); -#endif }; class Event { @@ -126,9 +123,9 @@ public: PLATFORM = 3 }; - Event() : type(INTERNAL), hideSendId(false) {} - Event(const std::string& name, Type type = INTERNAL) : name(name), type(type), hideSendId(false) {} - Event(const Arabica::DOM::Node& xmlString) : type(INTERNAL), hideSendId(false) {}; + Event() : eventType(INTERNAL), hideSendId(false) {} + Event(const std::string& name, Type type = INTERNAL) : name(name), eventType(type), hideSendId(false) {} + Event(const Arabica::DOM::Node& xmlString) : eventType(INTERNAL), hideSendId(false) {}; bool operator< (const Event& other) const { return this < &other; } @@ -140,11 +137,11 @@ public: this->name = name; } - Type getType() { - return type; + Type getEventType() { + return eventType; } - void setType(const Type type) { - this->type = type; + void setEventType(const Type type) { + this->eventType = type; } std::string getOrigin() { @@ -225,52 +222,12 @@ public: return ss.str(); } -#ifdef SWIG - /// TODO: Do we want to set namelist and params as well? - std::map getNameList() { - return namelist; - } - - const std::vector getNameListKeys() { - std::set keys; - namelist_t::const_iterator nameListIter = namelist.begin(); - while (nameListIter != namelist.end()) { - keys.insert(nameListIter->first); - nameListIter++; - } - return std::vector(keys.begin(), keys.end()); - } - - // substitute multimap by map with vectors for language bindings - std::map > getParams() { - std::map > paramsMap; - params_t::iterator paramIter = params.begin(); - while(paramIter != params.end()) { - paramsMap[paramIter->first].push_back(paramIter->second); - paramIter++; - } - return paramsMap; - } - - const std::vector getParamKeys() { - std::set keys; - params_t::iterator paramIter = params.begin(); - while(paramIter != params.end()) { - keys.insert(paramIter->first); - paramIter++; - } - return std::vector(keys.begin(), keys.end()); - } - -#else std::map& getNameList() { return namelist; } std::multimap& getParams() { return params; } -#endif - #ifdef SWIGIMPORTED protected: @@ -279,7 +236,7 @@ protected: std::string raw; std::string xml; std::string name; - Type type; + Type eventType; std::string origin; std::string origintype; Arabica::DOM::Document dom; @@ -294,9 +251,7 @@ protected: typedef std::multimap params_t; typedef std::map namelist_t; -#ifndef SWIG friend std::ostream& operator<< (std::ostream& os, const Event& event); -#endif }; class InvokeRequest : public Event { @@ -340,9 +295,7 @@ protected: std::string src; bool autoForward; -#ifndef SWIG friend std::ostream& operator<< (std::ostream& os, const InvokeRequest& sendReq); -#endif }; @@ -388,9 +341,7 @@ protected: std::string type; uint32_t delayMs; -#ifndef SWIG friend std::ostream& operator<< (std::ostream& os, const SendRequest& sendReq); -#endif }; diff --git a/src/uscxml/interpreter/InterpreterDraft6.cpp b/src/uscxml/interpreter/InterpreterDraft6.cpp index 0c82f8b..aa09b53 100644 --- a/src/uscxml/interpreter/InterpreterDraft6.cpp +++ b/src/uscxml/interpreter/InterpreterDraft6.cpp @@ -246,7 +246,7 @@ void InterpreterDraft6::mainEventLoop() { #if VERBOSE std::cout << "Received externalEvent event " << _currEvent.name << std::endl; #endif - _currEvent.type = Event::EXTERNAL; // make sure it is set to external + _currEvent.eventType = Event::EXTERNAL; // make sure it is set to external if (!_running) goto EXIT_INTERPRETER; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 2c877b2..7f6a9e7 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -509,7 +509,7 @@ void JSCDataModel::handleException(JSValueRef exception) { Event exceptionEvent; exceptionEvent.data.compound["exception"] = Data(exceptionMsg, Data::VERBATIM); exceptionEvent.name = "error.execution"; - exceptionEvent.type = Event::PLATFORM; + exceptionEvent.eventType = Event::PLATFORM; throw(exceptionEvent); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp index de3a93f..579012b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp @@ -7,7 +7,7 @@ namespace DOM { JSClassRef JSCSCXMLEvent::Tmpl; JSStaticValue JSCSCXMLEvent::staticValues[] = { - { "type", typeCustomAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "eventType", eventTypeCustomAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "name", nameAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "origin", originAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, { "origintype", origintypeAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.h index 306e563..8e00401 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.h @@ -39,7 +39,7 @@ public: JSC_DESTRUCTOR(JSCSCXMLEventPrivate); - static JSValueRef typeCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); + static JSValueRef eventTypeCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef nameAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef originAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef origintypeAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp index 1033034..0209467 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp @@ -3,11 +3,11 @@ namespace Arabica { namespace DOM { -JSValueRef JSCSCXMLEvent::typeCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { +JSValueRef JSCSCXMLEvent::eventTypeCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { struct JSCSCXMLEventPrivate* privData = (struct JSCSCXMLEventPrivate*)JSObjectGetPrivate(thisObj); JSStringRef stringRef; - switch (privData->nativeObj->type) { + switch (privData->nativeObj->eventType) { case uscxml::Event::INTERNAL: stringRef = JSStringCreateWithUTF8CString("internal"); break; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResultCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResultCustom.cpp index 90abfa3..7ef2755 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResultCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResultCustom.cpp @@ -5,24 +5,22 @@ namespace Arabica { namespace DOM { JSValueRef JSCXPathResult::singleNodeValueCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { -#if 0 - v8::Local self = info.Holder(); - V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + struct JSCXPathResultPrivate* privData = (struct JSCXPathResultPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->asNodeSet()[0]); + Arabica::XPath::NodeSet nodeSet = privData->nativeObj->asNodeSet(); + if (nodeSet.size() == 0) + return JSValueMakeUndefined(ctx); - v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(nodeSet[0]); + JSClassRef retClass = JSCNode::getTmpl(); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); retPrivData->dom = privData->dom; retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - retObj.MakeWeak(0, V8Node::jsDestructor); return retObj; -#endif } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index f912455..b394171 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -558,7 +558,7 @@ void V8DataModel::throwExceptionEvent(const v8::TryCatch& tryCatch) { assert(tryCatch.HasCaught()); Event exceptionEvent; exceptionEvent.name = "error.execution"; - exceptionEvent.type = Event::PLATFORM; + exceptionEvent.eventType = Event::PLATFORM; std::string exceptionString(*v8::String::AsciiValue(tryCatch.Exception())); exceptionEvent.data.compound["exception"] = Data(exceptionString, Data::VERBATIM);; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h index 670d818..8b71ed7 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h @@ -41,7 +41,7 @@ public: static bool hasInstance(v8::Handle); - static v8::Handle typeCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle eventTypeCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info); static v8::Handle nameAttrGetter(v8::Local property, const v8::AccessorInfo& info); static v8::Handle originAttrGetter(v8::Local property, const v8::AccessorInfo& info); static v8::Handle origintypeAttrGetter(v8::Local property, const v8::AccessorInfo& info); @@ -63,7 +63,7 @@ public: instance->SetInternalFieldCount(1); - instance->SetAccessor(v8::String::NewSymbol("type"), V8SCXMLEvent::typeCustomAttrGetter, 0, + instance->SetAccessor(v8::String::NewSymbol("eventType"), V8SCXMLEvent::eventTypeCustomAttrGetter, 0, v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); instance->SetAccessor(v8::String::NewSymbol("name"), V8SCXMLEvent::nameAttrGetter, 0, v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEventCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEventCustom.cpp index 4eecb94..d02a4cb 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEventCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEventCustom.cpp @@ -3,11 +3,11 @@ namespace Arabica { namespace DOM { -v8::Handle V8SCXMLEvent::typeCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info) { +v8::Handle V8SCXMLEvent::eventTypeCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info) { v8::Local self = info.Holder(); V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - switch (privData->nativeObj->type) { + switch (privData->nativeObj->eventType) { case uscxml::Event::INTERNAL: return v8::String::New("internal"); break; diff --git a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp index a52af4b..4a1ce05 100644 --- a/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp +++ b/src/uscxml/plugins/datamodel/prolog/swi/SWIDataModel.cpp @@ -202,7 +202,7 @@ void SWIDataModel::setEvent(const Event& event) { // event.type std::string type; - switch (event.type) { + switch (event.eventType) { case Event::PLATFORM: type = "platform"; break; diff --git a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp index c38aef3..842c560 100644 --- a/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp +++ b/src/uscxml/plugins/datamodel/xpath/XPathDataModel.cpp @@ -123,7 +123,7 @@ void XPathDataModel::setEvent(const Event& event) { // -- type Element eventTypeElem = _doc.createElement("type"); Text eventType; - switch (event.type) { + switch (event.eventType) { case Event::INTERNAL: eventType = _doc.createTextNode("internal"); break; diff --git a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp index a70be38..de5a580 100644 --- a/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp +++ b/src/uscxml/plugins/invoker/umundo/UmundoInvoker.cpp @@ -94,7 +94,7 @@ void UmundoInvoker::send(const SendRequest& req) { event.name = _invokeId + ".reply." + req.name; event.origin = msg.getMeta("um.channel"); event.origintype = "umundo"; - event.type = Event::EXTERNAL; + event.eventType = Event::EXTERNAL; returnEvent(event); svcIter++; @@ -230,7 +230,7 @@ void UmundoInvoker::receive(void* object, umundo::Message* msg) { event.invokeid = _invokeId; event.origin = msg->getMeta("um.channel"); event.origintype = "umundo"; - event.type = Event::EXTERNAL; + event.eventType = Event::EXTERNAL; // if (msg->getMeta().find("um.s11n.type") != msg->getMeta().end()) // event.compound["class"] = msg->getMeta("um.s11n.type"); @@ -268,7 +268,7 @@ void UmundoInvoker::added(umundo::ServiceDescription desc) { addedEvent.invokeid = _invokeId; addedEvent.origin = desc.getName(); addedEvent.origintype = "umundo"; - addedEvent.type = Event::EXTERNAL; + addedEvent.eventType = Event::EXTERNAL; addedEvent.name = _invokeId + ".added"; std::map::const_iterator propIter = desc.getProperties().begin(); @@ -294,7 +294,7 @@ void UmundoInvoker::removed(umundo::ServiceDescription desc) { addedEvent.invokeid = _invokeId; addedEvent.origin = desc.getName(); addedEvent.origintype = "umundo"; - addedEvent.type = Event::EXTERNAL; + addedEvent.eventType = Event::EXTERNAL; addedEvent.name = _invokeId + ".removed"; std::map::const_iterator propIter = desc.getProperties().begin(); diff --git a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp index a612ee6..56e2523 100644 --- a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp +++ b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp @@ -70,7 +70,7 @@ Data BasicHTTPIOProcessor::getDataModelVariables() { bool BasicHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) { Event reqEvent = req; - reqEvent.type = Event::EXTERNAL; + reqEvent.eventType = Event::EXTERNAL; bool scxmlStructFound = false; if (reqEvent.data.compound["header"].compound.find("Content-Type") != reqEvent.data.compound["header"].compound.end() && diff --git a/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.cpp index 25e0f8c..67b518c 100644 --- a/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.cpp +++ b/src/uscxml/plugins/ioprocessor/modality/MMIHTTPIOProcessor.cpp @@ -39,7 +39,7 @@ boost::shared_ptr MMIHTTPIOProcessor::create(InterpreterImpl* i bool MMIHTTPIOProcessor::httpRecvRequest(const HTTPServer::Request& req) { Event reqEvent = req; - reqEvent.type = Event::EXTERNAL; + reqEvent.eventType = Event::EXTERNAL; bool scxmlStructFound = false; if (reqEvent.data.compound["header"].compound.find("Content-Type") != reqEvent.data.compound["header"].compound.end() && diff --git a/test/samples/uscxml/test-java-datamodel.scxml b/test/samples/uscxml/test-java-datamodel.scxml new file mode 100644 index 0000000..05e9d21 --- /dev/null +++ b/test/samples/uscxml/test-java-datamodel.scxml @@ -0,0 +1,105 @@ + + + + + + + { + "id": 1, + "name": "Foo", + "price": 123, + "tags": [ "Bar", "Eek" ], + "stock": { + "warehouse": 300, + "retail": 20, + } + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v0.12