Adding ramlparser implementation for simulator.
authorAbitha Shankar <abitha.s@samsung.com>
Thu, 27 Aug 2015 07:57:31 +0000 (13:27 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Thu, 27 Aug 2015 10:39:14 +0000 (10:39 +0000)
1. Source code for RAML file parsing logic.
2. Implementation uses the external Yaml cpp parser.
3. Parser reads all the resources, its supported methods and respective responses from RAML.

Change-Id: I131cfa4d0cfcaa67ee974650a0206a623ac3bf3d
Signed-off-by: Abitha Shankar <abitha.s@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2233
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
38 files changed:
extlibs/yaml/SConscript [new file with mode: 0755]
service/simulator/SConscript
service/simulator/examples/README.txt [new file with mode: 0755]
service/simulator/examples/resources/light.raml [new file with mode: 0755]
service/simulator/examples/resources/oic.light.json [new file with mode: 0755]
service/simulator/examples/server/service_provider.cpp
service/simulator/ramlparser/SConscript [new file with mode: 0755]
service/simulator/ramlparser/raml/IncludeResolver.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/IncludeResolver.h [new file with mode: 0755]
service/simulator/ramlparser/raml/RamlParser.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/RamlParser.h [new file with mode: 0755]
service/simulator/ramlparser/raml/Utils.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/AbstractParam.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/model/AbstractParam.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/Action.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/model/Action.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/ActionType.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/DocumentationItem.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/model/DocumentationItem.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/FormParameter.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/Header.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/QueryParameter.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/Raml.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/model/Raml.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/RamlResource.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/model/RamlResource.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/RequestResponseBody.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/model/RequestResponseBody.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/ResourceProperties.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/model/ResourceProperties.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/Response.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/model/Response.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/Schema.cpp [new file with mode: 0755]
service/simulator/ramlparser/raml/model/Schema.h [new file with mode: 0755]
service/simulator/ramlparser/raml/model/UriParameter.h [new file with mode: 0755]
service/simulator/src/resource_manager.cpp
service/simulator/src/simulator_resource_creator.cpp
service/simulator/src/simulator_resource_creator.h

diff --git a/extlibs/yaml/SConscript b/extlibs/yaml/SConscript
new file mode 100755 (executable)
index 0000000..4cd8948
--- /dev/null
@@ -0,0 +1,54 @@
+#******************************************************************\r
+#\r
+# Copyright 2014 Samsung Electronics All Rights Reserved.\r
+#\r
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+#      http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+#\r
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+import os\r
+Import('env')\r
+\r
+yaml_env = env.Clone()\r
+src_dir = env.get('SRC_DIR')\r
+\r
+yamlDir = os.path.join(src_dir, 'extlibs','yaml','yaml')\r
+\r
+if not os.path.exists(yamlDir):\r
+    print '''\r
+*********************************** Error: ****************************************\r
+* Please download yaml using the following command:                               *\r
+*     $ git clone https://github.com/jbeder/yaml-cpp.git extlibs/yaml/yaml *\r
+***********************************************************************************\r
+'''\r
+    Exit(1)\r
+\r
+######################################################################\r
+# Build flags\r
+######################################################################\r
+yaml_env.AppendUnique(CPPPATH = ['yaml/src' , 'yaml/include'])\r
+yaml_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])\r
+yaml_env.AppendUnique(CPPDEFINES = ['LINUX'])\r
+yaml_env.AppendUnique(LIBS = ['pthread'])\r
+\r
+yaml_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])\r
+\r
+######################################################################\r
+# Source files and Targets\r
+######################################################################\r
+yaml_src = [env.Glob('yaml/src/*.cpp'), env.Glob('yaml/src/contrib/*.cpp')]\r
+yamlsdk = yaml_env.StaticLibrary('YamlParser', yaml_src)\r
+\r
+yaml_env.InstallTarget(yamlsdk, 'libYaml')\r
index 8363afc..ce9a46c 100644 (file)
@@ -40,6 +40,9 @@ simulator_env.AppendUnique(CPPPATH = [
                '../../resource/csdk/ocrandom/include',
                '../../resource/csdk/logger/include',
                '../../resource/oc_logger/include',
+               './ramlparser/raml',
+               './ramlparser/raml/model',              
+               '../../extlibs/yaml/yaml/include'
                ])
 
 # Including Java path for building JNI files
@@ -61,7 +64,7 @@ java_headers.append(os.path.join(java_headers[0], 'solaris'))
 simulator_env.AppendUnique(CPPPATH = java_headers)
 
 simulator_env.AppendUnique(CPPPATH = ['../../extlibs/cjson'])
-simulator_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap'])
+simulator_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap','RamlParser','YamlParser'])
 simulator_env.AppendUnique(LIBS = ['pthread'])
 
 simulator_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])
@@ -77,3 +80,5 @@ simulator_env.InstallTarget(simulatorsdk, 'libSimulator')
 #Build sample application
 SConscript('examples/server/SConscript')
 SConscript('examples/client-controller/SConscript')
