/** * @file * @author 2012-2013 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de) * @copyright Simplified BSD * * @cond * This program is free software: you can redistribute it and/or modify * it under the terms of the FreeBSD license as published by the FreeBSD * project. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the FreeBSD license along with this * program. If not, see . * @endcond */ #ifndef XPATHDATAMODEL_H_KN8TWG0V #define XPATHDATAMODEL_H_KN8TWG0V #include "uscxml/Interpreter.h" #include #ifdef BUILD_AS_PLUGINS #include "uscxml/plugins/Plugins.h" #endif namespace uscxml { class Event; class Data; } namespace uscxml { class XPathFunctionIn : public Arabica::XPath::BooleanXPathFunction { public: XPathFunctionIn(int minArgs, int maxArgs, const std::vector >& args, InterpreterInfo* interpreter) : Arabica::XPath::BooleanXPathFunction(minArgs, maxArgs, args), _interpreter(interpreter) {} protected: bool doEvaluate(const Arabica::DOM::Node& context, const Arabica::XPath::ExecutionContext& executionContext) const; InterpreterInfo* _interpreter; }; class XPathFunctionResolver : public Arabica::XPath::FunctionResolver { public: virtual ~XPathFunctionResolver() { } virtual Arabica::XPath::XPathFunction* resolveFunction(const std::string& namespace_uri, const std::string& name, const std::vector >& argExprs) const; virtual std::vector > validNames() const; void setInterpreter(InterpreterInfo* interpreter) { _interpreter = interpreter; } protected: Arabica::XPath::StandardXPathFunctionResolver _xpathFuncRes; InterpreterInfo* _interpreter; }; class NodeSetVariableResolver : public Arabica::XPath::VariableResolver { public: Arabica::XPath::XPathValue resolveVariable(const std::string& namepaceUri, const std::string& name) const; void setVariable(const std::string& name, const Arabica::XPath::NodeSet& value); bool isDeclared(const std::string& name); private: std::map > _variables; friend class XPathDataModel; }; class XPathDataModel : public DataModelImpl { public: XPathDataModel(); virtual ~XPathDataModel(); virtual boost::shared_ptr create(InterpreterInfo* interpreter); virtual std::list getNames() { std::list names; names.push_back("xpath"); return names; } virtual void initialize(); 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, const std::string& array, const std::string& index, uint32_t iteration); virtual void pushContext(); virtual void popContext(); virtual void eval(const Arabica::DOM::Element& scriptElem, const std::string& expr); virtual void assign(const Arabica::DOM::Element& assignElem, const Arabica::DOM::Node& node, const std::string& content); virtual void assign(const std::string& location, const Data& data); virtual void init(const Arabica::DOM::Element& dataElem, const Arabica::DOM::Node& node, const std::string& content); virtual void init(const std::string& location, const Data& data); virtual Data getStringAsData(const std::string& content); virtual bool isDeclared(const std::string& expr); virtual std::string evalAsString(const std::string& expr); virtual bool evalAsBool(const std::string& expr); virtual bool evalAsBool(const Arabica::DOM::Element& node, const std::string& expr); virtual double evalAsNumber(const std::string& expr); protected: Arabica::XPath::XPath _xpath; Arabica::DOM::DOMImplementation _domFactory; Arabica::DOM::Element _datamodel; Arabica::DOM::Document _doc; bool isValidIdentifier(const std::string& identifier); Arabica::XPath::NodeSet dataToNodeSet(const Data& data); // resolve value to its type void assign(const Arabica::XPath::XPathValue& key, const Arabica::XPath::XPathValue& value, const Arabica::DOM::Element& assignElem); void assign(const Arabica::XPath::XPathValue& key, const Arabica::XPath::NodeSet& value, const Arabica::DOM::Element& assignElem); // assign value to a nodeset key void assign(const Arabica::XPath::NodeSet& key, const std::string& value, const Arabica::DOM::Element& assignElem); void assign(const Arabica::XPath::NodeSet& key, const double value, const Arabica::DOM::Element& assignElem); void assign(const Arabica::XPath::NodeSet& key, const bool value, const Arabica::DOM::Element& assignElem); void assign(const Arabica::XPath::NodeSet& key, const Arabica::XPath::NodeSet& value, const Arabica::DOM::Element& assignElem); // assign value to an element key (from nodeset) void assign(const Arabica::DOM::Element& key, const Arabica::XPath::NodeSet& value, const Arabica::DOM::Element& assignElem); // assign value to a text node key (from nodeset) void assign(const Arabica::DOM::Text& key, const Arabica::XPath::NodeSet& value, const Arabica::DOM::Element& assignElem); NodeSetVariableResolver _varResolver; XPathFunctionResolver _funcResolver; }; #ifdef BUILD_AS_PLUGINS PLUMA_INHERIT_PROVIDER(XPathDataModel, DataModelImpl); #endif } #endif /* end of include guard: XPATHDATAMODEL_H_KN8TWG0V */