+#Raml Parser
+SConscript('ramlparser/SConscript')
diff --git a/service/simulator/examples/README.txt b/service/simulator/examples/README.txt
new file mode 100755 (executable)
index 0000000..1bec229
--- /dev/null
@@ -0,0 +1,3 @@
+Command to run Service Provider with Resource definitions provided throught RAML file :\r
+./simulator-server  ../../../../../../../../service/simulator/examples/resources/light.raml\r
+\r
diff --git a/service/simulator/examples/resources/light.raml b/service/simulator/examples/resources/light.raml
new file mode 100755 (executable)
index 0000000..db3e037
--- /dev/null
@@ -0,0 +1,27 @@
+#%RAML 0.8
+#RAML for Light Resource
+title: Resource Light
+version: 1.0
+mediaType : application/json
+schemas:
+- 
+  lightPublish: !include oic.light.json
+
+/oic/light:
+  displayName: Resource Light
+  description: |
+    Resource to be exposed by any OIC Device that can act as Light
+  get:
+    description: |
+      Get the attributes of light
+    responses:
+      200:
+        description: |
+          Respond with the selector criteria
+        body:
+          application/json:
+            schema: !include oic.light.json
+            example: |
+              {
+              
+              }
\ No newline at end of file
diff --git a/service/simulator/examples/resources/oic.light.json b/service/simulator/examples/resources/oic.light.json
new file mode 100755 (executable)
index 0000000..fd27af8
--- /dev/null
@@ -0,0 +1,21 @@
+{\r
+  "title": "light",\r
+  "rt": "oic.light",\r
+  "if": "oic.if.baseline",\r
+  "properties": {\r
+    "power": {\r
+      "type": "string",\r
+      "description": "Light status",\r
+      "values": ["on","off"],\r
+      "default": "on",\r
+      "update_frequency": 1000\r
+    },\r
+    "intensity": {\r
+      "type": "integer",\r
+      "description": "brightness of the light",\r
+      "range": [1,9],\r
+      "default": 1,\r
+      "update_frequency": 1001\r
+    }\r
+  }\r
+}
\ No newline at end of file
index a15ce05..6413b12 100644 (file)
@@ -33,7 +33,7 @@ std::shared_ptr<AppLogger> gAppLogger(new AppLogger());
 class SimLightResource
 {
     public:
-        void startTest()
+        void startTest(std::string &configPath)
         {
             printMenu();
             bool cont = true;
@@ -49,7 +49,7 @@ class SimLightResource
 
                 switch (choice)
                 {
-                    case 1: simulateResource(); break;
+                    case 1 : simulateResource(configPath); break;
                     case 2: displayResource(); break;
                     case 3: deleteResource(); break;
                     case 4: updateAttributePower(); break;
@@ -121,11 +121,12 @@ class SimLightResource
             std::cout << "########################" << std::endl;
         }
 
-        void simulateResource()
+        void simulateResource(std::string &configPath)
         {
             SimulatorResourceServer::ResourceModelChangedCB callback = std::bind(
                         &SimLightResource::onResourceModelChanged, this, std::placeholders::_1, std::placeholders::_2);
-            SimulatorResourceServerPtr resource = SimulatorManager::getInstance()->createResource("", callback);
+            SimulatorResourceServerPtr resource = SimulatorManager::getInstance()->createResource(configPath,
+                                                  callback);
             if (NULL == resource.get())
                 std::cout << "Failed to create resource" << std::endl;
 
@@ -466,10 +467,16 @@ class SimLightResource
 void printMainMenu()
 {
     std::cout << "############### MAIN MENU###############" << std::endl;
-    std::cout << "1. Test simulation of light resource" << std::endl;
+    std::cout << "1. Test simulation of resource" << std::endl;
     std::cout << "2. Set Logger" << std::endl;
     std::cout << "3. Help" << std::endl;
     std::cout << "0. Exit" << std::endl;
+    std::cout <<
+              "To set the Resource from RAML file, run the service provider with argument of Path of Raml File."
+              << std::endl;
+    std::cout <<
+              "Example: ./simulator-server  ../../../../../../../../service/simulator/examples/resources/light.raml"
+              << std::endl;
     std::cout << "######################################" << std::endl;
 }
 
@@ -506,8 +513,18 @@ void setLogger()
     }
 }
 
-int main(void)
+int main(int argc, char *argv[])
 {
+    std::string configPath = "";
+    if (argc == 2)
+    {
+        char *value = argv[1];
+        configPath.append(value);
+    }
+    else
+    {
+        configPath = "";
+    }
     SimLightResource lightResource;
 
     printMainMenu();
@@ -524,7 +541,7 @@ int main(void)
 
         switch (choice)
         {
-            case 1: lightResource.startTest();
+            case 1: lightResource.startTest(configPath);
                 std::cout << "Welcome back to main menu !" << std::endl;
                 break;
             case 2: setLogger(); break;
diff --git a/service/simulator/ramlparser/SConscript b/service/simulator/ramlparser/SConscript
new file mode 100755 (executable)
index 0000000..51e8fdd
--- /dev/null
@@ -0,0 +1,50 @@
+#******************************************************************\r
+#\r
+# Copyright 2014 Samsung Electronics All Rights Reserved.\r
+#\r
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+#      http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+#\r
+#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+import os\r
+Import('env')\r
+lib_env = env.Clone()\r
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')\r
+raml_env = lib_env.Clone()\r
+\r
+######################################################################\r
+# Build flags\r
+######################################################################\r
+raml_env.AppendUnique(CPPPATH = ['../../../extlibs/timer'])\r
+raml_env.AppendUnique(CPPPATH = ['raml/model','raml', '../../../extlibs/yaml/yaml/src' , '../../../extlibs/yaml/yaml/include'])\r
+raml_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])\r
+raml_env.AppendUnique(CPPDEFINES = ['LINUX'])\r
+\r
+raml_env.AppendUnique(CPPPATH = ['../../../extlibs/cjson/'])\r
+raml_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'libcoap','YamlParser'])\r
+raml_env.AppendUnique(LIBS = ['pthread'])\r
+\r
+raml_env.AppendUnique(CXXFLAGS = ['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])\r
+\r
+######################################################################\r
+# Source files and Targets\r
+######################################################################\r
+raml_src = [env.Glob('raml/model/*.cpp'), env.Glob('raml/*.cpp')]\r
+ramlsdk = raml_env.SharedLibrary('RamlParser', raml_src)\r
+\r
+raml_env.InstallTarget(ramlsdk, 'libRaml')\r
+\r
+SConscript('../../../extlibs/yaml/SConscript')\r
+\r
diff --git a/service/simulator/ramlparser/raml/IncludeResolver.cpp b/service/simulator/ramlparser/raml/IncludeResolver.cpp
new file mode 100755 (executable)
index 0000000..6065224
--- /dev/null
@@ -0,0 +1,73 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "IncludeResolver.h"\r
+\r
+namespace RAML\r
+{\r
+\r
+    YAML::Node IncludeResolver::readToYamlNode(const YAML::Node &yamlFile )\r
+    {\r
+        std::string value = yamlFile.as<std::string>();\r
+        YAML::Node yamlInclueNode = YAML::LoadFile(value);\r
+        return yamlInclueNode;\r
+    }\r
+\r
+    IncludeResolver::FileType IncludeResolver::getFileType(const YAML::Node &yamlNode )\r
+    {\r
+        IncludeResolver::FileType fileType = IncludeResolver::FileType::NOTAG;\r
+        if (yamlNode.Tag() == "!include")\r
+        {\r
+            std::string value = yamlNode.as<std::string>();\r
+            std::size_t found = value.find_last_of(".");\r
+            if (found > value.length())\r
+            {\r
+                fileType = IncludeResolver::FileType::FILE;\r
+                return fileType;\r
+            }\r
+            std::string extension = value.substr(found + 1);\r
+            if (std::find(Keys::AllowedRamlYamlTypes.begin(), Keys::AllowedRamlYamlTypes.end(),\r
+                          extension) != Keys::AllowedRamlYamlTypes.end())\r
+                fileType = IncludeResolver::FileType::NODE;\r
+            else if (extension == Keys::Json)\r
+                fileType = IncludeResolver::FileType::JSON;\r
+            else\r
+                fileType = IncludeResolver::FileType::FILE;\r
+        }\r
+        return fileType;\r
+    }\r
+\r
+    cJSON *IncludeResolver::readToJson(const YAML::Node &jsonFile)\r
+    {\r
+        return cJSON_Parse(readFromFile(jsonFile).c_str());\r
+    }\r
+\r
+    std::string IncludeResolver::readFromFile(const YAML::Node &file )\r
+    {\r
+        std::string val = file.as<std::string>();\r
+        std::ifstream fin((m_path + val).c_str());\r
+        if (!fin)\r
+            throw std::runtime_error("Error Include File not present ");\r
+        std::stringstream buffer;\r
+        buffer << fin.rdbuf();\r
+        return buffer.str();\r
+    }\r
+\r
+}\r
diff --git a/service/simulator/ramlparser/raml/IncludeResolver.h b/service/simulator/ramlparser/raml/IncludeResolver.h
new file mode 100755 (executable)
index 0000000..cb2cac3
--- /dev/null
@@ -0,0 +1,55 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef INCLUDE_RESOLVER_H\r
+#define INCLUDE_RESOLVER_H\r
+\r
+#include "yaml-cpp/yaml.h"\r
+#include "cJSON.h"\r
+#include "Utils.h"\r
+#include <fstream>\r
+#include "yaml-cpp/exceptions.h"\r
+\r
+namespace RAML\r
+{\r
+    class IncludeResolver\r
+    {\r
+\r
+        public:\r
+            enum class FileType\r
+            {\r
+                NODE, JSON, FILE, NOTAG , ERROR\r
+            };\r
+\r
+\r
+        public:\r
+            YAML::Node readToYamlNode(const YAML::Node &yamlFile );\r
+            cJSON *readToJson(const YAML::Node &jsonFile );\r
+            std::string readFromFile(const YAML::Node &file );\r
+            FileType getFileType(const YAML::Node &yamlNode );\r
+\r
+            IncludeResolver() {}\r
+            IncludeResolver(std::string &path) : m_path(path) {}\r
+        private:\r
+            std::string m_path;\r
+    };\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/RamlParser.cpp b/service/simulator/ramlparser/raml/RamlParser.cpp
new file mode 100755 (executable)
index 0000000..e9e4d0e
--- /dev/null
@@ -0,0 +1,246 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "RamlParser.h"\r
+#include <map>\r
+\r
+namespace RAML\r
+{\r
+    RamlPtr RamlParser::build()\r
+    {\r
+        YAML::Node yamlRootNode = YAML::LoadFile(m_fileLocation + m_ramlName);\r
+        m_ramlPtr->readRamlFromYaml(yamlRootNode);\r
+        setDataFromRoot();\r
+        return (m_ramlPtr);\r
+\r
+    }\r
+    RamlPtr RamlParser::getRamlPtr()\r
+    {\r
+        return m_ramlPtr;\r
+    }\r
+    void RamlParser::setDataFromRoot()\r
+    {\r
+        setTypes(getRamlPtr()->getResources());\r
+        setTraits(getRamlPtr()->getResources());\r
+        setBodyDefaultMediaType(getRamlPtr()->getResources());\r
+        setBodySchema(getRamlPtr()->getResources());\r
+    }\r
+    void RamlParser::setBodyDefaultMediaType(std::map<std::string, RamlResource> resource)\r
+    {\r
+        if (getRamlPtr()->getMediaType().empty())\r
+        {\r
+            return;\r
+        }\r
+        for (auto it : resource)\r
+        {\r
+            std::string type = getRamlPtr()->getMediaType();\r
+\r
+            for (auto  action :  it.second.getActions())\r
+            {\r
+                if (action.second.getRequestBody().empty())\r
+                {\r
+                    std::string resName = it.first;\r
+                    getRamlPtr()->getResource(resName).getAction(action.first).setRequestBody(type);\r
+                }\r
+                for (auto  response : action.second.getResponses())\r
+                {\r
+                    if (response.second.getResponseBody().empty())\r
+                    {\r
+                        std::string resName = it.first;\r
+                        std::string responseCode = response.first;\r
+                        getRamlPtr()->getResource(resName).getAction(action.first).getResponse(\r
+                            responseCode).setResponseBody(\r
+                                type);\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+    void RamlParser::setBodySchema(std::map<std::string, RamlResource> resource)\r
+    {\r
+        if (getRamlPtr()->getSchemas().empty())\r
+        {\r
+            return;\r
+        }\r
+        for (auto  it : resource)\r
+        {\r
+            for (auto  action :  it.second.getActions())\r
+            {\r
+                for (auto  body :  action.second.getRequestBody())\r
+                {\r
+                    Schema *schema = body.second.getSchema();\r
+\r
+                    if (schema != NULL)\r
+                    {\r
+                        std::string schemaValue = schema->getSchema();\r
+                        auto pos = std::find_if(getRamlPtr()->getSchemas().begin(), getRamlPtr()->getSchemas().end(),\r
+                                                [schemaValue](std::pair<std::string, Schema> const & pair)\r
+                        {\r
+                            return (pair.first == schemaValue);\r
+                        });\r
+                        if (pos != getRamlPtr()->getSchemas().end())\r
+                        {\r
+                            schema->setSchema((pos->second.getSchema()));\r
+                        }\r
+                    }\r
+                }\r
+                for (auto  response : action.second.getResponses())\r
+                {\r
+                    for (auto  body :  response.second.getResponseBody())\r
+                    {\r
+                        Schema *schema = body.second.getSchema();\r
+                        if (schema != NULL)\r
+                        {\r
+                            std::string schemaValue = schema->getSchema();\r
+                            auto schemas = getRamlPtr()->getSchemas();\r
+\r
+                            auto iter = schemas.begin();\r
+                            for (; iter != schemas.end(); iter++)\r
+                            {\r
+                                if (((*iter).first) == schemaValue)\r
+                                    break;\r
+                            }\r
+                            if (iter != schemas.end())\r
+                            {\r
+                                schema->setSchema((*iter).second.getSchema());\r
+                            }\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+    void RamlParser::setTypes(std::map<std::string, RamlResource> resource)\r
+    {\r
+        if (getRamlPtr()->getResourceTypes().empty())\r
+        {\r
+            return;\r
+        }\r
+        for (auto  it : resource)\r
+        {\r
+            auto resourceTypes = getRamlPtr()->getResourceTypes();\r
+            std::string typeValue = it.second.getResourceType();\r
+\r
+            auto iter = resourceTypes.begin();\r
+            for (; iter != resourceTypes.end(); iter++)\r
+            {\r
+                if (((*iter).first) == typeValue)\r
+                    break;\r
+            }\r
+            if (iter != resourceTypes.end())\r
+            {\r
+                std::string resName = it.first;\r
+                RamlResource &res = getRamlPtr()->getResource(resName);\r
+                RamlResource resType =  (*iter).second;\r
+\r
+                if (resType.getActions().empty())\r
+                    return;\r
+\r
+                for (auto resActions : resType.getActions())\r
+                {\r
+                    if (res.getActions().count(resActions.first) == 0)\r
+                        res.setAction(resActions.first, resActions.second);\r
+                }\r
+            }\r
+        }\r
+    }\r
+    void RamlParser::setTraits(std::map<std::string, RamlResource> resource)\r
+    {\r
+        if (getRamlPtr()->getTraits().empty())\r
+        {\r
+            return;\r
+        }\r
+        for (auto  it : resource)\r
+        {\r
+            auto trait = getRamlPtr()->getTraits();\r
+            for (auto act : it.second.getActions())\r
+            {\r
+                for (std::string  traitValue :  act.second.getTraits())\r
+                {\r
+                    auto iter = trait.begin();\r
+                    for (; iter != trait.end(); iter++)\r
+                    {\r
+                        if (((*iter).first) == traitValue)\r
+                            break;\r
+                    }\r
+                    if (iter != trait.end())\r
+                    {\r
+                        std::string resName = it.first;\r
+                        RamlResource &res = getRamlPtr()->getResource(resName);\r
+                        Action resTrait =  (*iter).second;\r
+\r
+                        Action &action = res.getAction(act.first);\r
+                        for (auto head : resTrait.getHeaders())\r
+                        {\r
+                            if (action.getHeaders().count(head.first) == 0)\r
+                                action.setHeader(head.first, head.second);\r
+                        }\r
+                        for (auto query : resTrait.getQueryParameters())\r
+                        {\r
+                            if (action.getQueryParameters().count(query.first) == 0)\r
+                                action.setQueryParameter(query.first, query.second);\r
+                        }\r
+                        for (auto resp : resTrait.getResponses())\r
+                        {\r
+                            if (action.getResponses().count(resp.first) == 0)\r
+                                action.setResponse(resp.first, resp.second);\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+            for (std::string  traitValue :  it.second.getTraits())\r
+            {\r
+                auto iter = trait.begin();\r
+                for (; iter != trait.end(); iter++)\r
+                {\r
+                    if (((*iter).first) == traitValue)\r
+                        break;\r
+                }\r
+                if (iter != trait.end())\r
+                {\r
+                    std::string resName = it.first;\r
+                    RamlResource &res = getRamlPtr()->getResource(resName);\r
+                    Action resTrait =  (*iter).second;\r
+\r
+                    for (auto act : res.getActions())\r
+                    {\r
+                        Action &action = res.getAction(act.first);\r
+                        for (auto head : resTrait.getHeaders())\r
+                        {\r
+                            if (action.getHeaders().count(head.first) == 0)\r
+                                action.setHeader(head.first, head.second);\r
+                        }\r
+                        for (auto query : resTrait.getQueryParameters())\r
+                        {\r
+                            if (action.getQueryParameters().count(query.first) == 0)\r
+                                action.setQueryParameter(query.first, query.second);\r
+                        }\r
+                        for (auto resp : resTrait.getResponses())\r
+                        {\r
+                            if (action.getResponses().count(resp.first) == 0)\r
+                                action.setResponse(resp.first, resp.second);\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+}\r
diff --git a/service/simulator/ramlparser/raml/RamlParser.h b/service/simulator/ramlparser/raml/RamlParser.h
new file mode 100755 (executable)
index 0000000..5db9c20
--- /dev/null
@@ -0,0 +1,59 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef RAML_PARSER_H\r
+#define RAML_PARSER_H\r
+\r
+#include "yaml-cpp/yaml.h"\r
+#include "Raml.h"\r
+#include "Utils.h"\r
+#include "RequestResponseBody.h"\r
+#include "RamlResource.h"\r
+#include "Action.h"\r
+#include "Response.h"\r
+#include <map>\r
+\r
+namespace RAML\r
+{\r
+    class RamlParser\r
+    {\r
+        private:\r
+            void setDataFromRoot();\r
+            void setBodyDefaultMediaType(std::map<std::string, RamlResource> resource);\r
+            void setBodySchema(std::map<std::string, RamlResource> resource);\r
+            void setTypes(std::map<std::string, RamlResource> resource);\r
+            void setTraits(std::map<std::string, RamlResource> resource);\r
+\r
+        public:\r
+            virtual RamlPtr build();\r
+            virtual RamlPtr getRamlPtr();\r
+            RamlParser(): m_ramlPtr(new Raml()) {}\r
+            RamlParser(std::string &fileLocation,\r
+                       std::string &ramlName): m_ramlPtr(new Raml(fileLocation)) ,\r
+                m_fileLocation(fileLocation) , m_ramlName(ramlName) {}\r
+        private:\r
+\r
+            RamlPtr m_ramlPtr;\r
+            std::string m_fileLocation;\r
+            std::string m_ramlName;\r
+    };\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/Utils.h b/service/simulator/ramlparser/raml/Utils.h
new file mode 100755 (executable)
index 0000000..9daef9f
--- /dev/null
@@ -0,0 +1,119 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+\r
+#ifndef UTILS_H\r
+#define UTILS_H\r
+\r
+#include "yaml-cpp/yaml.h"\r
+#include "ActionType.h"\r
+\r
+namespace RAML\r
+{\r
+    namespace Keys\r
+    {\r
+        const std::string Title = "title";\r
+        const std::string Version = "version";\r
+        const std::string BaseUri = "baseUri";\r
+        const std::string Protocols = "protocols";\r
+        const std::string MediaType = "mediaType";\r
+        const std::string Schemas = "schemas";\r
+        const std::string ResourceTypes = "resourceTypes";\r
+        const std::string Traits = "traits";\r
+        const std::string IsTrait = "is";\r
+\r
+        const std::string Resource = "/";\r
+        const std::vector<std::string> ActionType = {"get", "post", "put", "delete", "head", "patch", "options", "trace"};\r
+\r
+        const std::string Responses = "responses";\r
+        const std::string Body = "body";\r
+        const std::string Schema = "schema";\r
+        const std::string Example = "example";\r
+\r
+        const std::string BaseUriParameters = "baseUriParameters";\r
+        const std::string UriParameters = "uriParameters";\r
+        const std::string Headers = "headers";\r
+        const std::string QueryParameters = "queryParameters";\r
+        const std::string FormParameters = "formParameters";\r
+        const std::string DisplayName = "displayName";\r
+        const std::string Description = "description";\r
+        const std::string Type = "type";\r
+        const std::string Enum = "enum";\r
+        const std::string Pattern = "pattern";\r
+        const std::string MinLength = "minLength";\r
+        const std::string MaxLength = "maxLength";\r
+        const std::string Minimum = "minimum";\r
+        const std::string Maximum = "maximum";\r
+        const std::string Repeat = "repeat";\r
+        const std::string Required = "required";\r
+        const std::string Default = "default";\r
+\r
+        const std::string Documentation = "documentation";\r
+        const std::string Content = "content";\r
+\r
+        const std::string Json = "json";\r
+        const std::vector<std::string> AllowedRamlYamlTypes = {"raml", "yaml", "yml"};\r
+\r
+    }\r
+\r
+\r
+#define READ_NODE_AS_STRING(yamlNode)                   \\r
+({                                                      \\r
+(yamlNode).as<std::string>();                           \\r
+})\r
+\r
+#define READ_NODE_AS_INT(yamlNode)                      \\r
+({                                                      \\r
+    (yamlNode).as<int>();                               \\r
+})\r
+\r
+#define READ_NODE_AS_LONG(yamlNode)                     \\r
+({                                                      \\r
+    (yamlNode).as<long>();                              \\r
+})\r
+#define READ_NODE_AS_BOOL(yamlNode)                     \\r
+({                                                      \\r
+        (yamlNode).as<bool>();                          \\r
+})\r
+\r
+#define GET_ACTION_TYPE(key)                            \\r
+({                                                      \\r
+    ActionType actionType;                              \\r
+    if (key == "get" )                                  \\r
+        actionType = ActionType::GET;                               \\r
+    else if (key == "post" )                            \\r
+        actionType = ActionType::POST;                              \\r
+    else if (key == "put" )                             \\r
+        actionType = ActionType::PUT;                               \\r
+    else if (key == "delete" )                          \\r
+        actionType = ActionType::DELETE;                            \\r
+    else if (key == "head" )                            \\r
+        actionType = ActionType::HEAD;                              \\r
+    else if (key == "patch" )                           \\r
+        actionType = ActionType::PATCH;                             \\r
+    else if (key == "options" )                         \\r
+        actionType = ActionType::OPTIONS;                           \\r
+    else if (key == "trace" )                           \\r
+        actionType = ActionType::TRACE;                             \\r
+    actionType;                                         \\r
+})\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/AbstractParam.cpp b/service/simulator/ramlparser/raml/model/AbstractParam.cpp
new file mode 100755 (executable)
index 0000000..550af9a
--- /dev/null
@@ -0,0 +1,195 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "AbstractParam.h"\r
+\r
+\r
+namespace RAML\r
+{\r
+    std::string AbstractParam::getDefaultValue() const\r
+    {\r
+        return m_defaultValue;\r
+    }\r
+    void AbstractParam::setDefaultValue(const std::string &defaultValue)\r
+    {\r
+        m_defaultValue = defaultValue;\r
+    }\r
+\r
+    std::string AbstractParam::getDescription() const\r
+    {\r
+        return m_description;\r
+    }\r
+\r
+    void AbstractParam::setDescription(const std::string &description)\r
+    {\r
+        m_description = description;\r
+    }\r
+\r
+    std::string AbstractParam::getDisplayName() const\r
+    {\r
+        return m_displayName;\r
+    }\r
+\r
+    void AbstractParam::setDisplayName(const std::string &displayName)\r
+    {\r
+        m_displayName = displayName;\r
+    }\r
+\r
+    std::list<std::string> AbstractParam::getEnumeration() const\r
+    {\r
+        return m_enumeration;\r
+    }\r
+\r
+    void AbstractParam::setEnumeration(const std::string &enumeration)\r
+    {\r
+        m_enumeration.push_back(enumeration);\r
+    }\r
+\r
+    std::string AbstractParam::getExample() const\r
+    {\r
+        return m_example;\r
+    }\r
+\r
+    void AbstractParam::setExample(const std::string &example)\r
+    {\r
+        m_example = example;\r
+    }\r
+\r
+    int AbstractParam::getMaxLength() const\r
+    {\r
+        return m_maxLength;\r
+    }\r
+\r
+    void AbstractParam::setMaxLength(int maxLength)\r
+    {\r
+        m_maxLength = maxLength;\r
+    }\r
+\r
+    int AbstractParam::getMaximum() const\r
+    {\r
+        return m_maximum;\r
+    }\r
+\r
+    void AbstractParam::setMaximum(int maximum)\r
+    {\r
+        m_maximum = maximum;\r
+    }\r
+\r
+    int AbstractParam::getMinLength() const\r
+    {\r
+        return m_minLength;\r
+    }\r
+\r
+    void AbstractParam::setMinLength(int minLength)\r
+    {\r
+        m_minLength = minLength;\r
+    }\r
+\r
+    int AbstractParam::getMinimum() const\r
+    {\r
+        return m_minimum;\r
+    }\r
+\r
+    void AbstractParam::setMinimum(int minimum)\r
+    {\r
+        m_minimum = minimum;\r
+    }\r
+\r
+    std::string AbstractParam::getPattern() const\r
+    {\r
+        return m_pattern;\r
+    }\r
+\r
+    void AbstractParam::setPattern(const std::string &pattern)\r
+    {\r
+        m_pattern = pattern;\r
+    }\r
+\r
+    std::string AbstractParam::getType() const\r
+    {\r
+        return m_type;\r
+    }\r
+\r
+    void AbstractParam::setType(const std::string &type)\r
+    {\r
+        m_type = type;\r
+    }\r
+\r
+    bool AbstractParam::isRepeat() const\r
+    {\r
+        return m_repeat;\r
+    }\r
+\r
+    void AbstractParam::setRepeat(bool repeat)\r
+    {\r
+        m_repeat = repeat;\r
+    }\r
+\r
+    bool AbstractParam::isRequired() const\r
+    {\r
+        return m_required;\r
+    }\r
+\r
+    void AbstractParam::setRequired(bool required)\r
+    {\r
+        m_required = required;\r
+    }\r
+\r
+    void AbstractParam::readParameters(const YAML::Node &yamlNode)\r
+    {\r
+        for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
+        {\r
+            std::string key = READ_NODE_AS_STRING(it->first);\r
+\r
+            if (key == Keys::Description)\r
+                setDescription(READ_NODE_AS_STRING(it->second));\r
+            else if (key == Keys::Default)\r
+                setDefaultValue(READ_NODE_AS_STRING(it->second));\r
+            else if (key == Keys::DisplayName)\r
+                setDisplayName(READ_NODE_AS_STRING(it->second));\r
+\r
+            else if (key == Keys::Example)\r
+                setExample(READ_NODE_AS_STRING(it->second));\r
+            else if (key == Keys::Maximum)\r
+                setMaximum(READ_NODE_AS_LONG(it->second));\r
+            else if (key == Keys::Minimum)\r
+                setMinimum(READ_NODE_AS_LONG(it->second));\r
+            else if (key == Keys::MaxLength)\r
+                setMaxLength(READ_NODE_AS_INT(it->second));\r
+            else if (key == Keys::MinLength)\r
+                setMinLength(READ_NODE_AS_INT(it->second));\r
+\r
+            else if (key == Keys::Pattern)\r
+                setPattern(READ_NODE_AS_STRING(it->second));\r
+            else if (key == Keys::Repeat)\r
+                setRepeat(READ_NODE_AS_BOOL(it->second));\r
+            else if (key == Keys::Required)\r
+                setRequired(READ_NODE_AS_BOOL(it->second));\r
+            else if (key == Keys::Type)\r
+                setType(READ_NODE_AS_STRING(it->second));\r
+            else if (key == Keys::Enum)\r
+            {\r
+                YAML::Node enumNode = it->second;\r
+                for ( YAML::const_iterator tt = enumNode.begin(); tt != enumNode.end(); ++tt )\r
+                    setEnumeration(READ_NODE_AS_STRING(*tt));\r
+            }\r
+        }\r
+    }\r
+}\r
diff --git a/service/simulator/ramlparser/raml/model/AbstractParam.h b/service/simulator/ramlparser/raml/model/AbstractParam.h
new file mode 100755 (executable)
index 0000000..fc3533c
--- /dev/null
@@ -0,0 +1,105 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef ABSTRACT_PARAM_H\r
+#define ABSTRACT_PARAM_H\r
+\r
+\r
+#include <map>\r
+#include <list>\r
+#include <string>\r
+#include "Utils.h"\r
+\r
+\r
+namespace RAML\r
+{\r
+    class AbstractParam\r
+    {\r
+        public:\r
+            virtual std::string getDefaultValue() const;\r
+            virtual void setDefaultValue(const std::string &defaultValue);\r
+\r
+            virtual std::string getDescription() const;\r
+            virtual void setDescription(const std::string &description);\r
+\r
+            virtual std::string getDisplayName() const;\r
+            virtual void setDisplayName(const std::string &displayName);\r
+\r
+            virtual std::list<std::string> getEnumeration() const;\r
+            virtual void setEnumeration(const std::string &enumeration);\r
+\r
+            virtual std::string getExample() const;\r
+            virtual void setExample(const std::string &example);\r
+\r
+            virtual int getMaxLength() const;\r
+            virtual void setMaxLength(int maxLength);\r
+\r
+            virtual int getMaximum() const;\r
+            virtual void setMaximum(int maximum);\r
+\r
+            virtual int getMinLength() const;\r
+            virtual void setMinLength(int minLength);\r
+\r
+            virtual int getMinimum() const;\r
+            virtual void setMinimum(int minimum);\r
+\r
+            virtual std::string getPattern() const;\r
+            virtual void setPattern(const std::string &pattern) ;\r
+\r
+            virtual std::string getType() const;\r
+            virtual void setType(const std::string &type);\r
+\r
+            virtual bool isRepeat() const;\r
+            virtual void setRepeat(bool repeat);\r
+\r
+            virtual bool isRequired() const;\r
+            virtual void setRequired(bool required);\r
+\r
+\r
+            AbstractParam() : m_maximum(0), m_minimum(0), m_minLength(0), m_maxLength(0), m_repeat(false),\r
+                m_required(false) {}\r
+            AbstractParam(const YAML::Node &yamlNode) : m_maximum(0), m_minimum(0), m_minLength(0),\r
+                m_maxLength(0), m_repeat(false), m_required(false)\r
+            {\r
+                readParameters(yamlNode);\r
+            }\r
+        private:\r
+            virtual void readParameters(const YAML::Node &yamlNode);\r
+\r
+        private:\r
+            std::string m_defaultValue;\r
+            std::string m_description;\r
+            std::string m_displayName;\r
+            std::list<std::string> m_enumeration;\r
+            std::string m_example;\r
+            int m_maxLength;\r
+            int m_maximum;\r
+            int m_minLength;\r
+            int m_minimum;\r
+            std::string m_pattern;\r
+            bool m_repeat;\r
+            bool m_required;\r
+            std::string m_type;\r
+\r
+\r
+    };\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/Action.cpp b/service/simulator/ramlparser/raml/model/Action.cpp
new file mode 100755 (executable)
index 0000000..346fa9e
--- /dev/null
@@ -0,0 +1,192 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "Action.h"\r
+\r
+namespace RAML\r
+{\r
+    ActionType Action::getType() const\r
+    {\r
+        return m_type;\r
+    }\r
+    void Action::setType(const ActionType &type)\r
+    {\r
+        m_type = type;\r
+    }\r
+    std::string Action::getDescription() const\r
+    {\r
+        return m_description;\r
+    }\r
+    void Action::setDescription(const std::string &description)\r
+    {\r
+        m_description = description;\r
+    }\r
+    std::map<std::string, Header> Action::getHeaders() const\r
+    {\r
+        return m_headers;\r
+    }\r
+    void Action::setHeader(const std::string &headerName, const Header &header)\r
+    {\r
+        m_headers[headerName] = header;\r
+    }\r
+    std::map<std::string, QueryParameter> Action::getQueryParameters()const\r
+    {\r
+        return m_queryParameters;\r
+    }\r
+    void Action::setQueryParameter(const std::string &paramName, const QueryParameter &queryParameter)\r
+    {\r
+        m_queryParameters[paramName] = queryParameter;\r
+    }\r
+    RequestResponseBody &Action::getRequestBody(std::string bodyType)\r
+    {\r
+        return m_requestBody[bodyType];\r
+    }\r
+\r
+    std::map<std::string, RequestResponseBody> Action::getRequestBody() const\r
+    {\r
+        return m_requestBody;\r
+    }\r
+    void Action::setRequestBody(const std::string &typeName)\r
+    {\r
+        m_requestBody[typeName] = *(new RequestResponseBody(typeName));\r
+    }\r
+\r
+    void Action::setRequestBody(const std::string &typeName , const RequestResponseBody &body)\r
+    {\r
+        m_requestBody[typeName] = body;\r
+    }\r
+    Response &Action::getResponse(std::string responseCode)\r
+    {\r
+        return m_responses[responseCode];\r
+    }\r
+\r
+    std::map<std::string, Response> Action::getResponses() const\r
+    {\r
+        return m_responses;\r
+    }\r
+    void Action::setResponse(const std::string &responseCode, const Response &response)\r
+    {\r
+        m_responses[responseCode] = response;\r
+    }\r
+\r
+    std::list<std::string> Action::getProtocols() const\r
+    {\r
+        return m_protocols;\r
+    }\r
+    void Action::setProtocol(const std::string &protocol)\r
+    {\r
+        m_protocols.push_back(protocol);\r
+    }\r
+    std::map<std::string, UriParameter > Action::getBaseUriParameters() const\r
+    {\r
+        return m_baseUriParameters;\r
+    }\r
+    void Action::setBaseUriParameter(const std::string &paramName ,\r
+                                     const UriParameter  &baseUriParameter)\r
+    {\r
+        m_baseUriParameters[paramName] = baseUriParameter;\r
+    }\r
+\r
+    std::list<std::string> Action::getTraits() const\r
+    {\r
+        return m_trait;\r
+    }\r
+    void Action::setTrait(const std::string &trait)\r
+    {\r
+        m_trait.push_back(trait);\r
+    }\r
+    void Action::readAction(const ActionType actionType, const YAML::Node &yamlNode,\r
+                            IncludeResolver *includeResolver)\r
+    {\r
+        m_includeResolver = includeResolver;\r
+        m_type = actionType;\r
+        for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
+        {\r
+            std::string key = READ_NODE_AS_STRING(it->first);\r
+\r
+            if (key == Keys::Description)\r
+                setDescription(READ_NODE_AS_STRING(it->second));\r
+            else if (key == Keys::Responses)\r
+            {\r
+                YAML::Node responseNode = it->second;\r
+                for ( YAML::const_iterator tt = responseNode.begin(); tt != responseNode.end(); ++tt )\r
+                {\r
+                    std::string responseCode = READ_NODE_AS_STRING(tt->first);\r
+                    setResponse(responseCode, *(new Response(tt->second, m_includeResolver)));\r
+                }\r
+            }\r
+            else if (key == Keys::Headers)\r
+            {\r
+                YAML::Node paramNode = it->second;\r
+                for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
+                {\r
+                    Header *header = new Header(tt->second);\r
+                    setHeader(READ_NODE_AS_STRING(tt->first), *header);\r
+                }\r
+            }\r
+            else if (key == Keys::QueryParameters)\r
+            {\r
+                YAML::Node paramNode = it->second;\r
+                for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
+                {\r
+                    QueryParameter *queryParameter = new QueryParameter(tt->second);\r
+                    setQueryParameter(READ_NODE_AS_STRING(tt->first), *queryParameter);\r
+                }\r
+            }\r
+            else if (key == Keys::Protocols)\r
+            {\r
+                YAML::Node protocolNode = it->second;\r
+                for ( YAML::const_iterator tt = protocolNode.begin(); tt != protocolNode.end(); ++tt )\r
+                {\r
+                    setProtocol(READ_NODE_AS_STRING(*tt));\r
+                }\r
+            }\r
+            else if (key == Keys::BaseUriParameters)\r
+            {\r
+                YAML::Node paramNode = it->second;\r
+                for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
+                {\r
+                    UriParameter *uriParameter = new UriParameter(tt->second);\r
+                    setBaseUriParameter(READ_NODE_AS_STRING(tt->first), *uriParameter);\r
+                }\r
+            }\r
+            else if (key == Keys::Body)\r
+            {\r
+                YAML::Node responseBody = it->second;\r
+\r
+                for ( YAML::const_iterator tt = responseBody.begin(); tt != responseBody.end(); ++tt )\r
+                {\r
+                    std::string type = READ_NODE_AS_STRING(tt->first);\r
+                    setRequestBody(type, *(new RequestResponseBody(type, tt->second, m_includeResolver)));\r
+                }\r
+            }\r
+            else if (key == Keys::IsTrait)\r
+            {\r
+                YAML::Node traitNode = it->second;\r
+                for ( YAML::const_iterator tt = traitNode.begin(); tt != traitNode.end(); ++tt )\r
+                {\r
+                    setTrait(READ_NODE_AS_STRING(*tt));\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+};\r
+\r
diff --git a/service/simulator/ramlparser/raml/model/Action.h b/service/simulator/ramlparser/raml/model/Action.h
new file mode 100755 (executable)
index 0000000..c843bf4
--- /dev/null
@@ -0,0 +1,91 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef ACTION_H\r
+#define ACTION_H\r
+\r
+#include <map>\r
+#include <list>\r
+#include <string>\r
+#include "ActionType.h"\r
+#include "Header.h"\r
+#include "QueryParameter.h"\r
+#include "RequestResponseBody.h"\r
+#include "UriParameter.h"\r
+#include "Response.h"\r
+#include "Utils.h"\r
+#include "IncludeResolver.h"\r
+\r
+namespace RAML\r
+{\r
+    class Action\r
+    {\r
+        public:\r
+            virtual ActionType getType() const;\r
+            virtual void setType(const ActionType &type);\r
+            virtual std::string getDescription() const;\r
+            virtual void setDescription(const std::string &description);\r
+            virtual std::map<std::string, Header> getHeaders() const;\r
+            virtual void setHeader(const std::string &headerName, const Header &header);\r
+            virtual std::map<std::string, QueryParameter> getQueryParameters()const;\r
+            virtual void setQueryParameter(const std::string &paramName, const QueryParameter &queryParameter);\r
+            virtual RequestResponseBody &getRequestBody(std::string bodyType);\r
+            virtual std::map<std::string, RequestResponseBody> getRequestBody() const;\r
+            virtual void setRequestBody(const std::string &typeName);\r
+            virtual void setRequestBody(const std::string &typeName , const RequestResponseBody &body);\r
+            virtual Response &getResponse(std::string responseCode);\r
+            virtual std::map<std::string, Response> getResponses() const;\r
+            virtual void setResponse(const std::string &responseCode, const Response &response);\r
+            virtual std::list<std::string> getProtocols() const;\r
+            virtual void setProtocol(const std::string &protocol);\r
+            virtual std::map< std::string, UriParameter > getBaseUriParameters() const;\r
+            virtual void setBaseUriParameter(const std::string &paramName ,\r
+                                             const UriParameter  &baseUriParameter);\r
+            virtual std::list<std::string> getTraits() const;\r
+            virtual void setTrait(const std::string &trait);\r
+\r
+\r
+            Action() { }\r
+            Action(const ActionType actionType, const YAML::Node &yamlNode, IncludeResolver *includeResolver)\r
+            {\r
+                readAction(actionType, yamlNode, includeResolver);\r
+            }\r
+\r
+        private:\r
+            virtual void readAction(const ActionType actionType, const YAML::Node &yamlNode,\r
+                                    IncludeResolver *includeResolver);\r
+\r
+\r
+        private:\r
+            ActionType m_type;\r
+            std::string m_description;\r
+            std::map<std::string, Header> m_headers;\r
+            std::map<std::string, QueryParameter> m_queryParameters;\r
+            std::map<std::string, RequestResponseBody> m_requestBody;\r
+            std::map<std::string, Response> m_responses;\r
+            std::list<std::string> m_protocols;\r
+            std::map< std::string, UriParameter > m_baseUriParameters;\r
+            std::list<std::string> m_trait;\r
+\r
+        private:\r
+            IncludeResolver *m_includeResolver;\r
+    };\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/ActionType.h b/service/simulator/ramlparser/raml/model/ActionType.h
new file mode 100755 (executable)
index 0000000..8921b1e
--- /dev/null
@@ -0,0 +1,32 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef ACTION_TYPE_H\r
+#define ACTION_TYPE_H\r
+\r
+namespace RAML\r
+{\r
+    enum class ActionType\r
+    {\r
+        GET, POST, PUT, DELETE, HEAD, PATCH, OPTIONS, TRACE, NONE\r
+    };\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/DocumentationItem.cpp b/service/simulator/ramlparser/raml/model/DocumentationItem.cpp
new file mode 100755 (executable)
index 0000000..4b83366
--- /dev/null
@@ -0,0 +1,43 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "DocumentationItem.h"\r
+\r
+namespace RAML\r
+{\r
+\r
+    std::string DocumentationItem::getTitle() const\r
+    {\r
+        return m_title;\r
+    }\r
+    void DocumentationItem::setTitle(const std::string &title)\r
+    {\r
+        m_title = title;\r
+    }\r
+    std::string DocumentationItem::getContent() const\r
+    {\r
+        return m_content;\r
+    }\r
+    void DocumentationItem::setContent(const std::string &content)\r
+    {\r
+        m_content = content;\r
+    }\r
+\r
+}\r
diff --git a/service/simulator/ramlparser/raml/model/DocumentationItem.h b/service/simulator/ramlparser/raml/model/DocumentationItem.h
new file mode 100755 (executable)
index 0000000..d432ede
--- /dev/null
@@ -0,0 +1,48 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef DOCUMENTATION_ITEM_H\r
+#define DOCUMENTATION_ITEM_H\r
+\r
+#include <string>\r
+\r
+\r
+namespace RAML\r
+{\r
+    class DocumentationItem\r
+    {\r
+\r
+        public:\r
+            virtual std::string getTitle() const;\r
+            virtual void setTitle(const std::string &title);\r
+            virtual std::string getContent() const;\r
+            virtual void setContent(const std::string &content);\r
+\r
+            DocumentationItem();\r
+            DocumentationItem(const std::string &title , const std::string &content) : m_title(title),\r
+                m_content(content) {}\r
+        private:\r
+            std::string m_title;\r
+            std::string m_content;\r
+\r
+    };\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/FormParameter.h b/service/simulator/ramlparser/raml/model/FormParameter.h
new file mode 100755 (executable)
index 0000000..b62d954
--- /dev/null
@@ -0,0 +1,36 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef FORM_PARAMETER_H\r
+#define FORM_PARAMETER_H\r
+\r
+#include "AbstractParam.h"\r
+\r
+namespace RAML\r
+{\r
+    class FormParameter: public AbstractParam\r
+    {\r
+        public:\r
+            FormParameter(const YAML::Node &yamlNode) : AbstractParam(yamlNode) {}\r
+            FormParameter() {}\r
+    };\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/Header.h b/service/simulator/ramlparser/raml/model/Header.h
new file mode 100755 (executable)
index 0000000..47e03f7
--- /dev/null
@@ -0,0 +1,37 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef HEADER_PARAMETER_H\r
+#define HEADER_PARAMETER_H\r
+\r
+#include "AbstractParam.h"\r
+\r
+namespace RAML\r
+{\r
+    class Header: public AbstractParam\r
+    {\r
+        public:\r
+            Header(const YAML::Node &yamlNode) : AbstractParam(yamlNode) {}\r
+            Header() {}\r
+    };\r
+\r
+}\r
+#endif\r
+\r
diff --git a/service/simulator/ramlparser/raml/model/QueryParameter.h b/service/simulator/ramlparser/raml/model/QueryParameter.h
new file mode 100755 (executable)
index 0000000..d414378
--- /dev/null
@@ -0,0 +1,36 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef QUERY_PARAMETER_H\r
+#define QUERY_PARAMETER_H\r
+\r
+#include "AbstractParam.h"\r
+\r
+namespace RAML\r
+{\r
+    class QueryParameter: public AbstractParam\r
+    {\r
+        public:\r
+            QueryParameter(const YAML::Node &yamlNode) : AbstractParam(yamlNode) {}\r
+            QueryParameter() {}\r
+    };\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/Raml.cpp b/service/simulator/ramlparser/raml/model/Raml.cpp
new file mode 100755 (executable)
index 0000000..a9864b4
--- /dev/null
@@ -0,0 +1,263 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "Raml.h"\r
+\r
+namespace RAML\r
+{\r
+\r
+    std::string Raml::getTitle() const\r
+    {\r
+        return m_title;\r
+    }\r
+    void Raml::setTitle(const std::string &title)\r
+    {\r
+        m_title = title;\r
+    }\r
+\r
+    std::string Raml::getVersion() const\r
+    {\r
+        return m_version;\r
+    }\r
+    void Raml::setVersion(const std::string &version)\r
+    {\r
+        m_version = version;\r
+    }\r
+\r
+    std::string Raml::getBaseUri() const\r
+    {\r
+        return m_baseUri;\r
+    }\r
+    void Raml::setBaseUri(const std::string &baseUri)\r
+    {\r
+        m_baseUri = baseUri;\r
+    }\r
+\r
+    std::list<std::string> Raml::getProtocols() const\r
+    {\r
+        return m_protocols;\r
+    }\r
+    void Raml::setProtocol(const std::string &protocol)\r
+    {\r
+        m_protocols.push_back(protocol);\r
+    }\r
+    std::map<std::string, UriParameter> Raml::getBaseUriParameters() const\r
+    {\r
+        return m_baseUriParameters;\r
+    }\r
+    void Raml::setBaseUriParameter(const std::string &paramName, const UriParameter &uriParameter)\r
+    {\r
+        m_baseUriParameters[paramName] = uriParameter;\r
+    }\r
+\r
+    std::string Raml::getMediaType() const\r
+    {\r
+        return m_mediaType;\r
+    }\r
+    void Raml::setMediaType(const std::string &mediaType)\r
+    {\r
+        m_mediaType = mediaType;\r
+    }\r
+\r
+    std::list<std::pair<std::string, Schema> > Raml::getSchemas() const\r
+    {\r
+        return m_schemas;\r
+    }\r
+\r
+    void Raml::setSchema(const std::pair<std::string, Schema> &schema)\r
+    {\r
+        m_schemas.push_back(schema);\r
+    }\r
+\r
+    std::list<std::pair<std::string, RamlResource> > Raml::getResourceTypes() const\r
+    {\r
+        return m_resourceTypes;\r
+    }\r
+    void Raml::setResourceType(const std::pair<std::string, RamlResource> &resourceType)\r
+    {\r
+        m_resourceTypes.push_back(resourceType);\r
+    }\r
+\r
+    std::list<std::pair<std::string, Action> > Raml::getTraits() const\r
+    {\r
+        return m_traits;\r
+    }\r
+    void Raml::setTrait(const std::pair<std::string, Action> &trait)\r
+    {\r
+        m_traits.push_back(trait);\r
+    }\r
+    RamlResource &Raml::getResource(std::string resourceName)\r
+    {\r
+        return m_resources[resourceName];\r
+    }\r
+\r
+    std::map<std::string, RamlResource> Raml::getResources() const\r
+    {\r
+        return m_resources;\r
+    }\r
+\r
+    void Raml::setResource(const std::string &resourceKey, const RamlResource &resource)\r
+    {\r
+        m_resources[resourceKey] = resource;\r
+    }\r
+\r
+    void Raml::setDocumentationItem(const DocumentationItem &documentationItem)\r
+    {\r
+        m_documentation.push_back(documentationItem);\r
+    }\r
+\r
+    std::list<DocumentationItem> Raml::getDocumentation() const\r
+    {\r
+        return m_documentation;\r
+    }\r
+    void Raml::readRamlFromYaml(const YAML::Node &yamlNode )\r
+    {\r
+        if (yamlNode.Type() == YAML::NodeType::Map)\r
+        {\r
+            for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
+            {\r
+                std::string key = READ_NODE_AS_STRING(it->first);\r
+                if (key == Keys::Title)\r
+                {\r
+                    setTitle(READ_NODE_AS_STRING(it->second));\r
+                }\r
+                else if (key == Keys::Version)\r
+                {\r
+                    setVersion(READ_NODE_AS_STRING(it->second));\r
+                }\r
+                else if (key == Keys::BaseUri)\r
+                {\r
+                    setBaseUri(READ_NODE_AS_STRING(it->second));\r
+                }\r
+                else if ((key == Keys::BaseUriParameters) || (key == Keys::UriParameters))\r
+                {\r
+                    YAML::Node paramNode = it->second;\r
+                    for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
+                    {\r
+                        UriParameter *uriParameter = new UriParameter(tt->second);\r
+                        setBaseUriParameter(READ_NODE_AS_STRING(tt->first), *uriParameter);\r
+                    }\r
+                }\r
+                else if (key == Keys::Protocols)\r
+                {\r
+                    YAML::Node protocolNode = it->second;\r
+                    for ( YAML::const_iterator tt = protocolNode.begin(); tt != protocolNode.end(); ++tt )\r
+                    {\r
+                        setProtocol(READ_NODE_AS_STRING(*tt));\r
+                    }\r
+                }\r
+                else if (key == Keys::MediaType)\r
+                {\r
+                    setMediaType(READ_NODE_AS_STRING(it->second));\r
+                }\r
+                else if (key == Keys::Documentation)\r
+                {\r
+                    YAML::Node docNode = it->second;\r
+                    for ( YAML::const_iterator iit = docNode.begin(); iit != docNode.end(); ++iit )\r
+                    {\r
+                        std::string title ;\r
+                        std::string content ;\r
+\r
+                        for ( YAML::const_iterator tt = (*iit).begin(); tt != (*iit).end(); ++tt )\r
+                        {\r
+                            std::string key = READ_NODE_AS_STRING(tt->first);\r
+\r
+                            if (key == Keys::Title)\r
+                                title = READ_NODE_AS_STRING(tt->second);\r
+                            else if (key == Keys::Content)\r
+                                content = READ_NODE_AS_STRING(tt->second);\r
+\r
+                        }\r
+                        setDocumentationItem(*(new DocumentationItem(title, content)));\r
+                    }\r
+                }\r
+                else if (key == Keys::Schemas)\r
+                {\r
+                    YAML::Node schemaNode = it->second;\r
+                    for ( YAML::const_iterator iit = schemaNode.begin(); iit != schemaNode.end(); ++iit )\r
+                    {\r
+                        for ( YAML::const_iterator tt = (*iit).begin(); tt != (*iit).end(); ++tt )\r
+                        {\r
+                            std::string key = READ_NODE_AS_STRING(tt->first);\r
+                            std::pair<std::string, Schema> schema;\r
+\r
+                            IncludeResolver::FileType fileType = m_includeResolver->getFileType(tt->second);\r
+                            if ((fileType == IncludeResolver::FileType::JSON) || (fileType == IncludeResolver::FileType::FILE))\r
+                            {\r
+                                Schema *schemaPtr = new Schema(m_includeResolver->readFromFile(tt->second));\r
+                                schema = std::make_pair(key, *schemaPtr);\r
+                            }\r
+                            else\r
+                            {\r
+                                std::string value = READ_NODE_AS_STRING(tt->second);\r
+                                schema = std::make_pair(key, *(new Schema(value)));\r
+                            }\r
+                            setSchema(schema);\r
+                        }\r
+                    }\r
+                }\r
+\r
+                else if (key.compare(0, Keys::Resource.length(), Keys::Resource)  == 0)\r
+                {\r
+                    RamlResource *resource = new RamlResource(key, it->second, m_includeResolver, getBaseUri());\r
+                    setResource(key, *resource);\r
+                }\r
+                else if (key == Keys::Traits)\r
+                {\r
+                    YAML::Node traitNode = it->second;\r
+                    for ( YAML::const_iterator tt = traitNode.begin(); tt != traitNode.end(); ++tt )\r
+                    {\r
+                        for (auto elem : *tt)\r
+                        {\r
+                            std::string trait = READ_NODE_AS_STRING(elem.first);\r
+                            Action *action = new Action(ActionType::NONE, elem.second , m_includeResolver);\r
+\r
+                            std::pair<std::string, Action> resourceTrait;\r
+                            resourceTrait = std::make_pair(trait, *action);\r
+\r
+                            setTrait(resourceTrait);\r
+                        }\r
+                    }\r
+                }\r
+                else if (key == Keys::ResourceTypes)\r
+                {\r
+                    YAML::Node typeNode = it->second;\r
+                    for ( YAML::const_iterator tt = typeNode.begin(); tt != typeNode.end(); ++tt )\r
+                    {\r
+                        for (auto elem : *tt)\r
+                        {\r
+                            std::string type = READ_NODE_AS_STRING(elem.first);\r
+                            RamlResource *resource = new RamlResource(type, elem.second, m_includeResolver, getBaseUri());\r
+\r
+                            std::pair<std::string, RamlResource> resourceType;\r
+                            resourceType = std::make_pair(type, *resource);\r
+\r
+                            setResourceType(resourceType);\r
+\r
+                        }\r
+\r
+                    }\r
+                }\r
+            }\r
+        }\r
+\r
+    }\r
+\r
+}\r
diff --git a/service/simulator/ramlparser/raml/model/Raml.h b/service/simulator/ramlparser/raml/model/Raml.h
new file mode 100755 (executable)
index 0000000..c3c537c
--- /dev/null
@@ -0,0 +1,108 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef RAML_H\r
+#define RAML_H\r
+\r
+#include <map>\r
+#include <list>\r
+#include <string>\r
+#include "AbstractParam.h"\r
+#include "UriParameter.h"\r
+#include "QueryParameter.h"\r
+#include "FormParameter.h"\r
+#include "Header.h"\r
+\r
+#include "RequestResponseBody.h"\r
+#include "RamlResource.h"\r
+#include "ActionType.h"\r
+#include "Action.h"\r
+#include "Response.h"\r
+#include "Schema.h"\r
+#include "IncludeResolver.h"\r
+\r
+#include "DocumentationItem.h"\r
+#include "yaml-cpp/yaml.h"\r
+#include "Utils.h"\r
+#include "cJSON.h"\r
+\r
+\r
+namespace RAML\r
+{\r
+    class Raml\r
+    {\r
+        public:\r
+            virtual std::string getTitle() const;\r
+            virtual void setTitle(const std::string &title);\r
+\r
+            virtual std::string getVersion() const;\r
+            virtual void setVersion(const std::string &version);\r
+\r
+            virtual std::string getBaseUri() const;\r
+            virtual void setBaseUri(const std::string &baseUri);\r
+\r
+            virtual std::list<std::string> getProtocols() const;\r
+            virtual void setProtocol(const std::string &protocol);\r
+\r
+\r
+            virtual std::map<std::string, UriParameter> getBaseUriParameters() const;\r
+            virtual void setBaseUriParameter(const std::string &paramName, const UriParameter &uriParameter);\r
+\r
+            virtual std::string getMediaType() const;\r
+            virtual void setMediaType(const std::string &mediaType);\r
+\r
+            virtual std::list<std::pair<std::string, Schema> > getSchemas() const;\r
+            virtual void setSchema(const std::pair<std::string, Schema> &schema);\r
+\r
+            virtual std::list<std::pair<std::string, RamlResource> > getResourceTypes() const;\r
+            virtual void setResourceType(const std::pair<std::string, RamlResource> &resourceType);\r
+\r
+            virtual std::list<std::pair<std::string, Action> > getTraits() const;\r
+            virtual void setTrait(const std::pair<std::string, Action> &trait);\r
+\r
+            virtual RamlResource &getResource(std::string resourceName);\r
+            virtual std::map<std::string, RamlResource> getResources() const;\r
+            virtual void setResource(const std::string &resourceKey, const RamlResource &resource);\r
+\r
+            virtual void setDocumentationItem(const DocumentationItem &documentationItem);\r
+            virtual std::list<DocumentationItem> getDocumentation() const;\r
+\r
+            void readRamlFromYaml(const YAML::Node &yamlNode);\r
+            Raml() : m_includeResolver(new IncludeResolver()) {}\r
+            Raml(std::string &resourceLocation) : m_includeResolver(new IncludeResolver(resourceLocation)) {}\r
+        private:\r
+            std::string m_title;\r
+            std::string m_version;\r
+            std::string m_baseUri;\r
+            std::list<std::string> m_protocols;\r
+            std::map<std::string, UriParameter> m_baseUriParameters;\r
+            std::string m_mediaType;\r
+            std::list <std::pair<std::string, Schema> > m_schemas;\r
+            std::list <std::pair<std::string, RamlResource> > m_resourceTypes;\r
+            std::list <std::pair<std::string, Action> > m_traits;\r
+            std::map<std::string, RamlResource> m_resources;\r
+            std::list<DocumentationItem> m_documentation;\r
+            IncludeResolver *m_includeResolver;\r
+    };\r
+\r
+    typedef std::shared_ptr<Raml> RamlPtr;\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/RamlResource.cpp b/service/simulator/ramlparser/raml/model/RamlResource.cpp
new file mode 100755 (executable)
index 0000000..df5f617
--- /dev/null
@@ -0,0 +1,178 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "RamlResource.h"\r
+\r
+\r
+namespace RAML\r
+{\r
+    RamlResource *RamlResource::getParentResource()\r
+    {\r
+        return m_parentResource;\r
+    }\r
+    void RamlResource::setParentResource(RamlResource *parentResource)\r
+    {\r
+        m_parentResource = parentResource;\r
+    }\r
+\r
+    std::string RamlResource::getDisplayName() const\r
+    {\r
+        return m_displayName;\r
+    }\r
+    void RamlResource::setDisplayName(const std::string &displayName)\r
+    {\r
+        m_displayName = displayName;\r
+    }\r
+    std::string RamlResource::getDescription() const\r
+    {\r
+        return m_description;\r
+    }\r
+    void RamlResource::setDescription(const std::string &description)\r
+    {\r
+        m_description = description;\r
+    }\r
+    std::string RamlResource::getParentUri() const\r
+    {\r
+        return m_parentUri;\r
+    }\r
+    void RamlResource::setParentUri(const std::string &parentUri)\r
+    {\r
+        m_parentUri = parentUri;\r
+    }\r
+    std::string RamlResource::getRelativeUri() const\r
+    {\r
+        return m_relativeUri;\r
+    }\r
+    void RamlResource::setRelativeUri(const std::string &relativeUri)\r
+    {\r
+        m_relativeUri = relativeUri;\r
+    }\r
+    std::map<std::string, UriParameter> RamlResource::getUriParameters() const\r
+    {\r
+        return m_uriParameters;\r
+    }\r
+    void RamlResource::setUriParameter(const std::string &paramName, const UriParameter &uriParameter)\r
+    {\r
+        m_uriParameters[paramName] = uriParameter;\r
+    }\r
+    std::map<std::string, UriParameter > RamlResource::getBaseUriParameters() const\r
+    {\r
+        return m_baseUriParameters;\r
+    }\r
+    void RamlResource::setBaseUriParameter(const std::string &paramName,\r
+                                           const UriParameter &baseUriParameter)\r
+    {\r
+        m_baseUriParameters[paramName] = baseUriParameter;\r
+    }\r
+    Action &RamlResource::getAction(ActionType actionType)\r
+    {\r
+        return m_actions[actionType];\r
+    }\r
+\r
+    std::map<ActionType , Action> RamlResource::getActions() const\r
+    {\r
+        return m_actions;\r
+    }\r
+    void RamlResource::setAction(const ActionType &actiontype , const Action &action )\r
+    {\r
+        m_actions[actiontype] = action;\r
+    }\r
+    std::map<std::string, RamlResource> RamlResource::getResources() const\r
+    {\r
+        return m_resources;\r
+    }\r
+    void RamlResource::setResource(const std::string &resourceName, const RamlResource &resources)\r
+    {\r
+        m_resources[resourceName] = resources;\r
+    }\r
+    std::list<std::string> RamlResource::getTraits() const\r
+    {\r
+        return m_traits;\r
+    }\r
+    void RamlResource::setTrait(const std::string &trait)\r
+    {\r
+        m_traits.push_back(trait);\r
+    }\r
+    std::string RamlResource::getResourceType() const\r
+    {\r
+        return m_resourceType;\r
+    }\r
+    void RamlResource::setResourceType(const std::string &type)\r
+    {\r
+        m_resourceType = type;\r
+    }\r
+    std::string RamlResource::getResourceUri() const\r
+    {\r
+        return (m_parentUri + m_relativeUri);\r
+    }\r
+    void RamlResource::readResource(const std::string resourceKey, const YAML::Node &yamlNode,\r
+                                    IncludeResolver *includeResolver, const std::string &parentUri)\r
+    {\r
+        m_includeResolver = includeResolver;\r
+        m_relativeUri = resourceKey;\r
+        m_parentUri = parentUri;\r
+        for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
+        {\r
+            std::string key = READ_NODE_AS_STRING(it->first);\r
+\r
+            if (key == Keys::DisplayName)\r
+                setDisplayName(READ_NODE_AS_STRING(it->second));\r
+            else if (key == Keys::Description)\r
+                setDescription(READ_NODE_AS_STRING(it->second));\r
+            else if (std::find(Keys::ActionType.begin(), Keys::ActionType.end(), key) != Keys::ActionType.end())\r
+            {\r
+                ActionType actionType = GET_ACTION_TYPE(key);\r
+\r
+                setAction(actionType, *(new Action(actionType, it->second, m_includeResolver)));\r
+            }\r
+            else if (key == Keys::UriParameters)\r
+            {\r
+                YAML::Node paramNode = it->second;\r
+                for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
+                {\r
+                    UriParameter *uriParameter = new UriParameter(tt->second);\r
+                    setUriParameter(READ_NODE_AS_STRING(tt->first), *uriParameter);\r
+                }\r
+            }\r
+            else if (key == Keys::BaseUriParameters)\r
+            {\r
+                YAML::Node paramNode = it->second;\r
+                for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
+                {\r
+                    UriParameter *uriParameter = new UriParameter(tt->second);\r
+                    setBaseUriParameter(READ_NODE_AS_STRING(tt->first), *uriParameter);\r
+                }\r
+            }\r
+            else if (key == Keys::IsTrait)\r
+            {\r
+                YAML::Node traitNode = it->second;\r
+                for ( YAML::const_iterator tt = traitNode.begin(); tt != traitNode.end(); ++tt )\r
+                {\r
+                    setTrait(READ_NODE_AS_STRING(*tt));\r
+                }\r
+            }\r
+            else if (key == Keys::Type)\r
+            {\r
+                setResourceType(READ_NODE_AS_STRING(it->second));\r
+            }\r
+        }\r
+    }\r
+\r
+}\r
diff --git a/service/simulator/ramlparser/raml/model/RamlResource.h b/service/simulator/ramlparser/raml/model/RamlResource.h
new file mode 100755 (executable)
index 0000000..ebcbf3c
--- /dev/null
@@ -0,0 +1,95 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef RESOURCE_H\r
+#define RESOURCE_H\r
+\r
+#include <map>\r
+#include <list>\r
+#include <string>\r
+#include "UriParameter.h"\r
+#include "ActionType.h"\r
+#include "Action.h"\r
+#include "Utils.h"\r
+#include "IncludeResolver.h"\r
+\r
+namespace RAML\r
+{\r
+    class RamlResource\r
+    {\r
+        public:\r
+            virtual RamlResource *getParentResource();\r
+            virtual void setParentResource(RamlResource *parentResource);\r
+\r
+            virtual std::string getDisplayName() const;\r
+            virtual void setDisplayName(const std::string &displayName);\r
+\r
+            virtual std::string getDescription() const;\r
+            virtual void setDescription(const std::string &description);\r
+\r
+            virtual std::string getParentUri() const;\r
+            virtual void setParentUri(const std::string &parentUri);\r
+\r
+            virtual std::string getRelativeUri() const;\r
+            virtual void setRelativeUri(const std::string &relativeUri);\r
+\r
+            virtual std::map<std::string, UriParameter> getUriParameters() const;\r
+            virtual void setUriParameter(const std::string &paramName, const UriParameter &uriParameter);\r
+\r
+            virtual std::map<std::string, UriParameter > getBaseUriParameters() const;\r
+            virtual void setBaseUriParameter(const std::string &paramName,\r
+                                             const UriParameter &baseUriParameter);\r
+\r
+            virtual Action &getAction(ActionType actionType);\r
+            virtual std::map<ActionType , Action> getActions() const;\r
+            virtual void setAction(const ActionType &actiontype , const Action &action );\r
+\r
+            virtual std::map<std::string, RamlResource> getResources() const;\r
+            virtual void setResource(const std::string &resourceName, const RamlResource &resources);\r
+\r
+            virtual std::list<std::string> getTraits() const;\r
+            virtual void setTrait(const std::string &trait);\r
+\r
+            virtual std::string getResourceType() const;\r
+            virtual void setResourceType(const std::string &type);\r
+\r
+            virtual std::string getResourceUri() const;\r
+            RamlResource() {}\r
+            RamlResource(const std::string resourceKey, const YAML::Node &yamlNode ,\r
+                         IncludeResolver *includeResolver, const std::string &parentUri) { readResource(resourceKey, yamlNode, includeResolver, parentUri); }\r
+        private:\r
+            void readResource(const std::string resourceKey, const YAML::Node &yamlNode,\r
+                              IncludeResolver *includeResolver, const std::string &parentUri);\r
+        private:\r
+            std::string m_displayName;\r
+            std::string m_description;\r
+            std::string m_relativeUri;\r
+            std::map<std::string, UriParameter> m_uriParameters;\r
+            std::map<std::string, UriParameter > m_baseUriParameters;\r
+            std::map<ActionType , Action> m_actions;\r
+            std::list<std::string> m_traits;\r
+            std::string m_resourceType;\r
+            RamlResource *m_parentResource;\r
+            std::string m_parentUri;\r
+            std::map<std::string, RamlResource> m_resources;\r
+            IncludeResolver *m_includeResolver;\r
+    };\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/RequestResponseBody.cpp b/service/simulator/ramlparser/raml/model/RequestResponseBody.cpp
new file mode 100755 (executable)
index 0000000..366e026
--- /dev/null
@@ -0,0 +1,97 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "RequestResponseBody.h"\r
+\r
+namespace RAML\r
+{\r
+\r
+    std::string RequestResponseBody::getType() const\r
+    {\r
+        return m_type;\r
+    }\r
+    void RequestResponseBody::setType(const std::string &type)\r
+    {\r
+        m_type = type;\r
+    }\r
+    Schema *RequestResponseBody::getSchema() const\r
+    {\r
+        return m_schema;\r
+    }\r
+    void RequestResponseBody::setSchema(Schema *schema)\r
+    {\r
+        m_schema = schema;\r
+    }\r
+    std::string RequestResponseBody::getExample() const\r
+    {\r
+        return m_example;\r
+    }\r
+    void RequestResponseBody::setExample(const std::string &example)\r
+    {\r
+        m_example = example;\r
+    }\r
+    std::map<std::string, FormParameter > RequestResponseBody::getFormParameters() const\r
+    {\r
+        return m_formParameters ;\r
+    }\r
+    void RequestResponseBody::setFormParameter(const std::string &paramName,\r
+            const FormParameter  &formParameter)\r
+    {\r
+        m_formParameters[paramName] = formParameter;\r
+    }\r
+    void RequestResponseBody::readRequestResponseBody(const std::string &type,\r
+            const YAML::Node &yamlNode,\r
+            IncludeResolver *includeResolver)\r
+    {\r
+        m_type = type;\r
+        m_schema = NULL;\r
+        m_includeResolver = includeResolver;\r
+        for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
+        {\r
+            std::string key = READ_NODE_AS_STRING(it->first);\r
+\r
+            if (key == Keys::Schema)\r
+            {\r
+                IncludeResolver::FileType fileType = m_includeResolver->getFileType(it->second);\r
+                if ((fileType == IncludeResolver::FileType::JSON) || (fileType == IncludeResolver::FileType::FILE))\r
+                {\r
+                    setSchema(new Schema(m_includeResolver->readFromFile(it->second)));\r
+                }\r
+                else\r
+                {\r
+                    std::string value = READ_NODE_AS_STRING(it->second);\r
+                    setSchema(new Schema(value));\r
+                }\r
+            }\r
+            else if (key == Keys::Example)\r
+                setExample(READ_NODE_AS_STRING(it->second));\r
+            else if (key == Keys::FormParameters)\r
+            {\r
+                YAML::Node paramNode = it->second;\r
+                for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
+                {\r
+                    FormParameter *formParameter = new FormParameter(tt->second);\r
+                    setFormParameter(READ_NODE_AS_STRING(tt->first), *formParameter);\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+}\r
diff --git a/service/simulator/ramlparser/raml/model/RequestResponseBody.h b/service/simulator/ramlparser/raml/model/RequestResponseBody.h
new file mode 100755 (executable)
index 0000000..6c3e6bb
--- /dev/null
@@ -0,0 +1,61 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef REQUEST_RESPONSE_BODY_H\r
+#define REQUEST_RESPONSE_BODY_H\r
+\r
+#include <map>\r
+#include <list>\r
+#include "FormParameter.h"\r
+#include "Utils.h"\r
+#include "IncludeResolver.h"\r
+#include "Schema.h"\r
+\r
+namespace RAML\r
+{\r
+    class RequestResponseBody\r
+    {\r
+        public:\r
+            virtual std::string getType() const;\r
+            virtual void setType(const std::string &type);\r
+            virtual Schema *getSchema() const;\r
+            virtual void setSchema(Schema *schema);\r
+            virtual std::string getExample() const;\r
+            virtual void setExample(const std::string &example);\r
+            virtual std::map<std::string, FormParameter > getFormParameters() const;\r
+            virtual void setFormParameter(const std::string &paramName, const FormParameter  &formParameter);\r
+            RequestResponseBody(): m_schema(NULL) {}\r
+            RequestResponseBody(const std::string type) : m_type(type), m_schema(NULL) {}\r
+            RequestResponseBody(const std::string type, const YAML::Node &yamlNode,\r
+                                IncludeResolver *includeResolver) { readRequestResponseBody(type, yamlNode, includeResolver); }\r
+        private:\r
+            virtual void readRequestResponseBody(const std::string &type, const YAML::Node &yamlNode,\r
+                                                 IncludeResolver *includeResolver) ;\r
+        private:\r
+            std::string m_type;\r
+            Schema *m_schema;\r
+            std::string m_example;\r
+            std::map<std::string, FormParameter > m_formParameters;\r
+            IncludeResolver *m_includeResolver;\r
+\r
+\r
+    };\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/ResourceProperties.cpp b/service/simulator/ramlparser/raml/model/ResourceProperties.cpp
new file mode 100755 (executable)
index 0000000..9b6a122
--- /dev/null
@@ -0,0 +1,103 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "ResourceProperties.h"\r
+\r
+namespace RAML\r
+{\r
+\r
+    void ResourceProperties::readJson()\r
+    {\r
+        if (! m_cjson)\r
+            return;\r
+        cJSON *jsonrt = cJSON_GetObjectItem(m_cjson, "rt");\r
+        m_rt = jsonrt->valuestring;\r
+\r
+        cJSON *jsonif = cJSON_GetObjectItem(m_cjson, "if");\r
+        m_if = jsonif->valuestring;\r
+\r
+        cJSON *jsonProperties = cJSON_GetObjectItem(m_cjson, "properties");\r
+        cJSON *childProperties = jsonProperties->child;\r
+\r
+        while (childProperties)\r
+        {\r
+            std::string attName = childProperties->string;\r
+\r
+            std::string attType = cJSON_GetObjectItem(childProperties, "type")->valuestring;\r
+            if (attType == "string")\r
+            {\r
+                addAttribute(attName , std::string(cJSON_GetObjectItem(childProperties, "default")->valuestring));\r
+                cJSON *allowedvalues = cJSON_GetObjectItem(childProperties, "values");\r
+                if (allowedvalues)\r
+                {\r
+                    int size = cJSON_GetArraySize(allowedvalues);\r
+                    int idx = 0;\r
+                    std::vector<std::string> allwdValues;\r
+\r
+                    do\r
+                    {\r
+                        allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valuestring);\r
+\r
+                    }\r
+                    while ( ++idx < size);\r
+\r
+                    setAllowedValues(attName, allwdValues);\r
+                }\r
+            }\r
+            else\r
+            {\r
+                addAttribute(attName , int(cJSON_GetObjectItem(childProperties, "default")->valueint));\r
+                cJSON *allowedvalues = cJSON_GetObjectItem(childProperties, "values");\r
+                if (allowedvalues)\r
+                {\r
+                    int size = cJSON_GetArraySize(allowedvalues);\r
+                    int idx = 0;\r
+                    std::vector<int> allwdValues;\r
+\r
+                    do\r
+                    {\r
+                        allwdValues.push_back(cJSON_GetArrayItem(allowedvalues, idx)->valueint);\r
+\r
+                    }\r
+                    while ( ++idx < size);\r
+\r
+                    setAllowedValues(attName, allwdValues);\r
+                }\r
+                cJSON *ranges = cJSON_GetObjectItem(childProperties, "range");\r
+                if (ranges)\r
+                {\r
+                    int sizeRange = cJSON_GetArraySize(ranges);\r
+                    if (sizeRange == 2)\r
+                    {\r
+                        setRange(attName , (cJSON_GetArrayItem(ranges, 0)->valueint) , (cJSON_GetArrayItem(ranges,\r
+                                 1)->valueint));\r
+                    }\r
+                }\r
+\r
+            }\r
+\r
+            setUpdateInterval(attName , cJSON_GetObjectItem(childProperties, "update_frequency")->valueint);\r
+            childProperties = childProperties->next;\r
+        }\r
+\r
+    }\r
+\r
+}\r
+\r
diff --git a/service/simulator/ramlparser/raml/model/ResourceProperties.h b/service/simulator/ramlparser/raml/model/ResourceProperties.h
new file mode 100755 (executable)
index 0000000..802bde9
--- /dev/null
@@ -0,0 +1,239 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef RESOURCE_PROPERTIES_H_\r
+#define RESOURCE_PROPERTIES_H_\r
+\r
+#include <string>\r
+#include <vector>\r
+#include <map>\r
+#include "cJSON.h"\r
+#include <boost/variant.hpp>\r
+#include <boost/lexical_cast.hpp>\r
+\r
+namespace RAML\r
+{\r
+\r
+    class ResourceProperties\r
+    {\r
+        public:\r
+            ResourceProperties() {}\r
+            ResourceProperties(cJSON *cjson) : m_cjson(cjson) { readJson();}\r
+\r
+            class Attribute\r
+            {\r
+                public:\r
+                    typedef boost::variant <\r
+                    int,\r
+                    double,\r
+                    std::string\r
+                    > ValueVariant;\r
+\r
+                    Attribute() = default;\r
+                    Attribute(const std::string &attrName) : m_name(attrName) {}\r
+\r
+                    inline std::string getName(void) const { return m_name; }\r
+                    inline void setName(const std::string &name) { m_name = name;}\r
+\r
+                    template <typename T>\r
+                    T getValue() const\r
+                    {\r
+                        T val = T();\r
+                        return boost::get<T>(m_value);\r
+                    }\r
+\r
+                    ValueVariant &getValue()\r
+                    {\r
+                        return m_value;\r
+                    }\r
+\r
+                    int getValueType() const\r
+                    {\r
+                        return m_value.which();\r
+                    }\r
+                    int getValueInt()\r
+                    {\r
+                        return boost::lexical_cast<int> (m_value);\r
+                    }\r
+                    std::string getValueString()\r
+                    {\r
+                        return boost::lexical_cast<std::string> (m_value);\r
+                    }\r
+\r
+                    template <typename T>\r
+                    void setValue(const T &value)\r
+                    {\r
+                        m_value = value;\r
+                    }\r
+\r
+                    inline void getRange(int &min, int &max) const\r
+                    {\r
+                        min = m_min;\r
+                        max = m_max;\r
+                    }\r
+\r
+                    inline void setRange(const int &min, const int &max)\r
+                    {\r
+                        m_min = min;\r
+                        m_max = max;\r
+                    }\r
+\r
+                    template <typename T>\r
+                    bool setAllowedValues(const std::vector<T> &values)\r
+                    {\r
+                        ValueVariant temp = values.at(0);\r
+                        if (temp.which() != m_value.which())\r
+                        {\r
+                            return false;\r
+                        }\r
+\r
+                        m_allowedValues.addValues(values);\r
+                        return true;\r
+                    }\r
+                    inline int getAllowedValuesSize() const\r
+                    {\r
+                        return m_allowedValues.size();\r
+                    }\r
+\r
+                    inline std::vector<ValueVariant> getAllowedValues()\r
+                    {\r
+                        return m_allowedValues.getValues();\r
+                    }\r
+\r
+                    int getUpdateFrequencyTime() {return m_updateInterval;}\r
+                    void setUpdateFrequencyTime(int interval) {m_updateInterval = interval;}\r
+\r
+                private:\r
+                    class AllowedValues\r
+                    {\r
+                        public:\r
+                            template <typename T>\r
+                            void addValue(const T &value)\r
+                            {\r
+                                ValueVariant temp = value;\r
+                                m_values.push_back(temp);\r
+                            }\r
+\r
+                            template <typename T>\r
+                            void addValues(const std::vector<T> &values)\r
+                            {\r
+                                for (auto value : values)\r
+                                {\r
+                                    ValueVariant vValue = value;\r
+                                    m_values.push_back(vValue);\r
+                                }\r
+                            }\r
+\r
+                            inline ValueVariant &at(int index)\r
+                            {\r
+                                return m_values.at(index);\r
+                            }\r
+                            inline int size() const\r
+                            {\r
+                                return m_values.size();\r
+                            }\r
+\r
+                            inline std::vector<ValueVariant> getValues()\r
+                            {\r
+                                return m_values;\r
+                            }\r
+\r
+                        private:\r
+                            std::vector<ValueVariant> m_values;\r
+                    };\r
+\r
+                    std::string m_name;\r
+                    ValueVariant m_value;\r
+                    int m_max;\r
+                    int m_min;\r
+                    AllowedValues m_allowedValues;\r
+                    int m_updateInterval;\r
+            };\r
+            int size() const { return m_attributes.size(); }\r
+            inline bool getAttribute(const std::string &attrName, Attribute &value)\r
+            {\r
+                if (m_attributes.end() != m_attributes.find(attrName))\r
+                {\r
+                    value = m_attributes[attrName];\r
+                    return true;\r
+                }\r
+\r
+                return false;\r
+            }\r
+\r
+            inline std::map<std::string, Attribute> getAttributes() const\r
+            {\r
+                return m_attributes;\r
+            }\r
+\r
+\r
+            template <typename T>\r
+            void addAttribute(const std::string &attrName, const T &attrValue)\r
+            {\r
+                if (m_attributes.end() == m_attributes.find(attrName))\r
+                {\r
+                    m_attributes[attrName] = Attribute(attrName);\r
+                    m_attributes[attrName].setValue(attrValue);\r
+                }\r
+            }\r
+\r
+        private:\r
+            inline void setRange(const std::string &attrName, const int min, const int max)\r
+            {\r
+                if (m_attributes.end() != m_attributes.find(attrName))\r
+                    m_attributes[attrName].setRange(min, max);\r
+            }\r
+\r
+\r
+            template <typename T>\r
+            void setAllowedValues(const std::string &attrName, const std::vector<T> &values)\r
+            {\r
+                if (m_attributes.end() != m_attributes.find(attrName))\r
+                    m_attributes[attrName].setAllowedValues(values);\r
+            }\r
+\r
+            inline void setUpdateInterval(const std::string &attrName, int interval)\r
+            {\r
+                if (m_attributes.end() != m_attributes.find(attrName))\r
+                    m_attributes[attrName].setUpdateFrequencyTime(interval);\r
+            }\r
+\r
+\r
+            inline void removeAttribute(const std::string &attrName)\r
+            {\r
+                m_attributes.erase(attrName);\r
+                return;\r
+            }\r
+            void readJson();\r
+\r
+        public:\r
+            std::string getResoureType() const {return m_rt; }\r
+            std::string getInterface() const {return m_if; }\r
+\r
+        private:\r
+            std::map<std::string, Attribute> m_attributes;\r
+            std::string m_rt;\r
+            std::string m_if;\r
+            cJSON *m_cjson;\r
+\r
+    };\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/Response.cpp b/service/simulator/ramlparser/raml/model/Response.cpp
new file mode 100755 (executable)
index 0000000..8087d21
--- /dev/null
@@ -0,0 +1,90 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "Response.h"\r
+\r
+namespace RAML\r
+{\r
+\r
+    std::map<std::string, Header> Response::getHeaders() const\r
+    {\r
+        return m_headers;\r
+    }\r
+    void Response::setHeader(const std::string &headerName, const Header &header)\r
+    {\r
+        m_headers[headerName] = header;\r
+    }\r
+    std::string Response::getDescription() const\r
+    {\r
+        return m_description;\r
+    }\r
+    void Response::setDescription(const std::string &description)\r
+    {\r
+        m_description = description;\r
+    }\r
+    void Response::setResponseBody(const std::string &typeName)\r
+    {\r
+        m_responseBody[typeName] = *(new RequestResponseBody(typeName));\r
+    }\r
+    void Response::setResponseBody(const std::string &type, const RequestResponseBody &body)\r
+    {\r
+        m_responseBody[type] = body;\r
+    }\r
+    std::map<std::string, RequestResponseBody> Response::getResponseBody() const\r
+    {\r
+        return m_responseBody;\r
+    }\r
+    RequestResponseBody &Response::getResponseBody(std::string bodyType)\r
+    {\r
+        return m_responseBody[bodyType];\r
+    }\r
+\r
+    void Response::readResponse(const YAML::Node &yamlNode, IncludeResolver *includeResolver)\r
+    {\r
+        m_includeResolver = includeResolver;\r
+        for ( YAML::const_iterator it = yamlNode.begin(); it != yamlNode.end(); ++it )\r
+        {\r
+            std::string key = READ_NODE_AS_STRING(it->first);\r
+\r
+            if (key == Keys::Description)\r
+                setDescription(READ_NODE_AS_STRING(it->second));\r
+            else if (key == Keys::Body)\r
+            {\r
+                YAML::Node responseBody = it->second;\r
+\r
+                for ( YAML::const_iterator tt = responseBody.begin(); tt != responseBody.end(); ++tt )\r
+                {\r
+                    std::string type = READ_NODE_AS_STRING(tt->first);\r
+                    setResponseBody(type, *(new RequestResponseBody(type, tt->second, m_includeResolver)));\r
+                }\r
+            }\r
+            else if (key == Keys::Headers)\r
+            {\r
+                YAML::Node paramNode = it->second;\r
+                for ( YAML::const_iterator tt = paramNode.begin(); tt != paramNode.end(); ++tt )\r
+                {\r
+                    Header *header = new Header(tt->second);\r
+                    setHeader(READ_NODE_AS_STRING(tt->first), *header);\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+}\r
diff --git a/service/simulator/ramlparser/raml/model/Response.h b/service/simulator/ramlparser/raml/model/Response.h
new file mode 100755 (executable)
index 0000000..cf720ec
--- /dev/null
@@ -0,0 +1,58 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef RESPONSE_H\r
+#define RESPONSE_H\r
+\r
+#include <map>\r
+#include <list>\r
+#include <string>\r
+#include "RequestResponseBody.h"\r
+#include "Header.h"\r
+#include "Utils.h"\r
+#include "IncludeResolver.h"\r
+\r
+namespace RAML\r
+{\r
+    class Response\r
+    {\r
+        public:\r
+            virtual std::map<std::string, Header> getHeaders() const;\r
+            virtual void setHeader(const std::string &headerName, const Header &header);\r
+            virtual std::string getDescription() const;\r
+            virtual void setDescription(const std::string &description);\r
+            virtual void setResponseBody(const std::string &typeName);\r
+            virtual void setResponseBody(const std::string &type, const RequestResponseBody &body) ;\r
+            virtual std::map<std::string, RequestResponseBody> getResponseBody() const;\r
+            virtual RequestResponseBody &getResponseBody(const std::string bodyType);\r
+\r
+\r
+            Response() {}\r
+            Response(const YAML::Node &yamlNode, IncludeResolver *includeResolver) { readResponse(yamlNode, includeResolver);}\r
+        private:\r
+            void readResponse(const YAML::Node &yamlNode, IncludeResolver *includeResolver) ;\r
+        private:\r
+            std::string m_description;\r
+            std::map<std::string, RequestResponseBody> m_responseBody;\r
+            std::map<std::string, Header> m_headers;\r
+            IncludeResolver *m_includeResolver;\r
+    };\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/Schema.cpp b/service/simulator/ramlparser/raml/model/Schema.cpp
new file mode 100755 (executable)
index 0000000..39dece5
--- /dev/null
@@ -0,0 +1,46 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "Schema.h"\r
+namespace RAML\r
+{\r
+\r
+    cJSON *Schema::getJson() const\r
+    {\r
+        return m_cjson;\r
+    }\r
+    void Schema::setJson(cJSON *cjson)\r
+    {\r
+        m_cjson = cjson;\r
+    }\r
+    std::string Schema::getSchema() const\r
+    {\r
+        return m_schema;\r
+    }\r
+    void Schema::setSchema(const std::string &schema)\r
+    {\r
+        m_schema = schema;\r
+    }\r
+    ResourceProperties *Schema::getProperties() const\r
+    {\r
+        return m_resProperties;\r
+    }\r
+\r
+}\r
diff --git a/service/simulator/ramlparser/raml/model/Schema.h b/service/simulator/ramlparser/raml/model/Schema.h
new file mode 100755 (executable)
index 0000000..e4e90ae
--- /dev/null
@@ -0,0 +1,53 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef SCHEMAS_H\r
+#define SCHEMAS_H\r
+\r
+#include <string>\r
+#include "cJSON.h"\r
+#include "IncludeResolver.h"\r
+\r
+#include "ResourceProperties.h"\r
+\r
+namespace RAML\r
+{\r
+    class Schema\r
+    {\r
+        public:\r
+            virtual cJSON *getJson() const;\r
+            virtual void setJson(cJSON *cjson);\r
+            virtual std::string getSchema() const;\r
+            virtual void setSchema(const std::string &schema);\r
+            virtual ResourceProperties *getProperties() const;\r
+\r
+            Schema(cJSON *cjson): m_cjson(cjson) {}\r
+            Schema(const std::string &schema): m_schema(schema) , m_cjson(cJSON_Parse(schema.c_str())),\r
+                m_resProperties(new ResourceProperties(m_cjson) ) {}\r
+            Schema() {}\r
+\r
+        private:\r
+            cJSON *m_cjson;\r
+            std::string m_schema;\r
+            ResourceProperties *m_resProperties;\r
+    };\r
+\r
+}\r
+#endif\r
diff --git a/service/simulator/ramlparser/raml/model/UriParameter.h b/service/simulator/ramlparser/raml/model/UriParameter.h
new file mode 100755 (executable)
index 0000000..a96536e
--- /dev/null
@@ -0,0 +1,36 @@
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *             http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#ifndef URI_PARAMETER_H\r
+#define URI_PARAMETER_H\r
+\r
+#include "AbstractParam.h"\r
+\r
+namespace RAML\r
+{\r
+    class UriParameter: public AbstractParam\r
+    {\r
+        public:\r
+            UriParameter(const YAML::Node &yamlNode) : AbstractParam(yamlNode) {}\r
+            UriParameter() {}\r
+    };\r
+\r
+}\r
+#endif\r
index 3225bd3..7556787 100644 (file)
@@ -43,7 +43,7 @@ SimulatorResourceServerPtr ResourceManager::createResource(const std::string &co
      * TODO: Temporarily creating the light resource for testing the basic flow
      * Once the config parser is included this method will simulate the resource based on the config file
      */
-    SimulatorResourceServerPtr simulatorResource = m_resourceCreator->createLightResoure();
+    SimulatorResourceServerPtr simulatorResource = m_resourceCreator->createResource(configPath);
     simulatorResource->setModelChangeCallback(callback);
     std::string uri = getURI(simulatorResource->getURI());
     if(uri.empty())
@@ -78,7 +78,7 @@ std::vector<SimulatorResourceServerPtr> ResourceManager::createResource(
          * TODO: Temporarily creating the light resource for testing the basic flow
          * Once the config parser is included this method will simulate the resource based on the config file
          */
-        SimulatorResourceServerPtr simulatorResource = m_resourceCreator->createLightResoure();
+        SimulatorResourceServerPtr simulatorResource = m_resourceCreator->createResource(configPath);
         simulatorResource->setModelChangeCallback(callback);
         std::string uri = getURI(simulatorResource->getURI());
         if(uri.empty())
index fb2359d..2364734 100644 (file)
@@ -1,52 +1,93 @@
-/******************************************************************
- *
- * Copyright 2015 Samsung Electronics All Rights Reserved.
- *
- *
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************/
-
-#include "simulator_resource_creator.h"
-#include "simulator_logger.h"
-
-SimulatorResourceServerPtr SimulatorResourceCreator::createLightResoure()
-{
-    std::shared_ptr<SimulatorResourceServer> lightResource(new SimulatorResourceServer);
-
-    // set power attribute with its properties
-    {
-        lightResource->addAttribute("power", std::string("on"));
-        std::vector<std::string> values {"on", "off"};
-        lightResource->setAllowedValues("power", values);
-        lightResource->setUpdateInterval("power", 2000);
-    }
-
-    // set intensity attributes with its properties
-    {
-        lightResource->addAttribute("intensity", int(1));
-        lightResource->setRange("intensity", 1, 10);
-        lightResource->setUpdateInterval("intensity", 3000);
-    }
-
-    // set other properties
-    lightResource->setName("Light");
-    lightResource->setURI("/oic/light");
-    lightResource->setResourceType("oic.light");
-    lightResource->setInterfaceType(OC::DEFAULT_INTERFACE);
-
-    SIM_LOG(ILogger::INFO, "Created sample light resource");
-    return lightResource;
-}
-
+/******************************************************************\r
+ *\r
+ * Copyright 2015 Samsung Electronics All Rights Reserved.\r
+ *\r
+ *\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ ******************************************************************/\r
+\r
+#include "simulator_resource_creator.h"\r
+#include "simulator_logger.h"\r
+#include <RamlParser.h>\r
+#include <boost/lexical_cast.hpp>\r
+\r
+using namespace RAML;\r
+\r
+SimulatorResourceServerPtr SimulatorResourceCreator::createResource(const std::string &configPath)\r
+{\r
+    std::shared_ptr<SimulatorResourceServer> resource(new SimulatorResourceServer);\r
+\r
+    if (configPath.length() > 0)\r
+    {\r
+        std::size_t found = configPath.find_last_of("/\\");\r
+        if (found > configPath.length())\r
+        {\r
+            return resource;\r
+        }\r
+        std::string filePath = configPath.substr(0, found) + "/";\r
+        std::string fileName = configPath.substr(found + 1);\r
+\r
+        RamlPtr raml = (new RamlParser(filePath, fileName))->build();\r
+        for (auto  resours : raml->getResources())\r
+        {\r
+            resource->setName(resours.first);\r
+            resource->setURI(resours.second.getResourceUri());\r
+            for (auto  action :  resours.second.getActions())\r
+            {\r
+                for (auto  response :  action.second.getResponses())\r
+                {\r
+                    for (auto bdy :  response.second.getResponseBody())\r
+                    {\r
+                        auto resourceProperties = bdy.second.getSchema()->getProperties();\r
+\r
+                        resource->setResourceType(resourceProperties->getResoureType());\r
+                        resource->setInterfaceType(resourceProperties->getInterface());\r
+\r
+                        for ( auto property : resourceProperties->getAttributes() )\r
+                        {\r
+                            int type = property.second.getValueType();\r
+                            if (type)\r
+                            {\r
+                                std::string attributeValue = property.second.getValueString();\r
+                                resource->addAttribute(property.second.getName(), std::string(attributeValue));\r
+                            }\r
+                            else\r
+                            {\r
+                                int attributeValue = property.second.getValueInt();\r
+                                resource->addAttribute(property.second.getName(), int(attributeValue));\r
+                            }\r
+\r
+                            resource->setUpdateInterval(property.second.getName(), property.second.getUpdateFrequencyTime());\r
+\r
+                            int min = 0, max = 0;\r
+                            property.second.getRange(min, max);\r
+                            resource->setRange(property.second.getName(), min, max);\r
+\r
+\r
+                            if (property.second.getAllowedValuesSize() > 0)\r
+                                resource->setAllowedValues(property.second.getName(), property.second.getAllowedValues());\r
+                        }\r
+                        SIM_LOG(ILogger::INFO, "Created sample resource");\r
+                        return resource;\r
+                    }\r
+                }\r
+\r
+            }\r
+        }\r
+    }\r
+    SIM_LOG(ILogger::INFO, "Created sample resource");\r
+    return resource;\r
+}\r
+\r
index 44d1faf..ad88014 100644 (file)
@@ -30,7 +30,7 @@ class SimulatorResourceCreator
          * This is temporary method to get the light resource as parser
          * needs to implemented/integrated
          */
-        SimulatorResourceServerPtr createLightResoure();
+        SimulatorResourceServerPtr createResource(const std::string &configPath);
 };
 
 #endif
\ No newline at end of file